Bug 909270 - Queue PushService alarms. r=jlebar

This commit is contained in:
Nikhil Marathe 2013-08-29 09:59:05 -07:00
parent 8072b982b6
commit 7c8b6a0105

View File

@ -625,9 +625,20 @@ this.PushService = {
/** |delay| should be in milliseconds. */
_setAlarm: function(delay) {
// Bug 909270: Since calls to AlarmService.add() are async, calls must be
// 'queued' to ensure only one alarm is ever active.
if (this._settingAlarm) {
// onSuccess will handle the set. Overwriting the variable enforces the
// last-writer-wins semantics.
this._queuedAlarmDelay = delay;
this._waitingForAlarmSet = true;
return;
}
// Stop any existing alarm.
this._stopAlarm();
this._settingAlarm = true;
AlarmService.add(
{
date: new Date(Date.now() + delay),
@ -637,6 +648,12 @@ this.PushService = {
function onSuccess(alarmID) {
this._alarmID = alarmID;
debug("Set alarm " + delay + " in the future " + this._alarmID);
this._settingAlarm = false;
if (this._waitingForAlarmSet) {
this._waitingForAlarmSet = false;
this._setAlarm(this._queuedAlarmDelay);
}
}.bind(this)
)
},