Bug 1445990 - delay lazy loading if we happen to be loaded prior to profile-after-change, r?florian draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 16 Mar 2018 14:23:47 +0000
changeset 768798 21c5c2bc5067c2bb012ec611c757ed91fbcab9af
parent 768797 d7e9797d094542b0bd0aaa72dd82fad1b6e83e50
push id102981
push usergijskruitbosch@gmail.com
push dateFri, 16 Mar 2018 21:04:14 +0000
reviewersflorian
bugs1445990
milestone61.0a1
Bug 1445990 - delay lazy loading if we happen to be loaded prior to profile-after-change, r?florian MozReview-Commit-ID: KBeNDXOThjo
toolkit/mozapps/extensions/nsBlocklistService.js
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -261,16 +261,22 @@ Blocklist.prototype = {
     Services.prefs.removeObserver(PREF_EM_LOGGING_ENABLED, this);
   },
 
   observe(aSubject, aTopic, aData) {
     switch (aTopic) {
     case "xpcom-shutdown":
       this.shutdown();
       break;
+    case "profile-after-change":
+      Services.obs.removeObserver(this, "profile-after-change");
+      if (!this.isLoaded) {
+        this.loadBlocklistAsync();
+      }
+      break;
     case "nsPref:changed":
       switch (aData) {
         case PREF_EM_LOGGING_ENABLED:
           gLoggingEnabled = Services.prefs.getBoolPref(PREF_EM_LOGGING_ENABLED, false);
           break;
         case PREF_BLOCKLIST_ENABLED:
           gBlocklistEnabled = Services.prefs.getBoolPref(PREF_BLOCKLIST_ENABLED, true);
           this._loadBlocklist();
@@ -778,17 +784,25 @@ Blocklist.prototype = {
   /* Used for testing */
   _clear() {
     this._addonEntries = null;
     this._gfxEntries = null;
     this._pluginEntries = null;
   },
 
   async loadBlocklistAsync() {
-    let profPath = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
+    let profPath;
+    try {
+      // Getting the profile path can fail if we're called before there's a profile.
+      profPath = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
+    } catch (ex) {
+      // Wait until we have a profile and don't try to load now.
+      Services.obs.addObserver(this, "profile-after-change");
+      return;
+    }
     try {
       await this._preloadBlocklistFile(profPath);
       return;
     } catch (e) {
       LOG("Blocklist::loadBlocklistAsync: Failed to load XML file " + e);
     }
 
     var appFile = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);