Bug 1181489 - Adding sanity checks into the alarm service for preventing from the alarm works erroneously. r=fabrice
authorTim Huang <tihuang@mozilla.com>
Tue, 22 Sep 2015 19:29:00 +0200
changeset 264139 a91c821d85b793430979dc8a1183622cc63e5a7b
parent 264138 a40d943a6ab9534c5644496cf18c38907521fc49
child 264140 4f0530d695b6898a865e61b0bfaa39761a815f6e
push id65534
push usercbook@mozilla.com
push dateThu, 24 Sep 2015 04:09:22 +0000
treeherdermozilla-inbound@4f0530d695b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs1181489
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1181489 - Adding sanity checks into the alarm service for preventing from the alarm works erroneously. r=fabrice
dom/alarm/AlarmService.jsm
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -247,16 +247,28 @@ this.AlarmService = {
       aAlarm.alarmFiredCb(this._publicAlarm(aAlarm));
     }
   },
 
   _onAlarmFired: function _onAlarmFired() {
     debug("_onAlarmFired()");
 
     if (this._currentAlarm) {
+      let currentAlarmTime = this._getAlarmTime(this._currentAlarm);
+
+      // If a alarm fired before the actual time that the current
+      // alarm should occur, we reset this current alarm.
+      if (currentAlarmTime > Date.now()) {
+        let currentAlarm = this._currentAlarm;
+        this._currentAlarm = currentAlarm;
+
+        this._debugCurrentAlarm();
+        return;
+      }
+
       this._removeAlarmFromDb(this._currentAlarm.id, null);
       this._notifyAlarmObserver(this._currentAlarm);
       this._currentAlarm = null;
     }
 
     // Reset the next alarm from the queue.
     let alarmQueue = this._alarmQueue;
     while (alarmQueue.length > 0) {
@@ -409,28 +421,37 @@ this.AlarmService = {
         debug("Callback after adding alarm in database.");
 
         aNewAlarm['id'] = aNewId;
 
         // Now that the alarm has been added to the database, we can tack on
         // the non-serializable callback to the in-memory object.
         aNewAlarm['alarmFiredCb'] = aAlarmFiredCb;
 
+        // If the new alarm already expired at this moment, we directly
+        // notify this alarm
+        let aNewAlarmTime = this._getAlarmTime(aNewAlarm);
+        if (aNewAlarmTime < Date.now()) {
+          aSuccessCb(aNewId);
+          this._removeAlarmFromDb(aNewAlarm.id, null);
+          this._notifyAlarmObserver(aNewAlarm);
+          return;
+        }
+
         // If there is no alarm being set in system, set the new alarm.
         if (this._currentAlarm == null) {
           this._currentAlarm = aNewAlarm;
           this._debugCurrentAlarm();
           aSuccessCb(aNewId);
           return;
         }
 
         // If the new alarm is earlier than the current alarm, swap them and
         // push the previous alarm back to the queue.
         let alarmQueue = this._alarmQueue;
-        let aNewAlarmTime = this._getAlarmTime(aNewAlarm);
         let currentAlarmTime = this._getAlarmTime(this._currentAlarm);
         if (aNewAlarmTime < currentAlarmTime) {
           alarmQueue.unshift(this._currentAlarm);
           this._currentAlarm = aNewAlarm;
           this._debugCurrentAlarm();
           aSuccessCb(aNewId);
           return;
         }