Bug 1496637 - Fetch missed FxA commands sporadically on sync r=markh
authorEdouard Oger <eoger@fastmail.com>
Thu, 11 Oct 2018 20:08:33 +0000
changeset 499227 15d5855f46d51c0d5d5af1994644151cc70886c0
parent 499226 0b2ac40765b93f823d36fbdb7804594da6a81552
child 499228 ab32d2dc93e2969169b901d6c5be9ec07d8ffc07
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1496637
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496637 - Fetch missed FxA commands sporadically on sync r=markh Differential Revision: https://phabricator.services.mozilla.com/D7911
browser/app/profile/firefox.js
services/sync/modules/policies.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1414,16 +1414,19 @@ pref("identity.mobilepromo.ios", "https:
 #ifdef MOZ_DEV_EDITION
 pref("identity.fxaccounts.migrateToDevEdition", true);
 #else
 pref("identity.fxaccounts.migrateToDevEdition", false);
 #endif
 
 // If activated, send tab will use the new FxA commands backend.
 pref("identity.fxaccounts.commands.enabled", true);
+// How often should we try to fetch missed FxA commands on sync (in seconds).
+// Default is 24 hours.
+pref("identity.fxaccounts.commands.missed.fetch_interval", 86400);
 
 // On GTK, we now default to showing the menubar only when alt is pressed:
 #ifdef MOZ_WIDGET_GTK
 pref("ui.key.menuAccessKeyFocuses", true);
 #endif
 
 #ifdef NIGHTLY_BUILD
 pref("media.eme.vp9-in-mp4.enabled", true);
--- a/services/sync/modules/policies.js
+++ b/services/sync/modules/policies.js
@@ -78,16 +78,28 @@ SyncScheduler.prototype = {
   // nextSync is in milliseconds, but prefs can't hold that much
   get nextSync() {
     return Svc.Prefs.get("nextSync", 0) * 1000;
   },
   set nextSync(value) {
     Svc.Prefs.set("nextSync", Math.floor(value / 1000));
   },
 
+  get missedFxACommandsFetchInterval() {
+    return Services.prefs.getIntPref("identity.fxaccounts.commands.missed.fetch_interval");
+  },
+
+  get missedFxACommandsLastFetch() {
+    return Services.prefs.getIntPref("identity.fxaccounts.commands.missed.last_fetch", 0);
+  },
+
+  set missedFxACommandsLastFetch(val) {
+    Services.prefs.setIntPref("identity.fxaccounts.commands.missed.last_fetch", val);
+  },
+
   get syncInterval() {
     return this._syncInterval;
   },
   set syncInterval(value) {
     if (value != this._syncInterval) {
       Services.prefs.setIntPref("services.sync.syncInterval", value);
     }
   },
@@ -530,16 +542,26 @@ SyncScheduler.prototype = {
     }
 
     if (!Async.isAppReady()) {
       this._log.debug("Not initiating sync: app is shutting down");
       return;
     }
     Services.tm.dispatchToMainThread(() => {
       this.service.sync({engines, why});
+      const now = Math.round(new Date().getTime() / 1000);
+      // Only fetch missed messages in a "scheduled" sync so we don't race against
+      // the Push service reconnecting on a network link change for example.
+      if (why == "schedule" && now >= this.missedFxACommandsLastFetch + this.missedFxACommandsFetchInterval) {
+        fxAccounts.commands.fetchMissedRemoteCommands().then(() => {
+          this.missedFxACommandsLastFetch = now;
+        }).catch(e => {
+          this._log.error("Fetching missed remote commands failed.", e);
+        });
+      }
     });
   },
 
   /**
    * Set a timer for the next sync
    */
   scheduleNextSync(interval, {engines = null, why = null} = {}) {
     // If no interval was specified, use the current sync interval.