Bug 1544894 - Fix bug where BITS notifications never return from active to idle mode r=rstrong
authorKirk Steuber <ksteuber@mozilla.com>
Tue, 16 Apr 2019 18:21:45 +0000
changeset 469763 7c149c2cd4a90a9063c02082c51362043f29d47c
parent 469762 4a6e7c0051cbc31d80b1700d39406b0d59fba7da
child 469764 da7521e9da92901340c9b39bc882b4911e59cd05
push id83341
push userksteuber@mozilla.com
push dateWed, 17 Apr 2019 07:34:38 +0000
treeherderautoland@7c149c2cd4a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1544894
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1544894 - Fix bug where BITS notifications never return from active to idle mode r=rstrong Differential Revision: https://phabricator.services.mozilla.com/D27781
toolkit/mozapps/update/UpdateService.jsm
--- a/toolkit/mozapps/update/UpdateService.jsm
+++ b/toolkit/mozapps/update/UpdateService.jsm
@@ -4036,24 +4036,24 @@ Downloader.prototype = {
    * Removes a download listener
    * @param   listener
    *          The listener to remove.
    */
   removeDownloadListener: function Downloader_removeDownloadListener(listener) {
     for (let i = 0; i < this._listeners.length; ++i) {
       if (this._listeners[i] == listener) {
         this._listeners.splice(i, 1);
+
+        // Decrease the status update frequency when no one is listening
+        if (this._listeners.length == 0) {
+          this._maybeStopActiveNotifications();
+        }
         return;
       }
     }
-
-    // Decrease the status update frequency when no one is listening
-    if (this._listeners.length == 0) {
-      this._maybeStopActiveNotifications();
-    }
   },
 
   /**
    * Returns a boolean indicating whether there are any download listeners
    */
   get hasDownloadListeners() {
     return this._listeners.length > 0;
   },
@@ -4062,32 +4062,34 @@ Downloader.prototype = {
    * This speeds up BITS progress notifications in response to a user watching
    * the notifications.
    */
   _maybeStartActiveNotifications: async function Downloader__maybeStartActiveNotifications() {
     if (this.usingBits && !this._bitsActiveNotifications &&
         this.hasDownloadListeners && this._request) {
       LOG("Downloader:_maybeStartActiveNotifications - Starting active " +
           "notifications");
+      this._bitsActiveNotifications = true;
       await this._request.changeMonitorInterval(BITS_ACTIVE_POLL_RATE_MS).catch(error => {
         LOG("Downloader:_maybeStartActiveNotifications - Failed to increase " +
             "status update frequency. Error: " + error);
       });
     }
   },
 
   /**
    * This slows down BITS progress notifications in response to a user no longer
    * watching the notifications.
    */
   _maybeStopActiveNotifications: async function Downloader__maybeStopActiveNotifications() {
     if (this.usingBits && this._bitsActiveNotifications &&
         !this.hasDownloadListeners && this._request) {
       LOG("Downloader:_maybeStopActiveNotifications - Stopping active " +
           "notifications");
+      this._bitsActiveNotifications = false;
       await this._request.changeMonitorInterval(BITS_IDLE_POLL_RATE_MS).catch(error => {
         LOG("Downloader:_maybeStopActiveNotifications - Failed to decrease " +
             "status update frequency: " + error);
       });
     }
   },
 
   /**