choke uploadProgress signals
[profile/ivi/qtbase.git] / src / network / access / qnetworkreplyimpl.cpp
index 377f257..d039347 100644 (file)
@@ -94,7 +94,7 @@ void QNetworkReplyImplPrivate::_q_startOperation()
 
 #ifndef QT_NO_BEARERMANAGEMENT
     // Do not start background requests if they are not allowed by session policy
-    QSharedPointer<QNetworkSession> session(manager->d_func()->networkSession);
+    QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession());
     QVariant isBackground = backend->request().attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false));
     if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) {
         error(QNetworkReply::BackgroundRequestNotAllowedError,
@@ -144,6 +144,10 @@ void QNetworkReplyImplPrivate::_q_startOperation()
     }
 #endif
 
+    // Prepare timer for progress notifications
+    downloadProgressSignalChoke.start();
+    uploadProgressSignalChoke.invalidate();
+
     if (backend && backend->isSynchronous()) {
         state = Finished;
         q_func()->setFinished(true);
@@ -210,8 +214,11 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead()
     // emit readyRead before downloadProgress incase this will cause events to be
     // processed and we get into a recursive call (as in QProgressDialog).
     emit q->readyRead();
-    emit q->downloadProgress(bytesDownloaded,
+    if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
+        downloadProgressSignalChoke.restart();
+        emit q->downloadProgress(bytesDownloaded,
                              totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
+    }
     resumeNotificationHandling();
 }
 
@@ -288,7 +295,7 @@ void QNetworkReplyImplPrivate::_q_networkSessionConnected()
     if (manager.isNull())
         return;
 
-    QNetworkSession *session = manager->d_func()->networkSession.data();
+    QSharedPointer<QNetworkSession> session = manager->d_func()->getNetworkSession();
     if (!session)
         return;
 
@@ -316,7 +323,7 @@ void QNetworkReplyImplPrivate::_q_networkSessionFailed()
     // Abort waiting and working replies.
     if (state == WaitingForSession || state == Working) {
         state = Working;
-        QSharedPointer<QNetworkSession> session(manager->d_func()->networkSession);
+        QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession());
         QString errorStr;
         if (session)
             errorStr = session->errorString();
@@ -544,6 +551,17 @@ void QNetworkReplyImplPrivate::emitUploadProgress(qint64 bytesSent, qint64 bytes
 {
     Q_Q(QNetworkReplyImpl);
     bytesUploaded = bytesSent;
+
+    //choke signal emissions, except the first and last signals which are unconditional
+    if (uploadProgressSignalChoke.isValid()) {
+        if (bytesSent != bytesTotal && uploadProgressSignalChoke.elapsed() < progressSignalInterval) {
+            return;
+        }
+        uploadProgressSignalChoke.restart();
+    } else {
+        uploadProgressSignalChoke.start();
+    }
+
     pauseNotificationHandling();
     emit q->uploadProgress(bytesSent, bytesTotal);
     resumeNotificationHandling();
@@ -640,8 +658,11 @@ void QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions()
     emit q->readyRead();
     // emit readyRead before downloadProgress incase this will cause events to be
     // processed and we get into a recursive call (as in QProgressDialog).
-    emit q->downloadProgress(bytesDownloaded,
+    if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
+        downloadProgressSignalChoke.restart();
+        emit q->downloadProgress(bytesDownloaded,
                              totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
+    }
 
     resumeNotificationHandling();
     // do we still have room in the buffer?
@@ -747,7 +768,10 @@ void QNetworkReplyImplPrivate::appendDownstreamDataDownloadBuffer(qint64 bytesRe
     // processed and we get into a recursive call (as in QProgressDialog).
     if (bytesDownloaded > 0)
         emit q->readyRead();
-    emit q->downloadProgress(bytesDownloaded, bytesTotal);
+    if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
+        downloadProgressSignalChoke.restart();
+        emit q->downloadProgress(bytesDownloaded, bytesTotal);
+    }
 }
 
 void QNetworkReplyImplPrivate::finished()
@@ -764,7 +788,7 @@ void QNetworkReplyImplPrivate::finished()
 
     if (!manager.isNull()) {
 #ifndef QT_NO_BEARERMANAGEMENT
-        QNetworkSession *session = manager->d_func()->networkSession.data();
+        QSharedPointer<QNetworkSession> session (manager->d_func()->getNetworkSession());
         if (session && session->state() == QNetworkSession::Roaming &&
             state == Working && errorCode != QNetworkReply::OperationCanceledError) {
             // only content with a known size will fail with a temporary network failure error
@@ -795,6 +819,8 @@ void QNetworkReplyImplPrivate::finished()
     pauseNotificationHandling();
     if (totalSize.isNull() || totalSize == -1) {
         emit q->downloadProgress(bytesDownloaded, bytesDownloaded);
+    } else {
+        emit q->downloadProgress(bytesDownloaded, totalSize.toLongLong());
     }
 
     if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer))