From 62dedc9bc4fb26d5d851014307f23403d0a0f02e Mon Sep 17 00:00:00 2001 From: Nikhil Marathe Date: Tue, 7 May 2013 09:51:24 -0400 Subject: [PATCH] Bug 863598 - SimplePush: Make PushService a module. r=dougt, a=lsblakk --HG-- rename : dom/push/src/PushService.js => dom/push/src/PushService.jsm --- b2g/chrome/content/shell.js | 1 + b2g/installer/package-manifest.in | 2 - dom/push/src/Makefile.in | 6 +- .../src/{PushService.js => PushService.jsm} | 68 ++++++++++--------- dom/push/src/PushService.manifest | 4 -- 5 files changed, 41 insertions(+), 40 deletions(-) rename dom/push/src/{PushService.js => PushService.jsm} (97%) delete mode 100644 dom/push/src/PushService.manifest diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index f743d5bd90b8..9c1f6118fb8b 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -12,6 +12,7 @@ Cu.import('resource://gre/modules/DOMFMRadioParent.jsm'); Cu.import('resource://gre/modules/AlarmService.jsm'); Cu.import('resource://gre/modules/ActivitiesService.jsm'); Cu.import('resource://gre/modules/PermissionPromptHelper.jsm'); +Cu.import('resource://gre/modules/PushService.jsm'); Cu.import('resource://gre/modules/ObjectWrapper.jsm'); Cu.import('resource://gre/modules/accessibility/AccessFu.jsm'); Cu.import('resource://gre/modules/Payment.jsm'); diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index b799d0dcaf88..94dbf5716a3b 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -502,8 +502,6 @@ @BINPATH@/components/AppsService.manifest @BINPATH@/components/Push.js @BINPATH@/components/Push.manifest -@BINPATH@/components/PushService.js -@BINPATH@/components/PushService.manifest @BINPATH@/components/nsDOMIdentity.js @BINPATH@/components/nsIDService.js diff --git a/dom/push/src/Makefile.in b/dom/push/src/Makefile.in index b9e6b18c20fc..2470e2befed0 100644 --- a/dom/push/src/Makefile.in +++ b/dom/push/src/Makefile.in @@ -12,8 +12,10 @@ include $(DEPTH)/config/autoconf.mk EXTRA_COMPONENTS = \ Push.js \ Push.manifest \ - PushService.js \ - PushService.manifest \ + $(NULL) + +EXTRA_JS_MODULES = \ + PushService.jsm \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/push/src/PushService.js b/dom/push/src/PushService.jsm similarity index 97% rename from dom/push/src/PushService.js rename to dom/push/src/PushService.jsm index 8edb63432be6..b338b2abb7ce 100644 --- a/dom/push/src/PushService.js +++ b/dom/push/src/PushService.jsm @@ -5,7 +5,7 @@ "use strict"; function debug(s) { -// dump("-*- PushService.js: " + s + "\n"); + // dump("-*- PushService.jsm: " + s + "\n"); } const Cc = Components.classes; @@ -19,6 +19,8 @@ Cu.import("resource://gre/modules/IndexedDBHelper.jsm"); Cu.import("resource://gre/modules/services-common/preferences.js"); Cu.import("resource://gre/modules/commonjs/promise/core.js"); +this.EXPORTED_SYMBOLS = ["PushService"]; + const prefs = new Preferences("services.push."); const kPUSHDB_DB_NAME = "push"; @@ -260,16 +262,6 @@ this.PushWebSocketListener.prototype = { } } -/** - * The implementation of the SimplePush system. This runs in the B2G parent - * process and is started on boot. It uses WebSockets to communicate with the - * server and PushDB (IndexedDB) for persistence. - */ -function PushService() -{ - debug("PushService Constructor."); -} - // websocket states // websocket is off const STATE_SHUT_DOWN = 0; @@ -281,26 +273,14 @@ const STATE_WAITING_FOR_HELLO = 2; // websocket operational, handshake completed, begin protocol messaging const STATE_READY = 3; -PushService.prototype = { - classID : Components.ID("{0ACE8D15-9B15-41F4-992F-C88820421DBF}"), - - QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver, - Ci.nsIUDPServerSocketListener]), - +/** + * The implementation of the SimplePush system. This runs in the B2G parent + * process and is started on boot. It uses WebSockets to communicate with the + * server and PushDB (IndexedDB) for persistence. + */ +this.PushService = { observe: function observe(aSubject, aTopic, aData) { switch (aTopic) { - case "app-startup": - - if (!prefs.get("enabled")) - return; - - Services.obs.addObserver(this, "final-ui-startup", false); - Services.obs.addObserver(this, "profile-change-teardown", false); - Services.obs.addObserver(this, - "network-interface-state-changed", - false); - Services.obs.addObserver(this, "webapps-uninstall", false); - break; case "final-ui-startup": Services.obs.removeObserver(this, "final-ui-startup"); this.init(); @@ -441,6 +421,13 @@ PushService.prototype = { init: function() { debug("init()"); + if (!prefs.get("enabled")) + 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._db = new PushDB(this); let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"] @@ -486,8 +473,15 @@ PushService.prototype = { _shutdown: function() { debug("_shutdown()"); - this._db.close(); - this._db = null; + + Services.obs.removeObserver(this, "network-interface-state-changed", + false); + Services.obs.removeObserver(this, "webapps-uninstall", false); + + if (this._db) { + this._db.close(); + this._db = null; + } if (this._udpServer) { this._udpServer.close(); @@ -498,6 +492,15 @@ PushService.prototype = { // or receiving notifications. this._shutdownWS(); + // At this point, profile-change-net-teardown has already fired, so the + // WebSocket has been closed with NS_ERROR_ABORT (if it was up) and will + // try to reconnect. Stop the timer. + if (this._retryTimeoutTimer) + this._retryTimeoutTimer.cancel(); + + if (this._requestTimeoutTimer) + this._requestTimeoutTimer.cancel(); + debug("shutdown complete!"); }, @@ -1178,6 +1181,7 @@ PushService.prototype = { */ _wsOnStop: function(context, statusCode) { debug("wsOnStop()"); + if (statusCode != Cr.NS_OK && !(statusCode == Cr.NS_BASE_STREAM_CLOSED && this._willBeWokenUpByUDP)) { debug("Socket error " + statusCode); @@ -1329,4 +1333,4 @@ PushService.prototype = { } } -this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PushService]); +PushService.init(); diff --git a/dom/push/src/PushService.manifest b/dom/push/src/PushService.manifest deleted file mode 100644 index 03e034eaeffe..000000000000 --- a/dom/push/src/PushService.manifest +++ /dev/null @@ -1,4 +0,0 @@ -component {0ACE8D15-9B15-41F4-992F-C88820421DBF} PushService.js -contract @mozilla.org/PushService;1 {0ACE8D15-9B15-41F4-992F-C88820421DBF} -category app-startup PushService service,@mozilla.org/PushService;1 -