Bug 836654 - Part 10: Don't acquire the CPU wake lock in the alarm service any longer. r=cjones
authorJustin Lebar <justin.lebar@gmail.com>
Thu, 14 Feb 2013 15:41:30 -0500
changeset 131846 832ac179e3d0ce85b476c1a7daf9fe231b77de0b
parent 131845 5e64eb3c6c96abb94707cde25115066c9d2bed2a
child 131847 4497d85b07f4a8dbbb54a07cbca055812cf161e8
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs836654
milestone21.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 836654 - Part 10: Don't acquire the CPU wake lock in the alarm service any longer. r=cjones We've removed the event that the AlarmService was listening to in order to find out when we could drop the lock!
dom/alarm/AlarmService.jsm
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -42,34 +42,31 @@ this.AlarmService = {
 
     let alarmHalService = this._alarmHalService = Cc["@mozilla.org/alarmHalService;1"].getService(Ci.nsIAlarmHalService);
     alarmHalService.setAlarmFiredCb(this._onAlarmFired.bind(this));
     alarmHalService.setTimezoneChangedCb(this._onTimezoneChanged.bind(this));
 
     // add the messages to be listened
     const messages = ["AlarmsManager:GetAll",
                       "AlarmsManager:Add",
-                      "AlarmsManager:Remove",
-                      "SystemMessageManager:HandleMessageDone"];
+                      "AlarmsManager:Remove"];
     messages.forEach(function addMessage(msgName) {
         ppmm.addMessageListener(msgName, this);
     }.bind(this));
 
     // set the indexeddb database
     let idbManager = Cc["@mozilla.org/dom/indexeddb/manager;1"].getService(Ci.nsIIndexedDatabaseManager);
     idbManager.initWindowless(myGlobal);
     this._db = new AlarmDB(myGlobal);
     this._db.init(myGlobal);
 
     // variable to save alarms waiting to be set
     this._alarmQueue = [];
 
     this._restoreAlarmsFromDb();
-
-    this._cpuWakeLocks = {};
   },
 
   // getter/setter to access the current alarm set in system
   _alarm: null,
   get _currentAlarm() {
     return this._alarm;
   },
   set _currentAlarm(aAlarm) {
@@ -211,24 +208,16 @@ this.AlarmService = {
 
             // no alarm waiting to be set in the queue
             this._currentAlarm = null;
             this._debugCurrentAlarm();
           }.bind(this)
         );
         break;
 
-      case "SystemMessageManager:HandleMessageDone":
-        if (json.type != "alarm") {
-          return;
-        }
-        debug("Unlock the CPU wake lock after the alarm is handled for sure.");
-        this._unlockCpuWakeLock(json.message.id);
-        break;
-
       default:
         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
         break;
     }
   },
 
   _sendAsyncMessage: function _sendAsyncMessage(aMessageManager, aMessageName, aSuccess, aRequestId, aData) {
     debug("_sendAsyncMessage()");
@@ -280,54 +269,29 @@ this.AlarmService = {
         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
       }
     );
   },
 
   _fireSystemMessage: function _fireSystemMessage(aAlarm) {
     debug("Fire system message: " + JSON.stringify(aAlarm));
 
-    // We have to ensure the CPU doesn't sleep during the process of
-    // handling alarm message, so that it can be handled on time.
-    this._cpuWakeLocks[aAlarm.id] = {
-      wakeLock: powerManagerService.newWakeLock("cpu"),
-      timer: Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer)
-    };
-
-    // Set a watchdog to avoid locking the CPU wake lock too long,
-    // because it'd exhaust the battery quickly which is very bad.
-    // This could probably happen if the app failed to launch or
-    // handle the alarm message due to any unexpected reasons.
-    this._cpuWakeLocks[aAlarm.id].timer.initWithCallback(function timerCb() {
-      debug("Unlock the CPU wake lock if the alarm isn't properly handled.");
-      this._unlockCpuWakeLock(aAlarm.id);
-    }.bind(this), 30000, Ci.nsITimer.TYPE_ONE_SHOT);
-
     let manifestURI = Services.io.newURI(aAlarm.manifestURL, null, null);
     let pageURI = Services.io.newURI(aAlarm.pageURL, null, null);
 
     // We don't need to expose everything to the web content.
     let alarm = { "id":              aAlarm.id,
                   "date":            aAlarm.date,
                   "respectTimezone": aAlarm.ignoreTimezone ?
                                        "ignoreTimezone" : "honorTimezone", 
                   "data":            aAlarm.data };
 
     messenger.sendMessage("alarm", alarm, pageURI, manifestURI);
   },
 
-  _unlockCpuWakeLock: function _unlockCpuWakeLock(aAlarmId) {
-    let cpuWakeLock = this._cpuWakeLocks[aAlarmId];
-    if (cpuWakeLock) {
-      cpuWakeLock.wakeLock.unlock();
-      cpuWakeLock.timer.cancel();
-      delete this._cpuWakeLocks[aAlarmId];
-    }
-  },
-
   _onAlarmFired: function _onAlarmFired() {
     debug("_onAlarmFired()");
 
     if (this._currentAlarm) {
       this._fireSystemMessage(this._currentAlarm);
       this._removeAlarmFromDb(this._currentAlarm.id, null);
       this._currentAlarm = null;
     }