Bug 1445990 - delay lazy loading if we happen to be loaded prior to profile-after-change, r?florian
MozReview-Commit-ID: KBeNDXOThjo
--- 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]);