Bug 757762 - Lightning's alarms too late / internal time is wrong. r=philipp
This commit is contained in:
Родитель
087ba3e529
Коммит
ba7e09e778
|
@ -8,6 +8,8 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
|||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const kHoursBetweenUpdates = 6;
|
||||
const kSleepMonitorInterval = 60000;
|
||||
const kSleepMonitorTolerance = 1000;
|
||||
|
||||
function nowUTC() {
|
||||
return cal.jsDateToDateTime(new Date()).getInTimezone(cal.UTC());
|
||||
|
@ -30,6 +32,38 @@ function calAlarmService() {
|
|||
this.mTimerMap = {};
|
||||
this.mObservers = new calListenerBag(Components.interfaces.calIAlarmServiceObserver);
|
||||
|
||||
this.mSleepMonitor = {
|
||||
service: this,
|
||||
interval: kSleepMonitorInterval,
|
||||
timer: null,
|
||||
expected: null,
|
||||
|
||||
checkExpected: function sm_checkExpected() {
|
||||
let now = Date.now();
|
||||
if (now - this.expected > kSleepMonitorTolerance) {
|
||||
cal.LOG("[calAlarmService] Sleep cycle detected, reloading alarms");
|
||||
this.service.shutdown();
|
||||
this.service.startup();
|
||||
} else {
|
||||
this.expected = now + this.interval;
|
||||
}
|
||||
},
|
||||
|
||||
start: function sm_start() {
|
||||
this.stop();
|
||||
this.expected = Date.now() + this.interval;
|
||||
this.timer = newTimerWithCallback(this.checkExpected.bind(this),
|
||||
this.interval, true);
|
||||
},
|
||||
|
||||
stop: function sm_stop() {
|
||||
if (this.timer) {
|
||||
this.timer.cancel();
|
||||
this.timer = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.calendarObserver = {
|
||||
alarmService: this,
|
||||
|
||||
|
@ -271,6 +305,12 @@ calAlarmService.prototype = {
|
|||
|
||||
this.mUpdateTimer = newTimerWithCallback(timerCallback, kHoursBetweenUpdates * 3600000, true);
|
||||
|
||||
// The sleep monitor needs to be started on platforms that don't support wake_notification
|
||||
if (Services.appinfo.OS != "WINNT" && Services.appinfo.OS != "Darwin") {
|
||||
cal.LOG("[calAlarmService] Starting sleep monitor.");
|
||||
this.mSleepMonitor.start();
|
||||
}
|
||||
|
||||
this.mStarted = true;
|
||||
},
|
||||
|
||||
|
@ -303,6 +343,8 @@ calAlarmService.prototype = {
|
|||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
Services.obs.removeObserver(this, "wake_notification");
|
||||
|
||||
this.mSleepMonitor.stop();
|
||||
|
||||
this.mStarted = false;
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче