зеркало из https://github.com/mozilla/gecko-dev.git
Bug 863598 - SimplePush: Make PushService a module. r=dougt, a=lsblakk
--HG-- rename : dom/push/src/PushService.js => dom/push/src/PushService.jsm
This commit is contained in:
Родитель
6ad56bab44
Коммит
62dedc9bc4
|
@ -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');
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
@ -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();
|
|
@ -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
|
||||
|
Загрузка…
Ссылка в новой задаче