Bug 1439777 p1 - Remove X-Weave-Alert support. r?markh draft
authorEdouard Oger <eoger@fastmail.com>
Thu, 22 Feb 2018 15:44:11 +0800
changeset 763946 d0f9168395e4bf9388a7558ad94ce83dffeba546
parent 763748 a4ef1082c51d5b4508882c22487f6c8de5b35e2a
child 763947 7f34978e39658555fe2a865b659718a006c190e5
push id101608
push userbmo:eoger@fastmail.com
push dateTue, 06 Mar 2018 22:21:23 +0000
reviewersmarkh
bugs1439777
milestone60.0a1
Bug 1439777 p1 - Remove X-Weave-Alert support. r?markh MozReview-Commit-ID: L9GTrn8HPYJ
services/sync/modules/policies.js
services/sync/modules/service.js
services/sync/modules/status.js
services/sync/services-sync.js
services/sync/tests/unit/test_errorhandler_eol.js
services/sync/tests/unit/xpcshell.ini
services/sync/tps/extensions/tps/resource/tps.jsm
--- a/services/sync/modules/policies.js
+++ b/services/sync/modules/policies.js
@@ -52,17 +52,16 @@ SyncScheduler.prototype = {
 
   setDefaults: function setDefaults() {
     this._log.trace("Setting SyncScheduler policy values to defaults.");
 
     this.singleDeviceInterval = getThrottledIntervalPreference("scheduler.fxa.singleDeviceInterval");
     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;
 
     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
@@ -401,22 +400,16 @@ SyncScheduler.prototype = {
           this._log.debug("Going to sleep, doing a quick sync.");
           this.scheduleNextSync(0, {engines: ["tabs"], why: "sleep"});
         }
         break;
     }
   },
 
   adjustSyncInterval: function adjustSyncInterval() {
-    if (Status.eol) {
-      this._log.debug("Server status is EOL; using eolInterval.");
-      this.syncInterval = this.eolInterval;
-      return;
-    }
-
     if (this.numClients <= 1) {
       this._log.trace("Adjusting syncInterval to singleDeviceInterval.");
       this.syncInterval = this.singleDeviceInterval;
       return;
     }
 
     // Only MULTI_DEVICE clients will enter this if statement
     // since SINGLE_USER clients will be handled above.
@@ -656,18 +649,16 @@ SyncScheduler.prototype = {
 
 };
 
 function ErrorHandler(service) {
   this.service = service;
   this.init();
 }
 ErrorHandler.prototype = {
-  MINIMUM_ALERT_INTERVAL_MSEC: 604800000,   // One week.
-
   /**
    * Flag that turns on error reporting for all errors, incl. network errors.
    */
   dontIgnoreErrors: false,
 
   /**
    * Flag that indicates if we have already reported a prolonged failure.
    * Once set, we don't report it again, meaning this error is only reported
@@ -945,108 +936,25 @@ ErrorHandler.prototype = {
 
     let result = (![Status.login, Status.sync].includes(SERVER_MAINTENANCE) &&
                   ![Status.login, Status.sync].includes(LOGIN_FAILED_NETWORK_ERROR));
     this._log.trace("shouldReportError: ${result} due to login=${login}, sync=${sync}",
                     {result, login: Status.login, sync: Status.sync});
     return result;
   },
 
-  get currentAlertMode() {
-    return Svc.Prefs.get("errorhandler.alert.mode");
-  },
-
-  set currentAlertMode(str) {
-    return Svc.Prefs.set("errorhandler.alert.mode", str);
-  },
-
-  get earliestNextAlert() {
-    return Svc.Prefs.get("errorhandler.alert.earliestNext", 0) * 1000;
-  },
-
-  set earliestNextAlert(msec) {
-    return Svc.Prefs.set("errorhandler.alert.earliestNext", msec / 1000);
-  },
-
-  clearServerAlerts() {
-    // If we have any outstanding alerts, apparently they're no longer relevant.
-    Svc.Prefs.resetBranch("errorhandler.alert");
-  },
-
-  /**
-   * X-Weave-Alert headers can include a JSON object:
-   *
-   *   {
-   *    "code":    // One of "hard-eol", "soft-eol".
-   *    "url":     // For "Learn more" link.
-   *    "message": // Logged in Sync logs.
-   *   }
-   */
-  handleServerAlert(xwa) {
-    if (!xwa.code) {
-      this._log.warn("Got structured X-Weave-Alert, but no alert code.");
-      return;
-    }
-
-    switch (xwa.code) {
-      // Gently and occasionally notify the user that this service will be
-      // shutting down.
-      case "soft-eol":
-        // Fall through.
-
-      // Tell the user that this service has shut down, and drop our syncing
-      // frequency dramatically.
-      case "hard-eol":
-        // Note that both of these alerts should be subservient to future "sign
-        // in with your Firefox Account" storage alerts.
-        if ((this.currentAlertMode != xwa.code) ||
-            (this.earliestNextAlert < Date.now())) {
-          CommonUtils.nextTick(function() {
-            Svc.Obs.notify("weave:eol", xwa);
-          }, this);
-          this._log.error("X-Weave-Alert: " + xwa.code + ": " + xwa.message);
-          this.earliestNextAlert = Date.now() + this.MINIMUM_ALERT_INTERVAL_MSEC;
-          this.currentAlertMode = xwa.code;
-        }
-        break;
-      default:
-        this._log.debug("Got unexpected X-Weave-Alert code: " + xwa.code);
-    }
-  },
-
   /**
    * Handle HTTP response results or exceptions and set the appropriate
    * Status.* bits.
    *
    * This method also looks for "side-channel" warnings.
    */
   checkServerError(resp) {
     // In this case we were passed a resolved value of Resource#_doRequest.
     switch (resp.status) {
-      case 200:
-      case 404:
-      case 513:
-        let xwa = resp.headers["x-weave-alert"];
-
-        // Only process machine-readable alerts.
-        if (!xwa || !xwa.startsWith("{")) {
-          this.clearServerAlerts();
-          return;
-        }
-
-        try {
-          xwa = JSON.parse(xwa);
-        } catch (ex) {
-          this._log.warn("Malformed X-Weave-Alert from server: " + xwa);
-          return;
-        }
-
-        this.handleServerAlert(xwa);
-        break;
-
       case 400:
         if (resp == RESPONSE_OVER_QUOTA) {
           Status.sync = OVER_QUOTA;
         }
         break;
 
       case 401:
         this.service.logout();
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -515,17 +515,17 @@ Sync11Service.prototype = {
     let info;
     try {
       info = await this.resource(infoURL).get();
     } catch (ex) {
       this.errorHandler.checkServerError(ex);
       throw ex;
     }
 
-    // Always check for errors; this is also where we look for X-Weave-Alert.
+    // Always check for errors.
     this.errorHandler.checkServerError(info);
     if (!info.success) {
       this._log.error("Aborting sync: failed to get collections.");
       throw info;
     }
     return info;
   },
 
--- a/services/sync/modules/status.js
+++ b/services/sync/modules/status.js
@@ -54,25 +54,16 @@ var Status = {
   },
 
   set sync(code) {
     this._log.debug("Status.sync: " + this._sync + " => " + code);
     this._sync = code;
     this.service = code == SYNC_SUCCEEDED ? STATUS_OK : SYNC_FAILED;
   },
 
-  get eol() {
-    let modePref = PREFS_BRANCH + "errorhandler.alert.mode";
-    try {
-      return Services.prefs.getCharPref(modePref) == "hard-eol";
-    } catch (ex) {
-      return false;
-    }
-  },
-
   get engines() {
     return this._engines;
   },
 
   set engines([name, code]) {
     this._log.debug("Status for engine " + name + ": " + code);
     this._engines[name] = code;
 
--- a/services/sync/services-sync.js
+++ b/services/sync/services-sync.js
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* global pref */
 
 pref("services.sync.lastversion", "firstrun");
 pref("services.sync.sendVersionInfo", true);
 
-pref("services.sync.scheduler.eolInterval", 604800); // 1 week
 pref("services.sync.scheduler.idleInterval", 3600);  // 1 hour
 pref("services.sync.scheduler.activeInterval", 600);   // 10 minutes
 pref("services.sync.scheduler.immediateInterval", 90);    // 1.5 minutes
 pref("services.sync.scheduler.idleTime", 300);   // 5 minutes
 
 pref("services.sync.scheduler.fxa.singleDeviceInterval", 3600); // 1 hour
 
 pref("services.sync.errorhandler.networkFailureReportTimeout", 1209600); // 2 weeks
deleted file mode 100644
--- a/services/sync/tests/unit/test_errorhandler_eol.js
+++ /dev/null
@@ -1,121 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-ChromeUtils.import("resource://services-sync/service.js");
-ChromeUtils.import("resource://services-sync/status.js");
-ChromeUtils.import("resource://services-sync/util.js");
-
-ChromeUtils.import("resource://testing-common/services/sync/fakeservices.js");
-
-function baseHandler(eolCode, request, response, statusCode, status, body) {
-  let alertBody = {
-    code: eolCode,
-    message: "Service is EOLed.",
-    url: "http://getfirefox.com",
-  };
-  response.setHeader("X-Weave-Timestamp", "" + new_timestamp(), false);
-  response.setHeader("X-Weave-Alert", "" + JSON.stringify(alertBody), false);
-  response.setStatusLine(request.httpVersion, statusCode, status);
-  response.bodyOutputStream.write(body, body.length);
-}
-
-function handler513(request, response) {
-  let statusCode = 513;
-  let status = "Upgrade Required";
-  let body = "{}";
-  baseHandler("hard-eol", request, response, statusCode, status, body);
-}
-
-function handler200(eolCode) {
-  return function(request, response) {
-    let statusCode = 200;
-    let status = "OK";
-    let body = "{\"meta\": 123456789010}";
-    baseHandler(eolCode, request, response, statusCode, status, body);
-  };
-}
-
-function sync_httpd_setup(infoHandler) {
-  let handlers = {
-    "/1.1/johndoe/info/collections": infoHandler,
-  };
-  return httpd_setup(handlers);
-}
-
-async function setUp(server) {
-  await configureIdentity({username: "johndoe"}, server);
-  new FakeCryptoService();
-}
-
-function do_check_soft_eol(eh, start) {
-  // We subtract 1000 because the stored value is in second precision.
-  Assert.ok(eh.earliestNextAlert >= (start + eh.MINIMUM_ALERT_INTERVAL_MSEC - 1000));
-  Assert.equal("soft-eol", eh.currentAlertMode);
-}
-function do_check_hard_eol(eh, start) {
-  // We subtract 1000 because the stored value is in second precision.
-  Assert.ok(eh.earliestNextAlert >= (start + eh.MINIMUM_ALERT_INTERVAL_MSEC - 1000));
-  Assert.equal("hard-eol", eh.currentAlertMode);
-  Assert.ok(Status.eol);
-}
-
-add_task(async function test_200_hard() {
-  let eh = Service.errorHandler;
-  let start = Date.now();
-  let server = sync_httpd_setup(handler200("hard-eol"));
-  await setUp(server);
-
-  let promiseObserved = promiseOneObserver("weave:eol");
-
-  await Service._fetchInfo();
-  Service.scheduler.adjustSyncInterval(); // As if we failed or succeeded in syncing.
-
-  let { subject } = await promiseObserved;
-  Assert.equal("hard-eol", subject.code);
-  do_check_hard_eol(eh, start);
-  Assert.equal(Service.scheduler.eolInterval, Service.scheduler.syncInterval);
-  eh.clearServerAlerts();
-  await promiseStopServer(server);
-});
-
-add_task(async function test_513_hard() {
-  let eh = Service.errorHandler;
-  let start = Date.now();
-  let server = sync_httpd_setup(handler513);
-  await setUp(server);
-
-  let promiseObserved = promiseOneObserver("weave:eol");
-
-  try {
-    await Service._fetchInfo();
-    Service.scheduler.adjustSyncInterval(); // As if we failed or succeeded in syncing.
-  } catch (ex) {
-    // Because fetchInfo will fail on a 513.
-  }
-  let { subject } = await promiseObserved;
-  Assert.equal("hard-eol", subject.code);
-  do_check_hard_eol(eh, start);
-  Assert.equal(Service.scheduler.eolInterval, Service.scheduler.syncInterval);
-  eh.clearServerAlerts();
-
-  await promiseStopServer(server);
-});
-
-add_task(async function test_200_soft() {
-  let eh = Service.errorHandler;
-  let start = Date.now();
-  let server = sync_httpd_setup(handler200("soft-eol"));
-  await setUp(server);
-
-  let promiseObserved = promiseOneObserver("weave:eol");
-
-  await Service._fetchInfo();
-  Service.scheduler.adjustSyncInterval(); // As if we failed or succeeded in syncing.
-  let { subject } = await promiseObserved;
-  Assert.equal("soft-eol", subject.code);
-  do_check_soft_eol(eh, start);
-  Assert.equal(Service.scheduler.singleDeviceInterval, Service.scheduler.syncInterval);
-  eh.clearServerAlerts();
-
-  await promiseStopServer(server);
-});
--- a/services/sync/tests/unit/xpcshell.ini
+++ b/services/sync/tests/unit/xpcshell.ini
@@ -99,17 +99,16 @@ run-sequentially = Frequent timeouts, bu
 [test_errorhandler_2.js]
 run-sequentially = Frequent timeouts, bug 1395148
 [test_errorhandler_filelog.js]
 # Bug 676978: test hangs on Android (see also testing/xpcshell/xpcshell.ini)
 skip-if = os == "android"
 [test_errorhandler_sync_checkServerError.js]
 # Bug 676978: test hangs on Android (see also testing/xpcshell/xpcshell.ini)
 skip-if = os == "android"
-[test_errorhandler_eol.js]
 [test_hmac_error.js]
 [test_interval_triggers.js]
 [test_node_reassignment.js]
 run-sequentially = Frequent timeouts, bug 1395148
 [test_score_triggers.js]
 [test_status.js]
 [test_status_checkSetup.js]
 [test_syncscheduler.js]
--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -263,17 +263,16 @@ var TPS = {
   },
 
   /**
    * Given that we cannot complely disable the automatic sync operations, we
    * massively delay the next sync. Sync operations have to only happen when
    * directly called via TPS.Sync()!
    */
   delayAutoSync: function TPS_delayAutoSync() {
-    Weave.Svc.Prefs.set("scheduler.eolInterval", 7200);
     Weave.Svc.Prefs.set("scheduler.immediateInterval", 7200);
     Weave.Svc.Prefs.set("scheduler.idleInterval", 7200);
     Weave.Svc.Prefs.set("scheduler.activeInterval", 7200);
     Weave.Svc.Prefs.set("syncThreshold", 10000000);
   },
 
   StartAsyncOperation: function TPS__StartAsyncOperation() {
     this._operations_pending++;