Bug 1313960 - synchronous addon DB loader should handle in-progress async load r=kmag
authorRobert Helmer <rhelmer@mozilla.com>
Tue, 15 Nov 2016 13:40:47 -0800
changeset 440384 ca88bad072d09be6bd6229cf94465c93116c3beb
parent 440383 eae1056ae373b94d922c3a78cfaf72b3f80190b2
child 440385 91c099f8ec09b1fbf9b0159210f63a25f63d7208
push id36216
push userbmo:ato@mozilla.com
push dateThu, 17 Nov 2016 13:57:13 +0000
reviewerskmag
bugs1313960
milestone53.0a1
Bug 1313960 - synchronous addon DB loader should handle in-progress async load r=kmag MozReview-Commit-ID: LwzmRr3PdXx
toolkit/mozapps/extensions/internal/XPIProviderUtils.js
--- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js
+++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js
@@ -614,24 +614,21 @@ this.XPIDatabase = {
       else {
         this.rebuildUnreadableDB(e, aRebuildOnError);
       }
     }
     finally {
       if (fstream)
         fstream.close();
     }
-    // If an async load was also in progress, resolve that promise with our DB;
-    // otherwise create a resolved promise
+    // If an async load was also in progress, record in telemetry.
     if (this._dbPromise) {
       AddonManagerPrivate.recordSimpleMeasure("XPIDB_overlapped_load", 1);
-      this._dbPromise.resolve(this.addonDB);
     }
-    else
-      this._dbPromise = Promise.resolve(this.addonDB);
+    this._dbPromise = Promise.resolve(this.addonDB);
   },
 
   /**
    * Parse loaded data, reconstructing the database if the loaded data is not valid
    * @param aRebuildOnError
    *        If true, synchronously reconstruct the database from installed add-ons
    */
   parseDB: function(aData, aRebuildOnError) {
@@ -765,31 +762,32 @@ this.XPIDatabase = {
     let readOptions = {
       outExecutionDuration: 0
     };
     return this._dbPromise = OS.File.read(this.jsonFile.path, null, readOptions).then(
       byteArray => {
         logger.debug("Async JSON file read took " + readOptions.outExecutionDuration + " MS");
         AddonManagerPrivate.recordSimpleMeasure("XPIDB_asyncRead_MS",
           readOptions.outExecutionDuration);
-        if (this._addonDB) {
+
+        if (this.addonDB) {
           logger.debug("Synchronous load completed while waiting for async load");
           return this.addonDB;
         }
         logger.debug("Finished async read of XPI database, parsing...");
         let decodeTimer = AddonManagerPrivate.simpleTimer("XPIDB_decode_MS");
         let decoder = new TextDecoder();
         let data = decoder.decode(byteArray);
         decodeTimer.done();
         this.parseDB(data, true);
         return this.addonDB;
       })
-    .then(null,
+    .catch(
       error => {
-        if (this._addonDB) {
+        if (this.addonDB) {
           logger.debug("Synchronous load completed while waiting for async load");
           return this.addonDB;
         }
         if (error.becauseNoSuchFile) {
           this.upgradeDB(true);
         }
         else {
           // it's there but unreadable