Bug 1472238: hook up alwaysConnect pref changes r?lina draft
authorEthan Glasser-Camp <ethan@betacantrips.com>
Fri, 29 Jun 2018 12:33:20 -0400
changeset 823235 f5f84dad9f9a2b29a611282f0a0bf951a65c094c
parent 822981 4e6486b672b32aba075b704c6b1e41e8ccf7a135
child 823236 d36b97b0a90050aa53e621df0ef0d1de1685114c
push id117622
push userbmo:eglassercamp@mozilla.com
push dateThu, 26 Jul 2018 21:32:07 +0000
reviewerslina
bugs1472238
milestone63.0a1
Bug 1472238: hook up alwaysConnect pref changes r?lina The original code had a bug in that going from disabled to enabled would always connect, whereas actually we want to only connect if there are records (or alwaysConnect is on). We maintain the existing behavior that if the user has set dom.push.connection.enabled to false, we don't connect, figuring that this is the way a privacy-conscious user might indicate that they don't want to talk to "the mothership". MozReview-Commit-ID: ClbhYhnHVog
dom/push/PushService.jsm
--- a/dom/push/PushService.jsm
+++ b/dom/push/PushService.jsm
@@ -291,17 +291,17 @@ var PushService = {
         if (aData == "dom.push.serverURL") {
           console.debug("observe: dom.push.serverURL changed for websocket",
                 prefs.get("serverURL"));
           this._stateChangeProcessEnqueue(_ =>
             this._changeServerURL(prefs.get("serverURL"),
                                   CHANGING_SERVICE_EVENT)
           );
 
-        } else if (aData == "dom.push.connection.enabled") {
+        } else if (aData == "dom.push.connection.enabled" || aData == "dom.push.alwaysConnect") {
           this._stateChangeProcessEnqueue(_ =>
             this._changeStateConnectionEnabledEvent(prefs.get("connection.enabled"))
           );
         }
         break;
 
       case "idle-daily":
         this._dropExpiredRegistrations().catch(error => {
@@ -496,16 +496,18 @@ var PushService = {
 
     // The offline-status-changed event is used to know
     // when to (dis)connect. It may not fire if the underlying OS changes
     // networks; in such a case we rely on timeout.
     Services.obs.addObserver(this, "network:offline-status-changed");
 
     // Used to monitor if the user wishes to disable Push.
     prefs.observe("connection.enabled", this);
+    // Used to load-test the server-side infrastructure for broadcast.
+    prefs.observe("alwaysConnect", this);
 
     // Prunes expired registrations and notifies dormant service workers.
     Services.obs.addObserver(this, "idle-daily");
 
     // Prunes registrations for sites for which the user revokes push
     // permissions.
     Services.obs.addObserver(this, "perm-changed");
   },
@@ -579,16 +581,17 @@ var PushService = {
   _stopObservers: function() {
     console.debug("stopObservers()");
 
     if (this._state < PUSH_SERVICE_ACTIVATING) {
       return;
     }
 
     prefs.ignore("connection.enabled", this);
+    prefs.ignore("alwaysConnect", this);
 
     Services.obs.removeObserver(this, "network:offline-status-changed");
     Services.obs.removeObserver(this, "clear-origin-attributes-data");
     Services.obs.removeObserver(this, "idle-daily");
     Services.obs.removeObserver(this, "perm-changed");
   },
 
   _shutdownService() {