Bug 1365509: Don't trigger a sync load of the add-ons DB at startup when a built-in LWT is enabled. r?rhelmer draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 17 May 2017 13:51:42 -0700
changeset 579853 d9fe525f493d234d2684f09802fe7cda698b9b59
parent 579852 f0ce0e47812e64a8bef91115dcfe99c62ba46923
child 629128 f319a651d1a60fde4251ac8beb3562a79631fcd1
push id59381
push usermaglione.k@gmail.com
push dateWed, 17 May 2017 20:53:16 +0000
reviewersrhelmer
bugs1365509
milestone55.0a1
Bug 1365509: Don't trigger a sync load of the add-ons DB at startup when a built-in LWT is enabled. r?rhelmer MozReview-Commit-ID: AG0dXSnBwZ3
toolkit/mozapps/extensions/LightweightThemeManager.jsm
toolkit/mozapps/extensions/internal/XPIProviderUtils.js
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -667,16 +667,18 @@ function _setCurrentTheme(aData, aLocal)
   let needsRestart = (ADDON_TYPE == "theme") &&
                      Services.prefs.prefHasUserValue(PREF_GENERAL_SKINS_SELECTEDSKIN);
 
   let cancel = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
   cancel.data = false;
   Services.obs.notifyObservers(cancel, "lightweight-theme-change-requested",
                                JSON.stringify(aData));
 
+  let notify = true;
+
   if (aData) {
     let theme = LightweightThemeManager.getUsedTheme(aData.id);
     let isInstall = !theme || theme.version != aData.version;
     if (isInstall) {
       aData.updateDate = Date.now();
       if (theme && "installDate" in theme)
         aData.installDate = theme.installDate;
       else
@@ -686,31 +688,37 @@ function _setCurrentTheme(aData, aLocal)
       var wrapper = new AddonWrapper(aData);
       AddonManagerPrivate.callInstallListeners("onExternalInstall", null,
                                                wrapper, oldWrapper, false);
       AddonManagerPrivate.callAddonListeners("onInstalling", wrapper, false);
     }
 
     let current = LightweightThemeManager.currentTheme;
     let usedThemes = _usedThemesExceptId(aData.id);
-    if (current && current.id != aData.id)
+    if (current && current.id != aData.id) {
       usedThemes.splice(1, 0, aData);
-    else
+    } else {
+      if (current && current.id == aData.id) {
+        notify = false;
+      }
       usedThemes.unshift(aData);
+    }
     _updateUsedThemes(usedThemes);
 
     if (isInstall)
       AddonManagerPrivate.callAddonListeners("onInstalled", wrapper);
   }
 
   if (cancel.data)
     return null;
 
-  AddonManagerPrivate.notifyAddonChanged(aData ? aData.id + ID_SUFFIX : null,
-                                         ADDON_TYPE, needsRestart);
+  if (notify) {
+    AddonManagerPrivate.notifyAddonChanged(aData ? aData.id + ID_SUFFIX : null,
+                                           ADDON_TYPE, needsRestart);
+  }
 
   return LightweightThemeManager.currentTheme;
 }
 
 function _sanitizeTheme(aData, aBaseURI, aLocal) {
   if (!aData || typeof aData != "object")
     return null;
 
--- a/toolkit/mozapps/extensions/internal/XPIProviderUtils.js
+++ b/toolkit/mozapps/extensions/internal/XPIProviderUtils.js
@@ -817,18 +817,19 @@ this.XPIDatabase = {
    *         The type(s) of add-on to retrieve
    * @return an array of DBAddonInternals
    */
   getAddonsByType(...aTypes) {
     if (!this.addonDB) {
       // jank-tastic! Must synchronously load DB if the theme switches from
       // an XPI theme to a lightweight theme before the DB has loaded,
       // because we're called from sync XPIProvider.addonChanged
-      logger.warn("Synchronous load of XPI database due to getAddonsByType([" +
-        aTypes.join(", ") + "])");
+      logger.warn(`Synchronous load of XPI database due to ` +
+                  `getAddonsByType([${aTypes.join(", ")}]) ` +
+                  `Stack: ${Error().stack}`);
       AddonManagerPrivate.recordSimpleMeasure("XPIDB_lateOpen_byType", XPIProvider.runPhase);
       this.syncLoadDB(true);
     }
 
     return _filterDB(this.addonDB, aAddon => aTypes.includes(aAddon.type));
   },
 
   /**
@@ -836,17 +837,18 @@ this.XPIDatabase = {
    *
    * @param  aInternalName
    *         The internalName of the add-on to retrieve
    * @return a DBAddonInternal
    */
   getVisibleAddonForInternalName(aInternalName) {
     if (!this.addonDB) {
       // This may be called when the DB hasn't otherwise been loaded
-      logger.warn("Synchronous load of XPI database due to getVisibleAddonForInternalName");
+      logger.warn(`Synchronous load of XPI database due to ` +
+                  `getVisibleAddonForInternalName. Stack: ${Error().stack}`);
       AddonManagerPrivate.recordSimpleMeasure("XPIDB_lateOpen_forInternalName",
           XPIProvider.runPhase);
       this.syncLoadDB(true);
     }
 
     return _findAddon(this.addonDB,
                       aAddon => aAddon.visible &&
                                 (aAddon.internalName == aInternalName));