Bug 867913 - SimplePush: Monitor for active network change on B2G. r=jlebar

This commit is contained in:
Nikhil Marathe 2013-06-02 20:43:10 -07:00
parent d98176c5dc
commit 24d6c0abe6

View File

@ -293,9 +293,7 @@ this.PushService = {
Services.obs.removeObserver(this, "profile-change-teardown");
this._shutdown();
break;
case "network-interface-state-changed":
debug("network-interface-state-changed");
case "network-active-changed":
if (this._udpServer) {
this._udpServer.close();
}
@ -409,9 +407,20 @@ this.PushService = {
return null;
Services.obs.addObserver(this, "profile-change-teardown", false);
Services.obs.addObserver(this, "network-interface-state-changed",
false);
Services.obs.addObserver(this, "webapps-uninstall", false);
// This observer is notified only on B2G by
// dom/system/gonk/NetworkManager.js.
//
// 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
// _beginWSSetup() prevents unnecessary retries. When the network comes
// back online, network-active-changed is fired.
Services.obs.addObserver(this, "network-active-changed", false);
this._db = new PushDB(this);
let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
@ -464,8 +473,7 @@ this.PushService = {
_shutdown: function() {
debug("_shutdown()");
Services.obs.removeObserver(this, "network-interface-state-changed",
false);
Services.obs.removeObserver(this, "network-active-changed");
Services.obs.removeObserver(this, "webapps-uninstall", false);
if (this._db) {
@ -535,6 +543,11 @@ this.PushService = {
// Stop any pending reconnects scheduled for the near future.
this._stopAlarm();
if (Services.io.offline) {
debug("Network is offline.");
return;
}
var serverURL = prefs.get("serverURL");
if (!serverURL) {
debug("No services.push.serverURL found!");