Bug 1416320 - Do a quick sync before going to sleep. r=markh

MozReview-Commit-ID: I36uvEFlEz5

--HG--
extra : rebase_source : 1910ac25084f6a8c37a6d21accf17da974d56493
This commit is contained in:
Edouard Oger 2017-11-10 14:09:44 -05:00
Родитель 676e0a6e5c
Коммит ab35b46c98
3 изменённых файлов: 32 добавлений и 19 удалений

Просмотреть файл

@ -177,6 +177,7 @@ SyncScheduler.prototype = {
if (Status.checkSetup() == STATUS_OK) { if (Status.checkSetup() == STATUS_OK) {
Svc.Obs.add("wake_notification", this); Svc.Obs.add("wake_notification", this);
Svc.Obs.add("captive-portal-login-success", this); Svc.Obs.add("captive-portal-login-success", this);
Svc.Obs.add("sleep_notification", this);
IdleService.addIdleObserver(this, Svc.Prefs.get("scheduler.idleTime")); IdleService.addIdleObserver(this, Svc.Prefs.get("scheduler.idleTime"));
} }
}, },
@ -328,6 +329,7 @@ SyncScheduler.prototype = {
IdleService.addIdleObserver(this, Svc.Prefs.get("scheduler.idleTime")); IdleService.addIdleObserver(this, Svc.Prefs.get("scheduler.idleTime"));
Svc.Obs.add("wake_notification", this); Svc.Obs.add("wake_notification", this);
Svc.Obs.add("captive-portal-login-success", this); Svc.Obs.add("captive-portal-login-success", this);
Svc.Obs.add("sleep_notification", this);
break; break;
case "weave:service:start-over": case "weave:service:start-over":
this.setDefaults(); this.setDefaults();
@ -389,6 +391,9 @@ SyncScheduler.prototype = {
CommonUtils.nextTick(() => { CommonUtils.nextTick(() => {
this.scheduleNextSync(3000); this.scheduleNextSync(3000);
}); });
case "sleep_notification":
this._log.debug("Going to sleep, doing a quick sync.");
this.scheduleNextSync(0, ["tabs"], "sleep");
break; break;
} }
}, },
@ -490,7 +495,7 @@ SyncScheduler.prototype = {
* *
* Otherwise, reschedule a sync for later. * Otherwise, reschedule a sync for later.
*/ */
syncIfMPUnlocked: function syncIfMPUnlocked() { syncIfMPUnlocked(engines, why) {
// No point if we got kicked out by the master password dialog. // No point if we got kicked out by the master password dialog.
if (Status.login == MASTER_PASSWORD_LOCKED && if (Status.login == MASTER_PASSWORD_LOCKED &&
Utils.mpLocked()) { Utils.mpLocked()) {
@ -506,13 +511,15 @@ SyncScheduler.prototype = {
this._log.debug("Not initiating sync: app is shutting down"); this._log.debug("Not initiating sync: app is shutting down");
return; return;
} }
CommonUtils.nextTick(this.service.sync, this.service); Services.tm.dispatchToMainThread(() => {
this.service.sync({engines, why});
});
}, },
/** /**
* Set a timer for the next sync * Set a timer for the next sync
*/ */
scheduleNextSync: function scheduleNextSync(interval) { scheduleNextSync(interval, engines = null, why = null) {
// If no interval was specified, use the current sync interval. // If no interval was specified, use the current sync interval.
if (interval == null) { if (interval == null) {
interval = this.syncInterval; interval = this.syncInterval;
@ -543,12 +550,13 @@ SyncScheduler.prototype = {
// Start the sync right away if we're already late. // Start the sync right away if we're already late.
if (interval <= 0) { if (interval <= 0) {
this._log.trace("Requested sync should happen right away."); this._log.trace("Requested sync should happen right away.");
this.syncIfMPUnlocked(); this.syncIfMPUnlocked(engines, why);
return; return;
} }
this._log.debug("Next sync in " + interval + " ms."); this._log.debug("Next sync in " + interval + " ms.");
CommonUtils.namedTimer(this.syncIfMPUnlocked, interval, this, "syncTimer"); CommonUtils.namedTimer(() => { this.syncIfMPUnlocked(engines, why) },
interval, this, "syncTimer");
// Save the next sync time in-case sync is disabled (logout/offline/etc.) // Save the next sync time in-case sync is disabled (logout/offline/etc.)
this.nextSync = Date.now() + interval; this.nextSync = Date.now() + interval;

Просмотреть файл

@ -908,8 +908,8 @@ Sync11Service.prototype = {
// Stuff we need to do after login, before we can really do // Stuff we need to do after login, before we can really do
// anything (e.g. key setup). // anything (e.g. key setup).
async _remoteSetup(infoResponse) { async _remoteSetup(infoResponse, fetchConfig = true) {
if (!(await this._fetchServerConfiguration())) { if (fetchConfig && !(await this._fetchServerConfiguration())) {
return false; return false;
} }
@ -1112,7 +1112,7 @@ Sync11Service.prototype = {
histogram.add(1); histogram.add(1);
let synchronizer = new EngineSynchronizer(this); let synchronizer = new EngineSynchronizer(this);
await synchronizer.sync(engineNamesToSync); // Might throw! await synchronizer.sync(engineNamesToSync, why); // Might throw!
histogram = Services.telemetry.getHistogramById("WEAVE_COMPLETE_SUCCESS_COUNT"); histogram = Services.telemetry.getHistogramById("WEAVE_COMPLETE_SUCCESS_COUNT");
histogram.add(1); histogram.add(1);

Просмотреть файл

@ -31,7 +31,8 @@ this.EngineSynchronizer = function EngineSynchronizer(service) {
}; };
EngineSynchronizer.prototype = { EngineSynchronizer.prototype = {
async sync(engineNamesToSync) { async sync(engineNamesToSync, why) {
let fastSync = why && why == "sleep";
let startTime = Date.now(); let startTime = Date.now();
this.service.status.resetSync(); this.service.status.resetSync();
@ -75,17 +76,19 @@ EngineSynchronizer.prototype = {
engine.lastModified = info.obj[engine.name] || 0; engine.lastModified = info.obj[engine.name] || 0;
} }
if (!(await this.service._remoteSetup(info))) { if (!(await this.service._remoteSetup(info, !fastSync))) {
throw new Error("Aborting sync, remote setup failed"); throw new Error("Aborting sync, remote setup failed");
} }
// Make sure we have an up-to-date list of clients before sending commands if (!fastSync) {
this._log.debug("Refreshing client list."); // Make sure we have an up-to-date list of clients before sending commands
if (!(await this._syncEngine(this.service.clientsEngine))) { this._log.debug("Refreshing client list.");
// Clients is an engine like any other; it can fail with a 401, if (!(await this._syncEngine(this.service.clientsEngine))) {
// and we can elect to abort the sync. // Clients is an engine like any other; it can fail with a 401,
this._log.warn("Client engine sync failed. Aborting."); // and we can elect to abort the sync.
return; this._log.warn("Client engine sync failed. Aborting.");
return;
}
} }
// We only honor the "hint" of what engines to Sync if this isn't // We only honor the "hint" of what engines to Sync if this isn't
@ -107,7 +110,7 @@ EngineSynchronizer.prototype = {
break; break;
} }
if (this.service.clientsEngine.localCommands) { if (!fastSync && this.service.clientsEngine.localCommands) {
try { try {
if (!(await this.service.clientsEngine.processIncomingCommands())) { if (!(await this.service.clientsEngine.processIncomingCommands())) {
this.service.status.sync = ABORT_SYNC_COMMAND; this.service.status.sync = ABORT_SYNC_COMMAND;
@ -179,7 +182,9 @@ EngineSynchronizer.prototype = {
} }
} }
await Doctor.consult(enginesToValidate); if (!fastSync) {
await Doctor.consult(enginesToValidate);
}
// If there were no sync engine failures // If there were no sync engine failures
if (this.service.status.service != SYNC_FAILED_PARTIAL) { if (this.service.status.service != SYNC_FAILED_PARTIAL) {