author | Sebastian Hengst <archaeopteryx@coole-files.de> |
Thu, 29 Sep 2016 19:53:44 +0200 | |
changeset 316388 | 70a79f04def4c008fd2168e0f929c76570e155f4 |
parent 316387 | 88a8ec4889026852ce8a9c59534d67a767e5bc95 |
child 316389 | 2fae37a9ffe6e5e4f63dbb3f91f30c9ef8b88d45 |
push id | 30770 |
push user | kwierso@gmail.com |
push date | Wed, 05 Oct 2016 00:00:48 +0000 |
treeherder | mozilla-central@3470e326025c [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | kitcambridge |
bugs | 1306397 |
milestone | 52.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
|
dom/push/PushService.jsm | file | annotate | diff | comparison | revisions | |
dom/push/PushServiceWebSocket.jsm | file | annotate | diff | comparison | revisions |
--- a/dom/push/PushService.jsm +++ b/dom/push/PushService.jsm @@ -300,18 +300,17 @@ this.PushService = { /* * We need to call uninit() on shutdown to clean up things that modules * aren't very good at automatically cleaning up, so we don't get shutdown * leaks on browser shutdown. */ case "quit-application": this.uninit(); break; - case "network-active-changed": /* On B2G. */ - case "network:offline-status-changed": /* On desktop. */ + case "network:offline-status-changed": this._stateChangeProcessEnqueue(_ => this._changeStateOfflineEvent(aData === "offline", false) ); break; case "nsPref:changed": if (aData == "dom.push.serverURL") { console.debug("observe: dom.push.serverURL changed for websocket", @@ -379,29 +378,16 @@ this.PushService = { console.debug("backgroundUnregister: Notifying server", record); this._sendUnregister(record, reason).then(() => { gPushNotifier.notifySubscriptionModified(record.scope, record.principal); }).catch(e => { console.error("backgroundUnregister: Error notifying server", e); }); }, - // utility function used to add/remove observers in startObservers() and - // stopObservers() - getNetworkStateChangeEventName: function() { - try { - let networkManager = Cc["@mozilla.org/network/manager;1"]; - if (networkManager) { - networkManager.getService(Ci.nsINetworkManager); - return "network-active-changed"; - } - } catch (e) {} - return "network:offline-status-changed"; - }, - _findService: function(serverURL) { console.debug("findService()"); let uri; let service; if (!serverURL) { console.warn("findService: No dom.push.serverURL found"); @@ -528,36 +514,20 @@ this.PushService = { console.debug("startObservers()"); if (this._state != PUSH_SERVICE_ACTIVATING) { return; } Services.obs.addObserver(this, "clear-origin-data", false); - // On B2G the NetworkManager interface fires a network-active-changed - // event. - // - // The "active network" is based on priority - i.e. Wi-Fi has higher - // priority than data. The PushService should just use the preferred - // network, and not care about all interface changes. - // network-active-changed is not fired when the network goes offline, but - // socket connections time out. The check for Services.io.offline in - // PushServiceWebSocket._beginWSSetup() prevents unnecessary retries. When - // the network comes back online, network-active-changed is fired. - // - // On non-B2G platforms, the offline-status-changed event is used to know + // 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. - // - // On B2G both events fire, one after the other, when the network goes - // online, so we explicitly check for the presence of NetworkManager and - // don't add an observer for offline-status-changed on B2G. - this._networkStateChangeEventName = this.getNetworkStateChangeEventName(); - Services.obs.addObserver(this, this._networkStateChangeEventName, false); + Services.obs.addObserver(this, "network:offline-status-changed", false); // Used to monitor if the user wishes to disable Push. prefs.observe("connection.enabled", this); // Prunes expired registrations and notifies dormant service workers. Services.obs.addObserver(this, "idle-daily", false); // Prunes registrations for sites for which the user revokes push @@ -635,17 +605,17 @@ this.PushService = { console.debug("stopObservers()"); if (this._state < PUSH_SERVICE_ACTIVATING) { return; } prefs.ignore("connection.enabled", this); - Services.obs.removeObserver(this, this._networkStateChangeEventName); + Services.obs.removeObserver(this, "network:offline-status-changed"); Services.obs.removeObserver(this, "clear-origin-data"); Services.obs.removeObserver(this, "idle-daily"); Services.obs.removeObserver(this, "perm-changed"); }, _shutdownService() { let promiseChangeURL = this._changeServerURL("", UNINIT_EVENT); this._setState(PUSH_SERVICE_UNINIT);
--- a/dom/push/PushServiceWebSocket.jsm +++ b/dom/push/PushServiceWebSocket.jsm @@ -19,22 +19,16 @@ Cu.import("resource://gre/modules/XPCOMU const {PushDB} = Cu.import("resource://gre/modules/PushDB.jsm"); const {PushRecord} = Cu.import("resource://gre/modules/PushRecord.jsm"); const { PushCrypto, getCryptoParams, } = Cu.import("resource://gre/modules/PushCrypto.jsm"); -if (AppConstants.MOZ_B2G) { - XPCOMUtils.defineLazyServiceGetter(this, "gPowerManagerService", - "@mozilla.org/power/powermanagerservice;1", - "nsIPowerManagerService"); -} - const kPUSHWSDB_DB_NAME = "pushapi"; const kPUSHWSDB_DB_VERSION = 5; // Change this if the IndexedDB format changes const kPUSHWSDB_STORE_NAME = "pushapi"; // WebSocket close code sent by the server to indicate that the client should // not automatically reconnect. const kBACKOFF_WS_STATUS_CODE = 4774; @@ -511,17 +505,16 @@ this.PushServiceWebSocket = { console.debug("beginWSSetup: Connecting to", uri.spec); this._wsListener = new PushWebSocketListener(this); this._ws.protocol = "push-notification"; try { // Grab a wakelock before we open the socket to ensure we don't go to // sleep before connection the is opened. this._ws.asyncOpen(uri, uri.spec, 0, this._wsListener, null); - this._acquireWakeLock(); this._currentState = STATE_WAITING_FOR_WS_START; } catch(e) { console.error("beginWSSetup: Error opening websocket.", "asyncOpen failed", e); this._reconnect(); } }, @@ -532,58 +525,16 @@ this.PushServiceWebSocket = { this._beginWSSetup(); } }, isConnected: function() { return !!this._ws; }, - _acquireWakeLock: function() { - if (!AppConstants.MOZ_B2G) { - return; - } - - // Disable the wake lock on non-B2G platforms to work around bug 1154492. - if (!this._socketWakeLock) { - console.debug("acquireWakeLock: Acquiring Socket Wakelock"); - this._socketWakeLock = gPowerManagerService.newWakeLock("cpu"); - } - if (!this._socketWakeLockTimer) { - console.debug("acquireWakeLock: Creating Socket WakeLock Timer"); - this._socketWakeLockTimer = Cc["@mozilla.org/timer;1"] - .createInstance(Ci.nsITimer); - } - - console.debug("acquireWakeLock: Setting Socket WakeLock Timer"); - this._socketWakeLockTimer - .initWithCallback(this._releaseWakeLock.bind(this), - // Allow the same time for socket setup as we do for - // requests after the setup. Fudge it a bit since - // timers can be a little off and we don't want to go - // to sleep just as the socket connected. - this._requestTimeout + 1000, - Ci.nsITimer.TYPE_ONE_SHOT); - }, - - _releaseWakeLock: function() { - if (!AppConstants.MOZ_B2G) { - return; - } - - console.debug("releaseWakeLock: Releasing Socket WakeLock"); - if (this._socketWakeLockTimer) { - this._socketWakeLockTimer.cancel(); - } - if (this._socketWakeLock) { - this._socketWakeLock.unlock(); - this._socketWakeLock = null; - } - }, - /** * Protocol handler invoked by server message. */ _handleHelloReply: function(reply) { console.debug("handleHelloReply()"); if (this._currentState != STATE_WAITING_FOR_HELLO) { console.error("handleHelloReply: Unexpected state", this._currentState, "(expected STATE_WAITING_FOR_HELLO)"); @@ -995,17 +946,16 @@ this.PushServiceWebSocket = { console.error("receivedUpdate: Error acknowledging message", aChannelID, aLatestVersion, err); }); }, // begin Push protocol handshake _wsOnStart: function(context) { console.debug("wsOnStart()"); - this._releaseWakeLock(); if (this._currentState != STATE_WAITING_FOR_WS_START) { console.error("wsOnStart: NOT in STATE_WAITING_FOR_WS_START. Current", "state", this._currentState, "Skipping"); return; } let data = { @@ -1025,17 +975,16 @@ this.PushServiceWebSocket = { * This statusCode is not the websocket protocol status code, but the TCP * connection close status code. * * If we do not explicitly call ws.close() then statusCode is always * NS_BASE_STREAM_CLOSED, even on a successful close. */ _wsOnStop: function(context, statusCode) { console.debug("wsOnStop()"); - this._releaseWakeLock(); if (statusCode != Cr.NS_OK && !this._skipReconnect) { console.debug("wsOnStop: Reconnecting after socket error", statusCode); this._reconnect(); return; } this._shutdownWS();