Bug 1383773 - Fix race between browser and TPS initialization. r?markh
MozReview-Commit-ID: 7Ie1IzRzEbI
--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -16,16 +16,17 @@ var module = this;
// Global modules
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
+Cu.import("resource://gre/modules/PromiseUtils.jsm");
Cu.import("resource://services-common/async.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/main.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/telemetry.js");
Cu.import("resource://services-sync/bookmark_validator.js");
Cu.import("resource://services-sync/engines/passwords.js");
Cu.import("resource://services-sync/engines/forms.js");
@@ -124,16 +125,17 @@ var TPS = {
_test: null,
_triggeredSync: false,
_usSinceEpoch: 0,
_requestedQuit: false,
shouldValidateAddons: false,
shouldValidateBookmarks: false,
shouldValidatePasswords: false,
shouldValidateForms: false,
+ _windowsUpDeferred: PromiseUtils.defer(),
_init: function TPS__init() {
this.delayAutoSync();
OBSERVER_TOPICS.forEach(function(aTopic) {
Services.obs.addObserver(this, aTopic, true);
}, this);
@@ -171,24 +173,17 @@ var TPS = {
Services.obs.removeObserver(this, topic);
}, this);
Logger.close();
break;
case "sessionstore-windows-restored":
- // This is a terrible hack, but fixes cases where tps (usually cleanup)
- // fails because of sessionstore restoring windows before tps is able
- // to initialize. This used to take only 1 tick, but at some point
- // session store started restoring windows sooner, or tps started
- // initializing later.
- setTimeout(() => {
- this.RunNextTestAction();
- }, 1000);
+ this._windowsUpDeferred.resolve();
break;
case "weave:service:setup-complete":
this._setupComplete = true;
if (this._syncWipeAction) {
Weave.Svc.Prefs.set("firstSync", this._syncWipeAction);
this._syncWipeAction = null;
@@ -942,16 +937,19 @@ var TPS = {
Logger.logInfo("setting client.name to " + this.phases[this._currentPhase]);
Weave.Svc.Prefs.set("client.name", this.phases[this._currentPhase]);
this._interceptSyncTelemetry();
// start processing the test actions
this._currentAction = 0;
+ this._windowsUpDeferred.promise.then(() => {
+ this.RunNextTestAction();
+ });
} catch (e) {
this.DumpError("_executeTestPhase failed", e);
}
},
/**
* Override sync telemetry functions so that we can detect errors generating
* the sync ping, and count how many pings we report.