Bug 540356 - Enforce a sane minimum interval of 60 seconds for app.update.timer and provide mechanism for tests to have a minimum interval of 500 ms. r=dolske
authorRobert Strong <robert.bugzilla@gmail.com>
Sun, 31 Jan 2010 15:15:13 -0800
changeset 37781 8d97e554054633f72005cffb6d55c481fa3c5539
parent 37780 e5958f05a6dcf7442bb5a0c179030e8f1ef9d776
child 37782 46267f0a4b3e7f6cf7036b7f3a53e0bc9bc1d6a2
push id11429
push userrstrong@mozilla.com
push dateSun, 31 Jan 2010 23:16:09 +0000
treeherderautoland@b9d29c3997e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs540356
milestone1.9.3a1pre
Bug 540356 - Enforce a sane minimum interval of 60 seconds for app.update.timer and provide mechanism for tests to have a minimum interval of 500 ms. r=dolske
toolkit/mozapps/update/src/nsUpdateTimerManager.js
toolkit/mozapps/update/test_timermanager/unit/test_0010_timermanager.js
--- a/toolkit/mozapps/update/src/nsUpdateTimerManager.js
+++ b/toolkit/mozapps/update/src/nsUpdateTimerManager.js
@@ -133,19 +133,35 @@ TimerManager.prototype = {
   get _fudge() {
     return Math.round(Math.random() * this._timerInterval / 1000);
   },
 
   /**
    * See nsIObserver.idl
    */
   observe: function TM_observe(aSubject, aTopic, aData) {
+    // Prevent setting the timer interval to a value of less than 60 seconds.
+    var minInterval = 60000;
     switch (aTopic) {
+    case "utm-test-init":
+      // Enforce a minimum timer interval of 500 ms for tests and fall through
+      // to profile-after-change to initialize the timer.
+      minInterval = 500;
     case "profile-after-change":
-      this._start();
+      // Cancel the timer if it has already been initialized. This is primarily
+      // for tests.
+      if (this._timer) {
+        this._timer.cancel();
+        this._timer = null;
+      }
+      this._timerInterval = Math.max(getPref("getIntPref", PREF_APP_UPDATE_TIMER, 600000),
+                                     minInterval);
+      this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+      this._timer.initWithCallback(this, this._timerInterval,
+                                   Ci.nsITimer.TYPE_REPEATING_SLACK);
       break;
     case "xpcom-shutdown":
       let os = getObserverService();
       os.removeObserver(this, "xpcom-shutdown");
 
       // Release everything we hold onto.
       if (this._timer) {
         this._timer.cancel();
@@ -153,22 +169,16 @@ TimerManager.prototype = {
       }
       for (var timerID in this._timers)
         delete this._timers[timerID];
       this._timers = null;
       break;
     }
   },
 
-  _start: function TM__start() {
-    this._timerInterval = getPref("getIntPref", "app.update.timer", 600000);
-    this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    this._timer.initWithCallback(this, this._timerInterval,
-                                 Ci.nsITimer.TYPE_REPEATING_SLACK);
-  },
   /**
 #    Called when the checking timer fires.
 #    @param   timer
 #             The checking timer that fired.
    */
   notify: function TM_notify(timer) {
     var prefLastUpdate;
     var lastUpdateTime;
--- a/toolkit/mozapps/update/test_timermanager/unit/test_0010_timermanager.js
+++ b/toolkit/mozapps/update/test_timermanager/unit/test_0010_timermanager.js
@@ -145,17 +145,17 @@ function run_test() {
   while (entries.hasMoreElements()) {
     let entry = entries.getNext().QueryInterface(Ci.nsISupportsCString).data;
     gCatMan.deleteCategoryEntry(CATEGORY_UPDATE_TIMER, entry, false);
   }
 
   gUTM = Cc["@mozilla.org/updates/timer-manager;1"].
          getService(Ci.nsIUpdateTimerManager).
          QueryInterface(Ci.nsIObserver);
-  gUTM.observe(null, "profile-after-change", "");
+  gUTM.observe(null, "utm-test-init", "");
 
   do_execute_soon(run_test1thru6);
 }
 
 function end_test() {
   gUTM.observe(null, "xpcom-shutdown", "");
   do_test_finished();
 }