Bug 1313960 - synchronous addon DB loader should handle in-progress async load r?kmag
MozReview-Commit-ID: LwzmRr3PdXx
--- 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