Bug 1266794 - Fix lazy load of blocklist collections preferences draft
authorMathieu Leplatre <mathieu@mozilla.com>
Fri, 22 Apr 2016 19:56:33 +0200
changeset 355481 53a70521037b8cb49d6f128290640f8e256f916a
parent 355401 fc15477ce628599519cb0055f52cc195d640dc94
child 519206 484c7faa59cbc7af4c61d358bc624db3a36cbafb
push id16299
push usermleplatre@mozilla.com
push dateFri, 22 Apr 2016 17:57:10 +0000
bugs1266794
milestone48.0a1
Bug 1266794 - Fix lazy load of blocklist collections preferences MozReview-Commit-ID: Eg6CoI95YPH
services/common/KintoBlocklist.js
--- a/services/common/KintoBlocklist.js
+++ b/services/common/KintoBlocklist.js
@@ -56,33 +56,34 @@ function kintoClient() {
   };
 
   return new Kinto(config);
 }
 
 
 class BlocklistClient {
 
-  constructor(collectionName, lastCheckTimePref, processCallback) {
-    this.collectionName = collectionName;
+  constructor(collectionNamePref, lastCheckTimePref, processCallback) {
+    this.collectionNamePref = collectionNamePref;
     this.lastCheckTimePref = lastCheckTimePref;
     this.processCallback = processCallback;
   }
 
   /**
    * Synchronize from Kinto server, if necessary.
    *
    * @param {int}  lastModified the lastModified date (on the server) for
                                 the remote collection.
    * @param {Date} serverTime   the current date return by the server.
    * @return {Promise}          which rejects on sync or process failure.
    */
   maybeSync(lastModified, serverTime) {
     let db = kintoClient();
-    let collection = db.collection(this.collectionName);
+    const collectionName = Services.prefs.getCharPref(this.collectionNamePref);
+    let collection = db.collection(collectionName);
 
     return Task.spawn((function* syncCollection() {
       try {
         yield collection.db.open();
 
         let collectionLastModified = yield collection.db.getLastModified();
         // If the data is up to date, there's no need to sync. We still need
         // to record the fact that a check happened.
@@ -156,30 +157,30 @@ function* updateJSONBlocklist(filename, 
     Services.cpmm.sendAsyncMessage("Blocklist:reload-from-disk", eventData);
   } catch(e) {
     Cu.reportError(e);
   }
 }
 
 
 this.OneCRLBlocklistClient = new BlocklistClient(
-  Services.prefs.getCharPref(PREF_KINTO_ONECRL_COLLECTION),
+  PREF_KINTO_ONECRL_COLLECTION,
   PREF_KINTO_ONECRL_CHECKED_SECONDS,
   updateCertBlocklist
 );
 
 this.AddonBlocklistClient = new BlocklistClient(
-  Services.prefs.getCharPref(PREF_KINTO_ADDONS_COLLECTION),
+  PREF_KINTO_ADDONS_COLLECTION,
   PREF_KINTO_ADDONS_CHECKED_SECONDS,
   updateJSONBlocklist.bind(undefined, FILENAME_ADDONS_JSON)
 );
 
 this.GfxBlocklistClient = new BlocklistClient(
-  Services.prefs.getCharPref(PREF_KINTO_GFX_COLLECTION),
+  PREF_KINTO_GFX_COLLECTION,
   PREF_KINTO_GFX_CHECKED_SECONDS,
   updateJSONBlocklist.bind(undefined, FILENAME_GFX_JSON)
 );
 
 this.PluginBlocklistClient = new BlocklistClient(
-  Services.prefs.getCharPref(PREF_KINTO_PLUGINS_COLLECTION),
+  PREF_KINTO_PLUGINS_COLLECTION,
   PREF_KINTO_PLUGINS_CHECKED_SECONDS,
   updateJSONBlocklist.bind(undefined, FILENAME_PLUGINS_JSON)
 );