Bug 1450998: Part 3: Use bucket "main" by default draft
authorMathieu Leplatre <mathieu@mozilla.com>
Tue, 03 Apr 2018 06:07:51 -0700
changeset 777481 c8c997c3d335e991a09b7d33a405e2a026fab5b1
parent 777480 e4a2d5ca961ff833a9989063dc8435a4f5eb55cf
push id105222
push usermleplatre@mozilla.com
push dateWed, 04 Apr 2018 20:47:43 +0000
bugs1450998
milestone61.0a1
Bug 1450998: Part 3: Use bucket "main" by default MozReview-Commit-ID: 6nHo5INeDwS
modules/libpref/init/all.js
services/common/blocklist-clients.js
services/common/remote-settings.js
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2705,16 +2705,18 @@ pref("security.view-source.reachable-fro
 
 // If set to true, in some limited circumstances it may be possible to load
 // privileged content in frames inside unprivileged content.
 pref("security.allow_chrome_frames_inside_content", false);
 
 // Services security settings
 pref("services.settings.server", "https://firefox.settings.services.mozilla.com/v1");
 pref("services.settings.changes.path", "/buckets/monitor/collections/changes/records");
+pref("services.settings.default_bucket", "main");
+pref("services.settings.default_signer", "");
 
 // Blocklist preferences
 pref("extensions.blocklist.enabled", true);
 // OneCRL freshness checking depends on this value, so if you change it,
 // please also update security.onecrl.maximum_staleness_in_seconds.
 pref("extensions.blocklist.interval", 86400);
 // Required blocklist freshness for OneCRL OCSP bypass
 // (default is 1.25x extensions.blocklist.interval, or 30 hours)
--- a/services/common/blocklist-clients.js
+++ b/services/common/blocklist-clients.js
@@ -138,28 +138,31 @@ function initialize() {
     lastCheckTimePref: PREF_BLOCKLIST_ONECRL_CHECKED_SECONDS,
     signerName: "onecrl.content-signature.mozilla.org",
   });
   OneCRLBlocklistClient.on("change", updateCertBlocklist);
 
   AddonBlocklistClient = RemoteSettings(Services.prefs.getCharPref(PREF_BLOCKLIST_ADDONS_COLLECTION), {
     bucketName: Services.prefs.getCharPref(PREF_BLOCKLIST_BUCKET),
     lastCheckTimePref: PREF_BLOCKLIST_ADDONS_CHECKED_SECONDS,
+    signerName: "",  // disabled
   });
   AddonBlocklistClient.on("change", updateJSONBlocklist.bind(null, AddonBlocklistClient));
 
   PluginBlocklistClient = RemoteSettings(Services.prefs.getCharPref(PREF_BLOCKLIST_PLUGINS_COLLECTION), {
     bucketName: Services.prefs.getCharPref(PREF_BLOCKLIST_BUCKET),
     lastCheckTimePref: PREF_BLOCKLIST_PLUGINS_CHECKED_SECONDS,
+    signerName: "",  // disabled
   });
   PluginBlocklistClient.on("change", updateJSONBlocklist.bind(null, PluginBlocklistClient));
 
   GfxBlocklistClient = RemoteSettings(Services.prefs.getCharPref(PREF_BLOCKLIST_GFX_COLLECTION), {
     bucketName: Services.prefs.getCharPref(PREF_BLOCKLIST_BUCKET),
     lastCheckTimePref: PREF_BLOCKLIST_GFX_CHECKED_SECONDS,
+    signerName: "",  // disabled
   });
   GfxBlocklistClient.on("change", updateJSONBlocklist.bind(null, GfxBlocklistClient));
 
   PinningBlocklistClient = RemoteSettings(Services.prefs.getCharPref(PREF_BLOCKLIST_PINNING_COLLECTION), {
     bucketName: Services.prefs.getCharPref(PREF_BLOCKLIST_PINNING_BUCKET),
     lastCheckTimePref: PREF_BLOCKLIST_PINNING_CHECKED_SECONDS,
     signerName: "pinning-preload.content-signature.mozilla.org",
   });
--- a/services/common/remote-settings.js
+++ b/services/common/remote-settings.js
@@ -18,16 +18,18 @@ ChromeUtils.defineModuleGetter(this, "Ki
 ChromeUtils.defineModuleGetter(this, "FirefoxAdapter",
                                "resource://services-common/kinto-storage-adapter.js");
 ChromeUtils.defineModuleGetter(this, "CanonicalJSON",
                                "resource://gre/modules/CanonicalJSON.jsm");
 ChromeUtils.defineModuleGetter(this, "UptakeTelemetry",
                                "resource://services-common/uptake-telemetry.js");
 
 const PREF_SETTINGS_SERVER             = "services.settings.server";
+const PREF_SETTINGS_DEFAULT_BUCKET     = "services.settings.default_bucket";
+const PREF_SETTINGS_DEFAULT_SIGNER     = "services.settings.default_signer";
 const PREF_SETTINGS_VERIFY_SIGNATURE   = "services.settings.verify_signature";
 const PREF_SETTINGS_SERVER_BACKOFF     = "services.settings.server.backoff";
 const PREF_SETTINGS_CHANGES_PATH       = "services.settings.changes.path";
 const PREF_SETTINGS_LAST_UPDATE        = "services.settings.last_update_seconds";
 const PREF_SETTINGS_LAST_ETAG          = "services.settings.last_etag";
 const PREF_SETTINGS_CLOCK_SKEW_SECONDS = "services.settings.clock_skew_seconds";
 const PREF_SETTINGS_LOAD_DUMP          = "services.settings.load_dump";
 
@@ -396,31 +398,46 @@ 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();
 
+  // If not explicitly specified, use the default bucket name and signer.
+  const mainBucket = Services.prefs.getCharPref(PREF_SETTINGS_DEFAULT_BUCKET);
+  const defaultSigner = Services.prefs.getCharPref(PREF_SETTINGS_DEFAULT_SIGNER);
+
   const remoteSettings = function(collectionName, options) {
     // Get or instantiate a remote settings client.
-    const { bucketName } = options;
+    const rsOptions = {
+      bucketName: mainBucket,
+      signerName: defaultSigner,
+      ...options
+    };
+    const { bucketName } = rsOptions;
     const key = `${bucketName}/${collectionName}`;
     if (!_clients.has(key)) {
-      const c = new RemoteSettingsClient(collectionName, options);
+      const c = new RemoteSettingsClient(collectionName, rsOptions);
       _clients.set(key, c);
     }
     return _clients.get(key);
   };
 
   // This is called by the ping mechanism.
   // returns a promise that rejects if something goes wrong
   remoteSettings.pollChanges = async () => {