Bug 1383773 - Fix race between browser and TPS initialization. r?markh draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Mon, 24 Jul 2017 11:10:32 -0400
changeset 614479 767bac0fa25e72644066a0ffc8ad53bc7e31aca1
parent 614478 b8d5c1d7bf82ad052da3e846f8882f04b53a40c9
child 638865 cb6462ceeb08307b97a1d88a86c5f28eca089050
push id70011
push userbmo:tchiovoloni@mozilla.com
push dateMon, 24 Jul 2017 15:11:11 +0000
reviewersmarkh
bugs1383773
milestone56.0a1
Bug 1383773 - Fix race between browser and TPS initialization. r?markh MozReview-Commit-ID: 7Ie1IzRzEbI
services/sync/tps/extensions/tps/resource/tps.jsm
--- 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.