Bug 777207 - Alarm API - AlarmService should use "activities" or "system messages", or not broadcast information to all content processes. r=cjones
authorGene Lian <clian@mozilla.com>
Thu, 26 Jul 2012 09:59:20 +0800
changeset 106146 bfed91df39402daee0bc7c10926d6e6854a10085
parent 106145 ebed37a1e2f7c8ec4e63ee7005937f9b30916eae
child 106147 a7e20d9dc2f7e038cc0a658d8c7067cfeab713f2
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)
reviewerscjones
bugs777207
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 777207 - Alarm API - AlarmService should use "activities" or "system messages", or not broadcast information to all content processes. r=cjones
dom/alarm/AlarmService.jsm
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -70,26 +70,27 @@ let AlarmService = {
 
     if (!this._alarmHalService.setAlarm(this._getAlarmTime(aAlarm) / 1000, 0))
       throw Components.results.NS_ERROR_FAILURE;
   },
 
   receiveMessage: function receiveMessage(aMessage) {
     debug("receiveMessage(): " + aMessage.name);
 
+    let mm = aMessage.target.QueryInterface(Ci.nsIFrameMessageManager);
     let json = aMessage.json;
     switch (aMessage.name) {
       case "AlarmsManager:GetAll":
         this._db.getAll(
           function getAllSuccessCb(aAlarms) {
             debug("Callback after getting alarms from database: " + JSON.stringify(aAlarms));
-            this._sendAsyncMessage("GetAll:Return:OK", json.requestId, aAlarms);
+            this._sendAsyncMessage(mm, "GetAll", true, json.requestId, aAlarms);
           }.bind(this),
           function getAllErrorCb(aErrorMsg) {
-            this._sendAsyncMessage("GetAll:Return:KO", json.requestId, aErrorMsg);
+            this._sendAsyncMessage(mm, "GetAll", false, json.requestId, aErrorMsg);
           }.bind(this)
         );
         break;
 
       case "AlarmsManager:Add":
         // prepare a record for the new alarm to be added
         let newAlarm = {
           date: json.date, 
@@ -105,48 +106,48 @@ let AlarmService = {
             debug("Callback after adding alarm in database.");
 
             newAlarm['id'] = aNewId;
             let newAlarmTime = this._getAlarmTime(newAlarm);
 
             if (newAlarmTime <= Date.now()) {
               debug("Adding a alarm that has past time. Don't set it in system.");
               this._debugCurrentAlarm();
-              this._sendAsyncMessage("Add:Return:OK", json.requestId, aNewId);
+              this._sendAsyncMessage(mm, "Add", true, json.requestId, aNewId);
               return;
             }
 
             // if there is no alarm being set in system, set the new alarm
             if (this._currentAlarm == null) {
               this._currentAlarm = newAlarm;
               this._debugCurrentAlarm();
-              this._sendAsyncMessage("Add:Return:OK", json.requestId, aNewId);
+              this._sendAsyncMessage(mm, "Add", true, json.requestId, aNewId);
               return;
             }
 
             // if the new alarm is earlier than the current alarm
             // swap them and push the previous alarm back to queue
             let alarmQueue = this._alarmQueue;
             let currentAlarmTime = this._getAlarmTime(this._currentAlarm);
             if (newAlarmTime < currentAlarmTime) {
               alarmQueue.unshift(this._currentAlarm);
               this._currentAlarm = newAlarm;
               this._debugCurrentAlarm();
-              this._sendAsyncMessage("Add:Return:OK", json.requestId, aNewId);
+              this._sendAsyncMessage(mm, "Add", true, json.requestId, aNewId);
               return;
             }
 
             //push the new alarm in the queue
             alarmQueue.push(newAlarm);
             alarmQueue.sort(this._sortAlarmByTimeStamps.bind(this));
             this._debugCurrentAlarm();
-            this._sendAsyncMessage("Add:Return:OK", json.requestId, aNewId);
+            this._sendAsyncMessage(mm, "Add", true, json.requestId, aNewId);
           }.bind(this),
           function addErrorCb(aErrorMsg) {
-            this._sendAsyncMessage("Add:Return:KO", json.requestId, aErrorMsg);
+            this._sendAsyncMessage(mm, "Add", false, json.requestId, aErrorMsg);
           }.bind(this)
         );
         break;
 
       case "AlarmsManager:Remove":
         this._db.remove(
           json.id,
           function removeSuccessCb() {
@@ -190,42 +191,45 @@ let AlarmService = {
         break;
 
       default:
         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
         break;
     }
   },
 
-  _sendAsyncMessage: function _sendAsyncMessage(aMessageName, aRequestId, aData) {
+  _sendAsyncMessage: function _sendAsyncMessage(aMessageManager, aMessageName, aSuccess, aRequestId, aData) {
     debug("_sendAsyncMessage()");
 
+    if (!aMessageManager) {
+      debug("Invalid message manager: null");
+      throw Components.results.NS_ERROR_FAILURE;
+    }
+
     let json = null;
     switch (aMessageName)
     {
-      case "Add:Return:OK":
-        json = { requestId: aRequestId, id: aData };
+      case "Add":
+          json = aSuccess ? 
+            { requestId: aRequestId, id: aData } : 
+            { requestId: aRequestId, errorMsg: aData };
         break;
 
-      case "GetAll:Return:OK":
-        json = { requestId: aRequestId, alarms: aData };
-        break;
-
-      case "Add:Return:KO":
-      case "GetAll:Return:KO":
-        json = { requestId: aRequestId, errorMsg: aData };
+      case "GetAll":
+          json = aSuccess ? 
+            { requestId: aRequestId, alarms: aData } : 
+            { requestId: aRequestId, errorMsg: aData };
         break;
 
       default:
         throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
         break;
     }
 
-    if (aMessageName && json)
-      ppmm.sendAsyncMessage("AlarmsManager:" + aMessageName, json);
+    aMessageManager.sendAsyncMessage("AlarmsManager:" + aMessageName + ":Return:" + (aSuccess ? "OK" : "KO"), json);
   },
 
   _onAlarmFired: function _onAlarmFired() {
     debug("_onAlarmFired()");
 
     if (this._currentAlarm) {
       debug("Fire system intent: " + JSON.stringify(this._currentAlarm));
       let manifestURI = Services.io.newURI(this._currentAlarm.manifestURL, null, null);