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
--- 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() {