Bug 1393418 - Fix initialization of the Downloads Indicator on startup. r=mak draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Thu, 24 Aug 2017 13:34:08 +0100
changeset 652135 0c7d7449f42bc483a5ae4f878648ed512090aa19
parent 651826 d1c70c20e7b52f7295411343e4dc5db8ee7c92b9
child 727983 4add12b9335c60b55981c0ae4b83a8006d340ce2
push id75943
push userpaolo.mozmail@amadzone.org
push dateThu, 24 Aug 2017 12:35:04 +0000
reviewersmak
bugs1393418
milestone57.0a1
Bug 1393418 - Fix initialization of the Downloads Indicator on startup. r=mak MozReview-Commit-ID: GEQZoak5MFl
browser/components/downloads/DownloadsCommon.jsm
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -945,16 +945,17 @@ const DownloadsViewPrototype = {
     this._loading = true;
   },
 
   /**
    * Called after data loading finished.
    */
   onDownloadBatchEnded() {
     this._loading = false;
+    this._updateViews();
   },
 
   /**
    * Called when a new download data item is available, either during the
    * asynchronous data load or when a new download is started.
    *
    * @param download
    *        Download object that was just added.
@@ -1024,16 +1025,29 @@ const DownloadsViewPrototype = {
   /**
    * Private function used to refresh an individual view.
    *
    * @note Subclasses should override this.
    */
   _updateView() {
     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
   },
+
+  /**
+   * Computes aggregate values and propagates the changes to our views.
+   */
+  _updateViews() {
+    // Do not update the status indicators during batch loads of download items.
+    if (this._loading) {
+      return;
+    }
+
+    this._refreshProperties();
+    this._views.forEach(this._updateView, this);
+  },
 };
 
 // DownloadsIndicatorData
 
 /**
  * This object registers itself with DownloadsData as a view, and transforms the
  * notifications it receives into overall status data, that is then broadcast to
  * the registered download status indicators.
@@ -1060,23 +1074,16 @@ DownloadsIndicatorDataCtor.prototype = {
   removeView(aView) {
     DownloadsViewPrototype.removeView.call(this, aView);
 
     if (this._views.length == 0) {
       this._itemCount = 0;
     }
   },
 
-  // Callback functions from DownloadsData
-
-  onDataLoadCompleted() {
-    DownloadsViewPrototype.onDataLoadCompleted.call(this);
-    this._updateViews();
-  },
-
   onDownloadAdded(download) {
     DownloadsViewPrototype.onDownloadAdded.call(this, download);
     this._itemCount++;
     this._updateViews();
   },
 
   onDownloadStateChanged(download) {
     if (!download.succeeded && download.error && download.error.reputationCheckVerdict) {
@@ -1145,30 +1152,16 @@ DownloadsIndicatorDataCtor.prototype = {
     this._attentionSuppressed = aValue;
     this._attention = DownloadsCommon.ATTENTION_NONE;
     this._updateViews();
     return aValue;
   },
   _attentionSuppressed: false,
 
   /**
-   * Computes aggregate values and propagates the changes to our views.
-   */
-  _updateViews() {
-    // Do not update the status indicators during batch loads of download items.
-    if (this._loading) {
-      return;
-    }
-
-    this._refreshProperties();
-
-    this._views.forEach(this._updateView, this);
-  },
-
-  /**
    * Updates the specified view with the current aggregate values.
    *
    * @param aView
    *        DownloadsIndicatorView object to be updated.
    */
   _updateView(aView) {
     aView.hasDownloads = this._hasDownloads;
     aView.percentComplete = this._percentComplete;
@@ -1292,25 +1285,16 @@ DownloadsSummaryData.prototype = {
 
     if (this._views.length == 0) {
       // Clear out our collection of Download objects. If we ever have
       // another view registered with us, this will get re-populated.
       this._downloads = [];
     }
   },
 
-  // Callback functions from DownloadsData - see the documentation in
-  // DownloadsViewPrototype for more information on what these functions
-  // are used for.
-
-  onDataLoadCompleted() {
-    DownloadsViewPrototype.onDataLoadCompleted.call(this);
-    this._updateViews();
-  },
-
   onDownloadAdded(download) {
     DownloadsViewPrototype.onDownloadAdded.call(this, download);
     this._downloads.unshift(download);
     this._updateViews();
   },
 
   onDownloadStateChanged() {
     // Since the state of a download changed, reset the estimated time left.
@@ -1327,29 +1311,16 @@ DownloadsSummaryData.prototype = {
     let itemIndex = this._downloads.indexOf(download);
     this._downloads.splice(itemIndex, 1);
     this._updateViews();
   },
 
   // Propagation of properties to our views
 
   /**
-   * Computes aggregate values and propagates the changes to our views.
-   */
-  _updateViews() {
-    // Do not update the status indicators during batch loads of download items.
-    if (this._loading) {
-      return;
-    }
-
-    this._refreshProperties();
-    this._views.forEach(this._updateView, this);
-  },
-
-  /**
    * Updates the specified view with the current aggregate values.
    *
    * @param aView
    *        DownloadsIndicatorView object to be updated.
    */
   _updateView(aView) {
     aView.showingProgress = this._showingProgress;
     aView.percentComplete = this._percentComplete;