author | Gene Lian <clian@mozilla.com> |
Fri, 13 Jul 2012 20:01:43 +0800 | |
changeset 104073 | ad04b9931208493ce06f081513db78d0d336a983 |
parent 104072 | 7db81ae082e7f0d7bd2cdec9465fe492814a97eb |
child 104074 | bc145c1e0647db339c9511aa893fc304fcd1f64d |
push id | 1316 |
push user | akeybl@mozilla.com |
push date | Mon, 27 Aug 2012 22:37:00 +0000 |
treeherder | mozilla-beta@db4b09302ee2 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | vivien |
bugs | 773596 |
milestone | 16.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
|
dom/alarm/AlarmService.jsm | file | annotate | diff | comparison | revisions | |
dom/alarm/AlarmsManager.js | file | annotate | diff | comparison | revisions |
--- a/dom/alarm/AlarmService.jsm +++ b/dom/alarm/AlarmService.jsm @@ -76,26 +76,20 @@ let AlarmService = { debug("receiveMessage(): " + aMessage.name); 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)); - ppmm.sendAsyncMessage( - "AlarmsManager:GetAll:Return:OK", - { requestID: json.requestID, alarms: aAlarms } - ); + this._sendAsyncMessage("GetAll:Return:OK", json.requestId, aAlarms); }.bind(this), function getAllErrorCb(aErrorMsg) { - ppmm.sendAsyncMessage( - "AlarmsManager:GetAll:Return:KO", - { requestID: json.requestID, errorMsg: aErrorMsg } - ); + this._sendAsyncMessage("GetAll:Return:KO", json.requestId, aErrorMsg); }.bind(this) ); break; case "AlarmsManager:Add": // prepare a record for the new alarm to be added let newAlarm = { date: json.date, @@ -111,52 +105,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); 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); 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); return; } //push the new alarm in the queue alarmQueue.push(newAlarm); alarmQueue.sort(this._sortAlarmByTimeStamps.bind(this)); this._debugCurrentAlarm(); - - ppmm.sendAsyncMessage( - "AlarmsManager:Add:Return:OK", - { requestID: json.requestID, id: aNewId } - ); + this._sendAsyncMessage("Add:Return:OK", json.requestId, aNewId); }.bind(this), function addErrorCb(aErrorMsg) { - ppmm.sendAsyncMessage( - "AlarmsManager:Add:Return:KO", - { requestID: json.requestID, errorMsg: aErrorMsg } - ); + this._sendAsyncMessage("Add:Return:KO", json.requestId, aErrorMsg); }.bind(this) ); break; case "AlarmsManager:Remove": this._db.remove( json.id, function removeSuccessCb() { @@ -200,16 +190,44 @@ let AlarmService = { break; default: throw Components.results.NS_ERROR_NOT_IMPLEMENTED; break; } }, + _sendAsyncMessage: function _sendAsyncMessage(aMessageName, aRequestId, aData) { + debug("_sendAsyncMessage()"); + + let json = null; + switch (aMessageName) + { + case "Add:Return:OK": + json = { requestId: aRequestId, id: 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 }; + break; + + default: + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; + break; + } + + if (aMessageName && json) + ppmm.sendAsyncMessage("AlarmsManager:" + aMessageName, json); + }, + _onAlarmFired: function _onAlarmFired() { debug("_onAlarmFired()"); if (this._currentAlarm) { debug("Fire system intent: " + JSON.stringify(this._currentAlarm)); if (this._currentAlarm.manifestURL) messenger.sendMessage("alarm", this._currentAlarm, this._currentAlarm.manifestURL); this._currentAlarm = null;
--- a/dom/alarm/AlarmsManager.js +++ b/dom/alarm/AlarmsManager.js @@ -58,17 +58,17 @@ AlarmsManager.prototype = { default: throw Components.results.NS_ERROR_NOT_IMPLEMENTED; break; } let request = this.createRequest(); this._cpmm.sendAsyncMessage( "AlarmsManager:Add", - { requestID: this.getRequestId(request), date: aDate, ignoreTimezone: isIgnoreTimezone, data: aData, manifestURL: this._manifestURL } + { requestId: this.getRequestId(request), date: aDate, ignoreTimezone: isIgnoreTimezone, data: aData, manifestURL: this._manifestURL } ); return request; }, remove: function remove(aId) { debug("remove()"); return this._cpmm.sendSyncMessage( @@ -78,29 +78,29 @@ AlarmsManager.prototype = { }, getAll: function getAll() { debug("getAll()"); let request = this.createRequest(); this._cpmm.sendAsyncMessage( "AlarmsManager:GetAll", - { requestID: this.getRequestId(request) } + { requestId: this.getRequestId(request) } ); return request; }, receiveMessage: function receiveMessage(aMessage) { debug("receiveMessage(): " + aMessage.name); let json = aMessage.json; - let request = this.getRequest(json.requestID); + let request = this.getRequest(json.requestId); if (!request) { - debug("No request stored! " + json.requestID); + debug("No request stored! " + json.requestId); return; } switch (aMessage.name) { case "AlarmsManager:Add:Return:OK": Services.DOMRequest.fireSuccess(request, json.id); break; @@ -115,17 +115,17 @@ AlarmsManager.prototype = { case "AlarmsManager:GetAll:Return:KO": Services.DOMRequest.fireError(request, json.errorMsg); break; default: debug("Wrong message: " + aMessage.name); break; } - this.removeRequest(json.requestID); + this.removeRequest(json.requestId); }, // nsIDOMGlobalPropertyInitializer implementation init: function init(aWindow) { debug("init()"); // Set navigator.mozAlarms to null. if (!Services.prefs.getBoolPref("dom.mozAlarms.enabled"))