summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-06-26 08:31:19 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-06-26 08:31:19 (GMT)
commitb914c388a809c17e4f76a4dcc1d3a1006e13c115 (patch)
treeef6723688578c7ff13fed8b4ea0c961aaf98fe09 /src/network
parent7278c142089d46946d1ad2558eae949220dfe0c4 (diff)
parentd553f376a34ea1d27492a1a5fd14f79616f6a27c (diff)
downloadQt-b914c388a809c17e4f76a4dcc1d3a1006e13c115.zip
Qt-b914c388a809c17e4f76a4dcc1d3a1006e13c115.tar.gz
Qt-b914c388a809c17e4f76a4dcc1d3a1006e13c115.tar.bz2
Merge branch '4.5'
Conflicts: src/3rdparty/webkit/VERSION src/3rdparty/webkit/WebCore/ChangeLog src/network/access/qnetworkreplyimpl.cpp
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp30
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h5
2 files changed, 35 insertions, 0 deletions
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 265ebe9..d1dbdc9 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -56,6 +56,7 @@ inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate()
: backend(0), outgoingData(0), outgoingDataBuffer(0),
copyDevice(0), networkCache(0),
cacheEnabled(false), cacheSaveDevice(0),
+ notificationHandlingPaused(false),
bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1),
state(Idle)
{
@@ -126,9 +127,11 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead()
lastBytesDownloaded = bytesDownloaded;
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
+ pauseNotificationHandling();
emit q->downloadProgress(bytesDownloaded,
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
emit q->readyRead();
+ resumeNotificationHandling();
}
void QNetworkReplyImplPrivate::_q_copyReadChannelFinished()
@@ -262,6 +265,9 @@ void QNetworkReplyImplPrivate::backendNotify(InternalNotifications notification)
void QNetworkReplyImplPrivate::handleNotifications()
{
+ if (notificationHandlingPaused)
+ return;
+
NotificationQueue current = pendingNotifications;
pendingNotifications.clear();
@@ -292,6 +298,22 @@ void QNetworkReplyImplPrivate::handleNotifications()
}
}
+// Do not handle the notifications while we are emitting downloadProgress
+// or readyRead
+void QNetworkReplyImplPrivate::pauseNotificationHandling()
+{
+ notificationHandlingPaused = true;
+}
+
+// Resume notification handling
+void QNetworkReplyImplPrivate::resumeNotificationHandling()
+{
+ Q_Q(QNetworkReplyImpl);
+ notificationHandlingPaused = false;
+ if (pendingNotifications.size() >= 1)
+ QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated));
+}
+
void QNetworkReplyImplPrivate::createCache()
{
// check if we can save and if we're allowed to
@@ -347,7 +369,9 @@ void QNetworkReplyImplPrivate::emitUploadProgress(qint64 bytesSent, qint64 bytes
{
Q_Q(QNetworkReplyImpl);
bytesUploaded = bytesSent;
+ pauseNotificationHandling();
emit q->uploadProgress(bytesSent, bytesTotal);
+ resumeNotificationHandling();
}
@@ -398,12 +422,14 @@ void QNetworkReplyImplPrivate::appendDownstreamData(const QByteArray &data)
QPointer<QNetworkReplyImpl> qq = q;
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
+ pauseNotificationHandling();
emit q->downloadProgress(bytesDownloaded,
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
emit q->readyRead();
// hopefully we haven't been deleted here
if (!qq.isNull()) {
+ resumeNotificationHandling();
// do we still have room in the buffer?
if (nextDownstreamBlockSize() > 0)
backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite);
@@ -441,6 +467,7 @@ void QNetworkReplyImplPrivate::finished()
state = Finished;
pendingNotifications.clear();
+ pauseNotificationHandling();
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
if (totalSize.isNull() || totalSize == -1) {
emit q->downloadProgress(bytesDownloaded, bytesDownloaded);
@@ -448,14 +475,17 @@ void QNetworkReplyImplPrivate::finished()
if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer))
emit q->uploadProgress(0, 0);
+ resumeNotificationHandling();
completeCacheSave();
// note: might not be a good idea, since users could decide to delete us
// which would delete the backend too...
// maybe we should protect the backend
+ pauseNotificationHandling();
emit q->readChannelFinished();
emit q->finished();
+ resumeNotificationHandling();
}
void QNetworkReplyImplPrivate::error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage)
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index 4d75526..3e89a00 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -130,6 +130,9 @@ public:
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
QIODevice *outgoingData);
void setNetworkCache(QAbstractNetworkCache *networkCache);
+
+ void pauseNotificationHandling();
+ void resumeNotificationHandling();
void backendNotify(InternalNotifications notification);
void handleNotifications();
void createCache();
@@ -159,6 +162,8 @@ public:
QIODevice *cacheSaveDevice;
NotificationQueue pendingNotifications;
+ bool notificationHandlingPaused;
+
QUrl urlForLastAuthentication;
#ifndef QT_NO_NETWORKPROXY
QNetworkProxy lastProxyAuthentication;