Bug 454546: Update EM and blocklist service to be initialised on profile-after-change. r=robstrong, a1.9.1=beltzner
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 28 Nov 2008 12:49:48 -0800
changeset 22097 169f2cc23290f64465169635768558d01ca6e804
parent 22096 c99b74e60a17765f56dc4a25ec4b36e63d8d41b6
child 22098 b7fda2af9255124616b9708f6cdbcf034381d593
push idunknown
push userunknown
push dateunknown
reviewersrobstrong
bugs454546
milestone1.9.1b3pre
Bug 454546: Update EM and blocklist service to be initialised on profile-after-change. r=robstrong, a1.9.1=beltzner
toolkit/mozapps/extensions/src/nsBlocklistService.js
toolkit/mozapps/extensions/src/nsExtensionManager.js.in
toolkit/mozapps/extensions/test/unit/head_extensionmanager.js
toolkit/mozapps/extensions/test/unit/test_bug430120.js
--- a/toolkit/mozapps/extensions/src/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/src/nsBlocklistService.js
@@ -377,39 +377,31 @@ Blocklist.prototype = {
    *                   "maxVersion"  The maximum version in a version range
    *                                 (default = *)
    */
   _addonEntries: null,
   _pluginEntries: null,
 
   observe: function (aSubject, aTopic, aData) {
     switch (aTopic) {
-    case "app-startup":
-      gOS.addObserver(this, "profile-after-change", false);
-      gOS.addObserver(this, "quit-application", false);
-      break;
     case "profile-after-change":
       gLoggingEnabled = getPref("getBoolPref", PREF_EM_LOGGING_ENABLED, false);
       gBlocklistEnabled = getPref("getBoolPref", PREF_BLOCKLIST_ENABLED, true);
       gBlocklistLevel = Math.min(getPref("getIntPref", PREF_BLOCKLIST_LEVEL, DEFAULT_LEVEL),
                                  MAX_BLOCK_LEVEL);
       gPref.addObserver("extensions.blocklist.", this, false);
       var tm = Cc["@mozilla.org/updates/timer-manager;1"].
                getService(Ci.nsIUpdateTimerManager);
       var interval = getPref("getIntPref", PREF_BLOCKLIST_INTERVAL, 86400);
       tm.registerTimer("blocklist-background-update-timer", this, interval);
       break;
-    case "quit-application":
-      gOS.removeObserver(this, "profile-after-change");
-      gOS.removeObserver(this, "quit-application");
-      gPref.removeObserver("extensions.blocklist.", this);
-      break;
     case "xpcom-shutdown":
       gOS.removeObserver(this, "xpcom-shutdown");
       gOS = null;
+      gPref.removeObserver("extensions.blocklist.", this);
       gPref = null;
       gConsole = null;
       gVersionChecker = null;
       gApp = null;
       break;
     case "nsPref:changed":
       switch (aData) {
         case PREF_BLOCKLIST_ENABLED:
@@ -922,20 +914,17 @@ Blocklist.prototype = {
   },
 
   classDescription: "Blocklist Service",
   contractID: "@mozilla.org/extensions/blocklist;1",
   classID: Components.ID("{66354bc9-7ed1-4692-ae1d-8da97d6b205e}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                          Ci.nsIBlocklistService,
                                          Ci.nsITimerCallback]),
-  _xpcom_categories: [{
-    category: "app-startup",
-    service: true
-  }]
+  _xpcom_categories: [{ category: "profile-after-change" }]
 };
 
 /**
  * Helper for constructing a blocklist.
  */
 function BlocklistItemData(versionRangeElement) {
   var versionRange = this.getBlocklistVersionRange(versionRangeElement);
   this.minVersion = versionRange.minVersion;
--- a/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
+++ b/toolkit/mozapps/extensions/src/nsExtensionManager.js.in
@@ -2514,33 +2514,25 @@ function ExtensionManager() {
 }
 
 ExtensionManager.prototype = {
   /**
    * See nsIObserver.idl
    */
   observe: function EM_observe(subject, topic, data) {
     switch (topic) {
-    case "app-startup":
-      gOS.addObserver(this, "profile-after-change", false);
-      gOS.addObserver(this, "quit-application", false);
-      break;
     case "profile-after-change":
       this._profileSelected();
       break;
     case "quit-application-requested":
       this._confirmCancelDownloadsOnQuit(subject);
       break;
     case "offline-requested":
       this._confirmCancelDownloadsOnOffline(subject);
       break;
-    case "quit-application":
-      gOS.removeObserver(this, "profile-after-change");
-      gOS.removeObserver(this, "quit-application");
-      break;
     case "xpcom-shutdown":
       this._shutdown();
       break;
     case "nsPref:changed":
       if (data == PREF_EM_LOGGING_ENABLED)
         this._loggingToggled();
       else if (data == PREF_EM_CHECK_COMPATIBILITY ||
                data == PREF_EM_CHECK_UPDATE_SECURITY)
@@ -5956,17 +5948,17 @@ ExtensionManager.prototype = {
     var interfaces = [Ci.nsIExtensionManager, Ci.nsIObserver];
     count.value = interfaces.length;
     return interfaces;
   },
 
   classDescription: "Extension Manager",
   contractID: "@mozilla.org/extensions/manager;1",
   classID: Components.ID("{8A115FAA-7DCB-4e8f-979B-5F53472F51CF}"),
-  _xpcom_categories: [{ category: "app-startup", service: true }],
+  _xpcom_categories: [{ category: "profile-after-change" }],
   _xpcom_factory: {
     createInstance: function(outer, iid) {
       if (outer != null)
         throw Cr.NS_ERROR_NO_AGGREGATION;
   
       if (!gEmSingleton)
         gEmSingleton = new ExtensionManager();
       return gEmSingleton.QueryInterface(iid);
--- a/toolkit/mozapps/extensions/test/unit/head_extensionmanager.js
+++ b/toolkit/mozapps/extensions/test/unit/head_extensionmanager.js
@@ -211,17 +211,16 @@ function startupEM()
   // Make sure the update service is initialised.
   var updateSvc = Components.classes["@mozilla.org/updates/update-service;1"]
                             .getService(Components.interfaces.nsISupports);
   
   gEM = Components.classes["@mozilla.org/extensions/manager;1"]
                   .getService(Components.interfaces.nsIExtensionManager);
   
   gEM.QueryInterface(Components.interfaces.nsIObserver);
-  gEM.observe(null, "app-startup", null);
   gEM.observe(null, "profile-after-change", "startup");
 
   // First run is a new profile which nsAppRunner would consider as an update
   // (no existing compatibility.ini)
   var upgraded = true;
   var needsRestart = false;
   try {
     needsRestart = gEM.checkForMismatches();
--- a/toolkit/mozapps/extensions/test/unit/test_bug430120.js
+++ b/toolkit/mozapps/extensions/test/unit/test_bug430120.js
@@ -126,17 +126,16 @@ function run_test() {
   testserver.registerPathHandler("/1", failHandler);
   testserver.registerPathHandler("/2", pathHandler);
   testserver.start(4444);
 
   // Initialise the blocklist service
   gBlocklist = Components.classes["@mozilla.org/extensions/blocklist;1"]
                          .getService(Components.interfaces.nsIBlocklistService)
                          .QueryInterface(Components.interfaces.nsIObserver);
-  gBlocklist.observe(null, "app-startup", "");
   gBlocklist.observe(null, "profile-after-change", "");
 
   do_check_true(timerService.hasTimer(BLOCKLIST_TIMER));
 
   do_test_pending();
 
   // This should have no effect as the blocklist is disabled
   gPrefs.setCharPref(PREF_BLOCKLIST_URL, "http://localhost:4444/1");