Bug 777226 - Alarm API - If an alarm cannot be fired when the device shuts down, it should be fired when powering up. r=vivien
authorGene Lian <clian@mozilla.com>
Thu, 16 Aug 2012 10:46:40 +0800
changeset 108487 d51a3bf72b9c549903868a998783bf3ba3f69130
parent 108486 3e2cbfcaccd444308bf24a7f28e6f4f6284f4013
child 108488 eb0deea718b3184c1056587a77612baa70721a4a
push id1490
push userakeybl@mozilla.com
push dateMon, 08 Oct 2012 18:29:50 +0000
treeherdermozilla-beta@f335e7dacdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvivien
bugs777226
milestone17.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 777226 - Alarm API - If an alarm cannot be fired when the device shuts down, it should be fired when powering up. r=vivien
dom/alarm/AlarmService.jsm
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -300,22 +300,26 @@ let AlarmService = {
       null,
       function getAllSuccessCb(aAlarms) {
         debug("Callback after getting alarms from database: " + JSON.stringify(aAlarms));
 
         // clear any alarms set or queued in the cache
         let alarmQueue = this._alarmQueue;
         alarmQueue.length = 0;
         this._currentAlarm = null;
-        
-        // only add the alarm that is valid
-        let nowTime = Date.now();
+
+        // Only restore the alarm that's not yet expired; otherwise,
+        // fire a system message for it and remove it from database.
         aAlarms.forEach(function addAlarm(aAlarm) {
-          if (this._getAlarmTime(aAlarm) > nowTime)
+          if (this._getAlarmTime(aAlarm) > Date.now()) {
             alarmQueue.push(aAlarm);
+          } else {
+            this._fireSystemMessage(aAlarm);
+            this._removeAlarmFromDb(aAlarm.id, null);
+          }
         }.bind(this));
 
         // set the next alarm from queue
         if (alarmQueue.length) {
           alarmQueue.sort(this._sortAlarmByTimeStamps.bind(this));
           this._currentAlarm = alarmQueue.shift();
         }
 
@@ -324,17 +328,17 @@ let AlarmService = {
       function getAllErrorCb(aErrorMsg) {
         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
       }
     );
   },
 
   _getAlarmTime: function _getAlarmTime(aAlarm) {
     let alarmTime = (new Date(aAlarm.date)).getTime();
-    
+
     // For an alarm specified with "ignoreTimezone",
     // it must be fired respect to the user's timezone.
     // Supposing an alarm was set at 7:00pm at Tokyo,
     // it must be gone off at 7:00pm respect to Paris' 
     // local time when the user is located at Paris.
     // We can adjust the alarm UTC time by calculating
     // the difference of the orginal timezone and the 
     // current timezone.