Bug 1459243 - Always store last check pref in RemoteSettings r=mgoodwin
authorMathieu Leplatre <mathieu@mozilla.com>
Wed, 09 May 2018 14:19:02 +0200
changeset 417622 66f099c14bd9bcfc550532ddb0196941ebf99ee6
parent 417621 6505db7f437de65a5b158baa8ff890239721d2b8
child 417623 6c4bad08fa9a8946b103f814c8cd08d22a7e8364
push id33974
push userncsoregi@mozilla.com
push dateThu, 10 May 2018 09:47:43 +0000
treeherdermozilla-central@b52b2eb81d1e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgoodwin
bugs1459243
milestone62.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 1459243 - Always store last check pref in RemoteSettings r=mgoodwin MozReview-Commit-ID: 2CvYBKoOOaE
services/common/remote-settings.js
services/common/tests/unit/test_blocklist_clients.js
services/common/tests/unit/test_remote_settings.js
--- a/services/common/remote-settings.js
+++ b/services/common/remote-settings.js
@@ -120,21 +120,21 @@ async function fetchLatestChanges(url, l
   }
 
   return {changes, currentEtag, serverTimeMillis, backoffSeconds};
 }
 
 
 class RemoteSettingsClient {
 
-  constructor(collectionName, { lastCheckTimePref, bucketName, signerName }) {
+  constructor(collectionName, { bucketName, signerName, lastCheckTimePref }) {
     this.collectionName = collectionName;
-    this.lastCheckTimePref = lastCheckTimePref;
     this.bucketName = bucketName;
     this.signerName = signerName;
+    this._lastCheckTimePref = lastCheckTimePref;
 
     this._callbacks = new Map();
     this._callbacks.set("sync", []);
 
     this._kinto = null;
   }
 
   get identifier() {
@@ -142,16 +142,20 @@ class RemoteSettingsClient {
   }
 
   get filename() {
     // Replace slash by OS specific path separator (eg. Windows)
     const identifier = OS.Path.join(...this.identifier.split("/"));
     return `${identifier}.json`;
   }
 
+  get lastCheckTimePref() {
+    return this._lastCheckTimePref || `services.settings.${this.bucketName}.${this.collectionName}.last_check`;
+  }
+
   on(event, callback) {
     if (!this._callbacks.has(event)) {
       throw new Error(`Unknown event type ${event}`);
     }
     this._callbacks.get(event).push(callback);
   }
 
   /**
@@ -410,22 +414,16 @@ class RemoteSettingsClient {
   }
 
   /**
    * Save last time server was checked in users prefs.
    *
    * @param {Date} serverTime   the current date return by server.
    */
   _updateLastCheck(serverTime) {
-    if (!this.lastCheckTimePref) {
-      // If not set (default), it is not necessary to store the last check timestamp.
-      return;
-    }
-    // Storing the last check time is mainly a matter of retro-compatibility with
-    // the blocklists clients.
     const checkedServerTimeInSeconds = Math.round(serverTime / 1000);
     Services.prefs.setIntPref(this.lastCheckTimePref, checkedServerTimeInSeconds);
   }
 }
 
 
 function remoteSettingsFunction() {
   const _clients = new Map();
--- a/services/common/tests/unit/test_blocklist_clients.js
+++ b/services/common/tests/unit/test_blocklist_clients.js
@@ -122,16 +122,19 @@ add_task(async function test_list_is_wri
     const content = await readJSON(profFile.path);
     equal(content.data[0].blockID, testData[testData.length - 1]);
   }
 });
 add_task(clear_state);
 
 add_task(async function test_current_server_time_is_saved_in_pref() {
   for (let {client} of gBlocklistClients) {
+    // The lastCheckTimePref was customized:
+    ok(/services\.blocklist\.(\w+)\.checked/.test(client.lastCheckTimePref), client.lastCheckTimePref);
+
     const serverTime = Date.now();
     await client.maybeSync(2000, serverTime);
     const after = Services.prefs.getIntPref(client.lastCheckTimePref);
     equal(after, Math.round(serverTime / 1000));
   }
 });
 add_task(clear_state);
 
--- a/services/common/tests/unit/test_remote_settings.js
+++ b/services/common/tests/unit/test_remote_settings.js
@@ -74,16 +74,25 @@ add_task(async function test_records_obt
 
   // Open the collection, verify it's been populated:
   // Our test data has a single record; it should be in the local collection
   const list = await client.get();
   equal(list.length, 1);
 });
 add_task(clear_state);
 
+add_task(async function test_current_server_time_is_saved_in_pref() {
+  const serverTime = Date.now();
+  await client.maybeSync(2000, serverTime);
+  equal(client.lastCheckTimePref, "services.settings.main.password-fields.last_check");
+  const after = Services.prefs.getIntPref(client.lastCheckTimePref);
+  equal(after, Math.round(serverTime / 1000));
+});
+add_task(clear_state);
+
 add_task(async function test_records_changes_are_overwritten_by_server_changes() {
   // Create some local conflicting data, and make sure it syncs without error.
   const collection = await client.openCollection();
   await collection.create({
     "website": "",
     "id": "9d500963-d80e-3a91-6e74-66f3811b99cc"
   }, { useRecordId: true });