Bug 863598 - SimplePush: Make PushService a module. r=dougt

--HG--
rename : dom/push/src/PushService.js => dom/push/src/PushService.jsm
This commit is contained in:
Nikhil Marathe 2013-05-02 10:45:18 +05:30
Родитель f16e03b828
Коммит 850535cee6
5 изменённых файлов: 42 добавлений и 40 удалений

Просмотреть файл

@ -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');

Просмотреть файл

@ -510,8 +510,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

Просмотреть файл

@ -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

Просмотреть файл

@ -5,7 +5,7 @@
"use strict";
function debug(s) {
// dump("-*- PushService.js: " + s + "\n");
// dump("-*- PushService.jsm: " + s + "\n");
}
const Cc = Components.classes;
@ -20,6 +20,8 @@ Cu.import("resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
this.EXPORTED_SYMBOLS = ["PushService"];
const prefs = new Preferences("services.push.");
const kPUSHDB_DB_NAME = "push";
@ -261,16 +263,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;
@ -282,26 +274,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();
@ -383,6 +363,7 @@ PushService.prototype = {
debug("Error in getAllByManifestURL: url " + app.manifestURL);
});
break;
}
},
@ -442,6 +423,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"]
@ -487,8 +475,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();
@ -499,6 +494,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!");
},
@ -1173,6 +1177,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);
@ -1320,4 +1325,4 @@ PushService.prototype = {
}
}
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PushService]);
PushService.init();

Просмотреть файл

@ -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