Bug 1357517 - Remove Preferences.jsm usage from some dom/push/* files. r=kitcambridge
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Fri, 28 Jul 2017 23:13:57 +0200
changeset 371882 68c4c9c19f3c2fc32f2542a95cccd75bbe6f39f2
parent 371881 8d62cdcccad47370b23b882f45ee713148f53ce1
child 371883 65105a4351d19736d45d6dbef38acd2e9313d7db
push id47611
push userarchaeopteryx@coole-files.de
push dateSun, 30 Jul 2017 09:20:48 +0000
treeherderautoland@8b577b152383 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge
bugs1357517
milestone56.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 1357517 - Remove Preferences.jsm usage from some dom/push/* files. r=kitcambridge
dom/push/PushDB.jsm
dom/push/PushRecord.jsm
dom/push/PushServiceHttp2.jsm
--- a/dom/push/PushDB.jsm
+++ b/dom/push/PushDB.jsm
@@ -2,17 +2,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 "use strict";
 
 const Cu = Components.utils;
 Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
-Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.importGlobalProperties(["indexedDB"]);
 
 this.EXPORTED_SYMBOLS = ["PushDB"];
 
 XPCOMUtils.defineLazyGetter(this, "console", () => {
   let {ConsoleAPI} = Cu.import("resource://gre/modules/Console.jsm", {});
   return new ConsoleAPI({
--- a/dom/push/PushRecord.jsm
+++ b/dom/push/PushRecord.jsm
@@ -5,32 +5,31 @@
 "use strict";
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
 
 Cu.import("resource://gre/modules/AppConstants.jsm");
-Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "EventDispatcher",
                                   "resource://gre/modules/Messaging.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
                                   "resource://gre/modules/PrivateBrowsingUtils.jsm");
 
 
 this.EXPORTED_SYMBOLS = ["PushRecord"];
 
-const prefs = new Preferences("dom.push.");
+const prefs = Services.prefs.getBranch("dom.push.");
 
 /**
  * The push subscription record, stored in IndexedDB.
  */
 function PushRecord(props) {
   this.pushEndpoint = props.pushEndpoint;
   this.scope = props.scope;
   this.originAttributes = props.originAttributes;
@@ -45,25 +44,25 @@ function PushRecord(props) {
   this.setQuota(props.quota);
   this.ctime = (typeof props.ctime === "number") ? props.ctime : 0;
 }
 
 PushRecord.prototype = {
   setQuota(suggestedQuota) {
     if (this.quotaApplies()) {
       let quota = +suggestedQuota;
-      this.quota = quota >= 0 ? quota : prefs.get("maxQuotaPerSubscription");
+      this.quota = quota >= 0 ? quota : prefs.getIntPref("maxQuotaPerSubscription");
     } else {
       this.quota = Infinity;
     }
   },
 
   resetQuota() {
     this.quota = this.quotaApplies() ?
-                 prefs.get("maxQuotaPerSubscription") : Infinity;
+                 prefs.getIntPref("maxQuotaPerSubscription") : Infinity;
   },
 
   updateQuota(lastVisit) {
     if (this.isExpired() || !this.quotaApplies()) {
       // Ignore updates if the registration is already expired, or isn't
       // subject to quota.
       return;
     }
@@ -76,17 +75,17 @@ PushRecord.prototype = {
     if (lastVisit > this.lastPush) {
       // If the user visited the site since the last time we received a
       // notification, reset the quota. `Math.max(0, ...)` ensures the
       // last visit date isn't in the future.
       let daysElapsed =
         Math.max(0, (Date.now() - lastVisit) / 24 / 60 / 60 / 1000);
       this.quota = Math.min(
         Math.round(8 * Math.pow(daysElapsed, -0.8)),
-        prefs.get("maxQuotaPerSubscription")
+        prefs.getIntPref("maxQuotaPerSubscription")
       );
     }
   },
 
   receivedPush(lastVisit) {
     this.updateQuota(lastVisit);
     this.pushCount++;
     this.lastPush = Date.now();
@@ -101,17 +100,17 @@ PushRecord.prototype = {
     if (this.recentMessageIDs) {
       this.recentMessageIDs.unshift(id);
     } else {
       this.recentMessageIDs = [id];
     }
     // Drop older message IDs from the end of the list.
     let maxRecentMessageIDs = Math.min(
       this.recentMessageIDs.length,
-      Math.max(prefs.get("maxRecentMessageIDsPerSubscription"), 0)
+      Math.max(prefs.getIntPref("maxRecentMessageIDsPerSubscription"), 0)
     );
     this.recentMessageIDs.length = maxRecentMessageIDs || 0;
   },
 
   hasRecentMessageID(id) {
     return this.recentMessageIDs && this.recentMessageIDs.includes(id);
   },
 
@@ -209,17 +208,17 @@ PushRecord.prototype = {
   },
 
   /**
    * Indicates whether the registration can deliver push messages to its
    * associated service worker. System subscriptions are exempt from the
    * permission check.
    */
   hasPermission() {
-    if (this.systemRecord || prefs.get("testing.ignorePermission")) {
+    if (this.systemRecord || prefs.getBoolPref("testing.ignorePermission", false)) {
       return true;
     }
     let permission = Services.perms.testExactPermissionFromPrincipal(
       this.principal, "desktop-notification");
     return permission == Ci.nsIPermissionManager.ALLOW_ACTION;
   },
 
   quotaChanged() {
--- a/dom/push/PushServiceHttp2.jsm
+++ b/dom/push/PushServiceHttp2.jsm
@@ -12,34 +12,33 @@ const Cr = Components.results;
 
 const {PushDB} = Cu.import("resource://gre/modules/PushDB.jsm");
 const {PushRecord} = Cu.import("resource://gre/modules/PushRecord.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
-Cu.import("resource://gre/modules/Preferences.jsm");
 
 const {
   PushCrypto,
   concatArray,
 } = Cu.import("resource://gre/modules/PushCrypto.jsm");
 
 this.EXPORTED_SYMBOLS = ["PushServiceHttp2"];
 
 XPCOMUtils.defineLazyGetter(this, "console", () => {
   let {ConsoleAPI} = Cu.import("resource://gre/modules/Console.jsm", {});
   return new ConsoleAPI({
     maxLogLevelPref: "dom.push.loglevel",
     prefix: "PushServiceHttp2",
   });
 });
 
-const prefs = new Preferences("dom.push.");
+const prefs = Services.prefs.getBranch("dom.push.");
 
 const kPUSHHTTP2DB_DB_NAME = "pushHttp2";
 const kPUSHHTTP2DB_DB_VERSION = 5; // Change this if the IndexedDB format changes
 const kPUSHHTTP2DB_STORE_NAME = "pushHttp2";
 
 /**
  * A proxy between the PushService and connections listening for incoming push
  * messages. The PushService can silence messages from the connections by
@@ -252,17 +251,17 @@ SubscriptionListener.prototype = {
     if (!Components.isSuccessCode(aStatus)) {
       this._reject(new Error("Error listening for messages: " + aStatus));
       return;
     }
 
     var statusCode = aRequest.QueryInterface(Ci.nsIHttpChannel).responseStatus;
 
     if (Math.floor(statusCode / 100) == 5) {
-      if (this._subInfo.retries < prefs.get("http2.maxRetries")) {
+      if (this._subInfo.retries < prefs.getIntPref("http2.maxRetries")) {
         this._subInfo.retries++;
         var retryAfter = retryAfterParser(aRequest);
         this._retryTimeoutID = setTimeout(_ =>
           {
             this._reject(
               {
                 retry: true,
                 subInfo: this._subInfo
@@ -427,17 +426,17 @@ this.PushServiceHttp2 = {
   },
 
   hasmainPushService: function() {
     return this._mainPushService !== null;
   },
 
   validServerURI: function(serverURI) {
     if (serverURI.scheme == "http") {
-      return !!prefs.get("testing.allowInsecureServerURL");
+      return !!prefs.getBoolPref("testing.allowInsecureServerURL", false);
     }
     return serverURI.scheme == "https";
   },
 
   connect: function(subscriptions) {
     this.startConnections(subscriptions);
   },
 
@@ -577,39 +576,39 @@ this.PushServiceHttp2 = {
     this._serverURI = aServerURL;
 
     return Promise.resolve();
   },
 
   _retryAfterBackoff: function(aSubscriptionUri, retryAfter) {
     console.debug("retryAfterBackoff()");
 
-    var resetRetryCount = prefs.get("http2.reset_retry_count_after_ms");
+    var resetRetryCount = prefs.getIntPref("http2.reset_retry_count_after_ms");
     // If it was running for some time, reset retry counter.
     if ((Date.now() - this._conns[aSubscriptionUri].lastStartListening) >
         resetRetryCount) {
       this._conns[aSubscriptionUri].countUnableToConnect = 0;
     }
 
-    let maxRetries = prefs.get("http2.maxRetries");
+    let maxRetries = prefs.getIntPref("http2.maxRetries");
     if (this._conns[aSubscriptionUri].countUnableToConnect >= maxRetries) {
       this._shutdownSubscription(aSubscriptionUri);
       this._resubscribe(aSubscriptionUri);
       return;
     }
 
     if (retryAfter !== -1) {
       // This is a 5xx response.
       this._conns[aSubscriptionUri].countUnableToConnect++;
       this._conns[aSubscriptionUri].retryTimerID =
         setTimeout(_ => this._listenForMsgs(aSubscriptionUri), retryAfter);
       return;
     }
 
-    retryAfter = prefs.get("http2.retryInterval") *
+    retryAfter = prefs.getIntPref("http2.retryInterval") *
       Math.pow(2, this._conns[aSubscriptionUri].countUnableToConnect);
 
     retryAfter = retryAfter * (0.8 + Math.random() * 0.4); // add +/-20%.
 
     this._conns[aSubscriptionUri].countUnableToConnect++;
     this._conns[aSubscriptionUri].retryTimerID =
       setTimeout(_ => this._listenForMsgs(aSubscriptionUri), retryAfter);