Bug 1379831 Make sure we always load the XPI database
Telemetry requires information that we read from the XPI database and
it blocks shutdown until it gets that information. Now that we're no
longer loading the XPI database during startup, create a safety net here
and load the database if it isn't already loaded when shutdown begins.
MozReview-Commit-ID: LkoNn7wusxN
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -2324,17 +2324,17 @@ this.XPIProvider = {
},
/**
* Shuts down the database and releases all references.
* Return: Promise{integer} resolves / rejects with the result of
* flushing the XPI Database if it was loaded,
* 0 otherwise.
*/
- shutdown() {
+ async shutdown() {
logger.debug("shutdown");
// Stop anything we were doing asynchronously
this.cancelAll();
// Uninstall any temporary add-ons.
let tempLocation = XPIStates.getLocation(TemporaryInstallLocation.name);
if (tempLocation) {
@@ -2366,42 +2366,36 @@ this.XPIProvider = {
// If there are pending operations then we must update the list of active
// add-ons
if (Preferences.get(PREF_PENDING_OPERATIONS, false)) {
AddonManagerPrivate.recordSimpleMeasure("XPIDB_pending_ops", 1);
XPIDatabase.updateActiveAddons();
Services.prefs.setBoolPref(PREF_PENDING_OPERATIONS, false);
}
+ // Ugh, if we reach this point without loading the xpi database,
+ // we need to load it know, otherwise the telemetry shutdown blocker
+ // will never resolve.
+ if (!XPIDatabase.initialized) {
+ await XPIDatabase.asyncLoadDB();
+ }
+
this.installs = null;
this.installLocations = null;
this.installLocationsByName = null;
// This is needed to allow xpcshell tests to simulate a restart
this.extensionsActive = false;
this._addonFileMap.clear();
- if (gLazyObjectsLoaded) {
- let done = XPIDatabase.shutdown();
- done.then(
- ret => {
- logger.debug("Notifying XPI shutdown observers");
- Services.obs.notifyObservers(null, "xpi-provider-shutdown");
- },
- err => {
- logger.debug("Notifying XPI shutdown observers");
- this._shutdownError = err;
- Services.obs.notifyObservers(null, "xpi-provider-shutdown", err);
- }
- );
- return done;
- }
- logger.debug("Notifying XPI shutdown observers");
- Services.obs.notifyObservers(null, "xpi-provider-shutdown");
- return undefined;
+ try {
+ await XPIDatabase.shutdown();
+ } catch (err) {
+ this._shutdownError = err;
+ }
},
/**
* Applies any pending theme change to the preferences.
*/
applyThemeChange() {
if (!Preferences.get(PREF_SKIN_SWITCHPENDING, false))
return;