Bug 1416322 - Wait until the network is back up to sync after waking-up from sleep. r?markh
MozReview-Commit-ID: 2vzmj3UkvtD
--- a/services/sync/modules/policies.js
+++ b/services/sync/modules/policies.js
@@ -62,16 +62,20 @@ SyncScheduler.prototype = {
this.idleInterval = getThrottledIntervalPreference("scheduler.idleInterval");
this.activeInterval = getThrottledIntervalPreference("scheduler.activeInterval");
this.immediateInterval = getThrottledIntervalPreference("scheduler.immediateInterval");
this.eolInterval = getThrottledIntervalPreference("scheduler.eolInterval");
// A user is non-idle on startup by default.
this.idle = false;
+ // That flag will be flipped if we resume from sleep and the network link
+ // is down.
+ this.shouldSyncWhenLinkComesUp = false;
+
this.hasIncomingItems = false;
// This is the last number of clients we saw when previously updating the
// client mode. If this != currentNumClients (obtained from prefs written
// by the clients engine) then we need to transition to and from
// single and multi-device mode.
this.numClientsLastSync = 0;
this._resyncs = 0;
@@ -182,18 +186,25 @@ SyncScheduler.prototype = {
this._log.trace("Handling " + topic);
switch (topic) {
case "weave:engine:score:updated":
if (Status.login == LOGIN_SUCCEEDED) {
CommonUtils.namedTimer(this.calculateScore, SCORE_UPDATE_DELAY, this,
"_scoreTimer");
}
break;
+ case "network:link-status-changed":
+ if (this.shouldSyncWhenLinkComesUp && !this.offline) {
+ this._log.debug("Network link is up for the first time since we woke-up. Syncing.");
+ this.shouldSyncWhenLinkComesUp = false;
+ this.scheduleNextSync(0);
+ break;
+ }
+ // Intended fallthrough
case "network:offline-status-changed":
- case "network:link-status-changed":
case "captive-portal-detected":
// Whether online or offline, we'll reschedule syncs
this._log.trace("Network offline status change: " + data);
this.checkSyncStatus();
break;
case "weave:service:sync:start":
// Clear out any potentially pending syncs now that we're syncing
this.clearSyncTriggers();
@@ -353,25 +364,32 @@ SyncScheduler.prototype = {
if (this.numClients > 1) {
this.scheduleNextSync(0);
}
}, IDLE_OBSERVER_BACK_DELAY, this, "idleDebouncerTimer");
break;
case "wake_notification":
this._log.debug("Woke from sleep.");
CommonUtils.nextTick(() => {
- // Trigger a sync if we have multiple clients. We give it 5 seconds
- // incase the network is still in the process of coming back up.
+ // Trigger a sync if we have multiple clients. We give it 2 seconds
+ // so the browser can recover from the wake and do more important
+ // operations first (timers etc).
if (this.numClients > 1) {
- this._log.debug("More than 1 client. Will sync in 5s.");
- this.scheduleNextSync(5000);
+ if (!this.offline) {
+ this._log.debug("Online, will sync in 2s.");
+ this.scheduleNextSync(2000);
+ } else {
+ this._log.debug("Offline, will sync when link comes up.");
+ this.shouldSyncWhenLinkComesUp = true;
+ }
}
});
break;
case "captive-portal-login-success":
+ this.shouldSyncWhenLinkComesUp = false;
this._log.debug("Captive portal login success. Scheduling a sync.");
CommonUtils.nextTick(() => {
this.scheduleNextSync(3000);
});
break;
}
},