Bug 520284 - Use the update-timer category. r=robstrong
authorRyan Flint <rflint@ryanflint.com>
Thu, 07 Jan 2010 23:25:44 -0500
changeset 36944 0c8d99d73f0912970718a4b2039807d0ee02d76a
parent 36943 04e78ad9a910368b4ab55f34c5313d6bb3594674
child 36945 500e3dbc7d35c92e04342672dd7c80536a868b44
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersrobstrong
bugs520284
milestone1.9.3a1pre
Bug 520284 - Use the update-timer category. r=robstrong
browser/app/profile/firefox.js
toolkit/components/search/nsSearchService.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -296,17 +296,17 @@ pref("browser.search.openintab", false);
 
 // send ping to the server to update
 pref("browser.search.update", true);
 
 // disable logging for the search service update system by default
 pref("browser.search.update.log", false);
 
 // Check whether we need to perform engine updates every 6 hours
-pref("browser.search.updateinterval", 6);
+pref("browser.search.update.interval", 21600);
 
 // Whether or not microsummary and generator updates are enabled
 pref("browser.microsummary.enabled", true);
 pref("browser.microsummary.updateGenerators", true);
 
 // enable search suggestions by default
 pref("browser.search.suggest.enabled", true);
 
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -2457,52 +2457,40 @@ Submission.prototype = {
         aIID.equals(Ci.nsISupports))
       return this;
     throw Cr.NS_ERROR_NO_INTERFACE;
   }
 }
 
 // nsIBrowserSearchService
 function SearchService() {
-  this._init();
+  // Replace empty LOG function with the useful one if the log pref is set.
+  if (getBoolPref(BROWSER_SEARCH_PREF + "log", false))
+    LOG = DO_LOG;
+
+  try {
+    this._loadEngines();
+  } catch (ex) {
+    LOG("_init: failure loading engines: " + ex);
+  }
+  this._addObservers();
 }
 SearchService.prototype = {
   _engines: { },
   __sortedEngines: null,
   get _sortedEngines() {
     if (!this.__sortedEngines)
       return this._buildSortedEngineList();
     return this.__sortedEngines;
   },
 
   // Whether or not we need to write the order of engines on shutdown. This
   // needs to happen anytime _sortedEngines is modified after initial startup. 
   _needToSetOrderPrefs: false,
 
-  _init: function() {
-    // Replace empty LOG function with the useful one if the log pref is set.
-    if (getBoolPref(BROWSER_SEARCH_PREF + "log", false))
-      LOG = DO_LOG;
-
-    engineUpdateService.init();
-
-    try {
-      this._loadEngines();
-    } catch (ex) {
-      LOG("_init: failure loading engines: " + ex);
-    }
-
-    this._addObservers();
-
-    let selectedEngineName = getLocalizedPref(BROWSER_SEARCH_PREF +
-                                              "selectedEngine");
-    this._currentEngine = this.getEngineByName(selectedEngineName) ||
-                          this.defaultEngine;
-  },
-
   _buildCache: function SRCH_SVC__buildCache() {
     if (!getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true))
       return;
 
     let cache = {};
     let locale = getLocale();
     let buildID = Cc["@mozilla.org/xre/app-info;1"].
                   getService(Ci.nsIXULAppInfo).platformBuildID;
@@ -2515,17 +2503,16 @@ SearchService.prototype = {
     // (where the buildID is obviously going to change).
     // Extension-shipped plugins are the only exception to this, but their
     // directories are blown away during updates, so we'll detect their changes.
     cache.buildID = buildID;
     cache.locale = locale;
 
     cache.directories = {};
 
-
     function getParent(engine) {
       if (engine._file)
         return engine._file.parent;
 
       let uri = engine._uri;
       if (!uri.schemeIs("chrome")) {
         LOG("getParent: engine URI must be a chrome URI if it has no file");
         return null;
@@ -3375,16 +3362,22 @@ SearchService.prototype = {
     // might be hidden
     this._defaultEngine = this.getEngineByName(getLocalizedPref(defPref, ""));
     if (!this._defaultEngine || this._defaultEngine.hidden)
       this._defaultEngine = this._getSortedEngines(false)[0] || null;
     return this._defaultEngine;
   },
 
   get currentEngine() {
+    if (!this._currentEngine) {
+      let selectedEngine = getLocalizedPref(BROWSER_SEARCH_PREF +
+                                            "selectedEngine");
+      this._currentEngine = this.getEngineByName(selectedEngine);
+    }
+
     if (!this._currentEngine || this._currentEngine.hidden)
       this._currentEngine = this.defaultEngine;
     return this._currentEngine;
   },
   set currentEngine(val) {
     if (!(val instanceof Ci.nsISearchEngine))
       FAIL("Invalid argument passed to currentEngine setter");
 
@@ -3437,29 +3430,69 @@ SearchService.prototype = {
           // Flush to disk immediately
           this._batchTimer.cancel();
           this._buildCache();
         }
         break;
     }
   },
 
+  // nsITimerCallback
+  notify: function SRCH_SVC_notify(aTimer) {
+    LOG("_notify: checking for updates");
+
+    if (!getBoolPref(BROWSER_SEARCH_PREF + "update", true))
+      return;
+
+    // Our timer has expired, but unfortunately, we can't get any data from it.
+    // Therefore, we need to walk our engine-list, looking for expired engines
+    var currentTime = Date.now();
+    LOG("currentTime: " + currentTime);
+    for each (engine in this._engines) {
+      engine = engine.wrappedJSObject;
+      if (!engine._hasUpdates)
+        continue;
+
+      LOG("checking " + engine.name);
+
+      var expirTime = engineMetadataService.getAttr(engine, "updateexpir");
+      LOG("expirTime: " + expirTime + "\nupdateURL: " + engine._updateURL +
+          "\niconUpdateURL: " + engine._iconUpdateURL);
+
+      var engineExpired = expirTime <= currentTime;
+
+      if (!expirTime || !engineExpired) {
+        LOG("skipping engine");
+        continue;
+      }
+
+      LOG(engine.name + " has expired");
+
+      engineUpdateService.update(engine);
+
+      // Schedule the next update
+      engineUpdateService.scheduleNextUpdate(engine);
+
+    } // end engine iteration
+  },
+
   _addObservers: function SRCH_SVC_addObservers() {
     gObsSvc.addObserver(this, SEARCH_ENGINE_TOPIC, false);
     gObsSvc.addObserver(this, QUIT_APPLICATION_TOPIC, false);
   },
 
   _removeObservers: function SRCH_SVC_removeObservers() {
     gObsSvc.removeObserver(this, SEARCH_ENGINE_TOPIC);
     gObsSvc.removeObserver(this, QUIT_APPLICATION_TOPIC);
   },
 
   QueryInterface: function SRCH_SVC_QI(aIID) {
     if (aIID.equals(Ci.nsIBrowserSearchService) ||
         aIID.equals(Ci.nsIObserver)             ||
+        aIID.equals(Ci.nsITimerCallback)        ||
         aIID.equals(Ci.nsISupports))
       return this;
     throw Cr.NS_ERROR_NO_INTERFACE;
   }
 };
 
 var engineMetadataService = {
   get mDB() {
@@ -3594,28 +3627,16 @@ function ULOG(aText) {
     dump(SEARCH_UPDATE_LOG_PREFIX + aText + "\n");
     var consoleService = Cc["@mozilla.org/consoleservice;1"].
                          getService(Ci.nsIConsoleService);
     consoleService.logStringMessage(aText);
   }
 }
 
 var engineUpdateService = {
-  init: function eus_init() {
-    var tm = Cc["@mozilla.org/updates/timer-manager;1"].
-             getService(Ci.nsIUpdateTimerManager);
-    // figure out how often to check for any expired engines
-    var interval = gPrefSvc.getIntPref(BROWSER_SEARCH_PREF + "updateinterval");
-
-    // Interval is stored in hours
-    var seconds = interval * 3600;
-    tm.registerTimer("search-engine-update-timer", engineUpdateService,
-                     seconds);
-  },
-
   scheduleNextUpdate: function eus_scheduleNextUpdate(aEngine) {
     var interval = aEngine._updateInterval || SEARCH_DEFAULT_UPDATE_INTERVAL;
     var milliseconds = interval * 86400000; // |interval| is in days
     engineMetadataService.setAttr(aEngine, "updateexpir",
                                   Date.now() + milliseconds);
   },
 
   update: function eus_Update(aEngine) {
@@ -3654,56 +3675,16 @@ var engineUpdateService = {
     } else
       ULOG("invalid updateURI");
 
     if (engine._iconUpdateURL) {
       // If we're updating the engine too, use the new engine object,
       // otherwise use the existing engine object.
       (testEngine || engine)._setIcon(engine._iconUpdateURL, true);
     }
-  },
-
-  notify: function eus_Notify(aTimer) {
-    ULOG("notify called");
-
-    if (!getBoolPref(BROWSER_SEARCH_PREF + "update", true))
-      return;
-
-    // Our timer has expired, but unfortunately, we can't get any data from it.
-    // Therefore, we need to walk our engine-list, looking for expired engines
-    var searchService = Cc["@mozilla.org/browser/search-service;1"].
-                        getService(Ci.nsIBrowserSearchService);
-    var currentTime = Date.now();
-    ULOG("currentTime: " + currentTime);
-    for each (engine in searchService.getEngines()) {
-      engine = engine.wrappedJSObject;
-      if (!engine._hasUpdates)
-        continue;
-
-      ULOG("checking " + engine.name);
-
-      var expirTime = engineMetadataService.getAttr(engine, "updateexpir");
-      ULOG("expirTime: " + expirTime + "\nupdateURL: " + engine._updateURL +
-           "\niconUpdateURL: " + engine._iconUpdateURL);
-
-      var engineExpired = expirTime <= currentTime;
-
-      if (!expirTime || !engineExpired) {
-        ULOG("skipping engine");
-        continue;
-      }
-
-      ULOG(engine.name + " has expired");
-
-      this.update(engine);
-
-      // Schedule the next update
-      this.scheduleNextUpdate(engine);
-
-    } // end engine iteration
   }
 };
 
 const kClassID    = Components.ID("{7319788a-fe93-4db3-9f39-818cf08f4256}");
 const kClassName  = "Browser Search Service";
 const kContractID = "@mozilla.org/browser/search-service;1";
 
 // nsIFactory
@@ -3712,27 +3693,40 @@ const kFactory = {
     if (outer != null)
       throw Cr.NS_ERROR_NO_AGGREGATION;
     return (new SearchService()).QueryInterface(iid);
   }
 };
 
 // nsIModule
 const gModule = {
+  get _catMan() {
+    return Cc["@mozilla.org/categorymanager;1"].
+           getService(Ci.nsICategoryManager);
+  },
+
   registerSelf: function (componentManager, fileSpec, location, type) {
     componentManager.QueryInterface(Ci.nsIComponentRegistrar);
     componentManager.registerFactoryLocation(kClassID,
                                              kClassName,
                                              kContractID,
                                              fileSpec, location, type);
+    this._catMan.addCategoryEntry("update-timer", kClassName,
+                                  kContractID + 
+                                  ",getService," +
+                                  "search-engine-update-timer," +
+                                  BROWSER_SEARCH_PREF + "update.interval," +
+                                  "21600", /* 6 hours */
+                                  true, true);
   },
 
   unregisterSelf: function(componentManager, fileSpec, location) {
     componentManager.QueryInterface(Ci.nsIComponentRegistrar);
     componentManager.unregisterFactoryLocation(kClassID, fileSpec);
+    this._catMan.deleteCategoryEntry("update-timer", kClassName, true);
   },
 
   getClassObject: function (componentManager, cid, iid) {
     if (!cid.equals(kClassID))
       throw Cr.NS_ERROR_NO_INTERFACE;
     if (!iid.equals(Ci.nsIFactory))
       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
     return kFactory;