Bug 791911 - Listen for our child message managers dying and remove them from our list of managers to 'broadcast' to. r=gwagner

--HG--
extra : rebase_source : 407eb90d797c410db1a80a59ca2e52b42b68af87
This commit is contained in:
Blake Kaplan 2012-10-02 17:24:53 -04:00
parent 068ee6378f
commit a2b7792d24
2 changed files with 23 additions and 39 deletions

View File

@ -112,8 +112,6 @@ DOMWifiManager.prototype = {
this._onConnectionInfoUpdate = null;
this._onEnabled = null;
this._onDisabled = null;
this._mm.sendAsyncMessage("WifiManager:managerFinished");
},
_sendMessageForRequest: function(name, data, request) {

View File

@ -1385,7 +1385,7 @@ function WifiWorker() {
"WifiManager:associate", "WifiManager:forget",
"WifiManager:wps", "WifiManager:getState",
"WifiManager:setPowerSavingMode",
"WifiManager:managerFinished"];
"child-process-shutdown"];
messages.forEach((function(msgName) {
this._mm.addMessageListener(msgName, this);
@ -1996,15 +1996,10 @@ WifiWorker.prototype = {
_domManagers: [],
_fireEvent: function(message, data) {
// TODO (bug 791911): Managers don't correctly tell us when they're getting
// destroyed, so prune dead managers here.
this._domManagers = this._domManagers.filter(function(obj) {
try {
obj.manager.sendAsyncMessage("WifiManager:" + message, data);
return true;
} catch(e) {
return false;
}
this._domManagers.forEach(function(manager) {
// Note: We should never have a dead message manager here because we
// observe our child message managers shutting down, below.
manager.sendAsyncMessage("WifiManager:" + message, data);
});
},
@ -2014,12 +2009,24 @@ WifiWorker.prototype = {
},
receiveMessage: function MessageManager_receiveMessage(aMessage) {
if (!aMessage.target.assertPermission("wifi-manage")) {
let msg = aMessage.data || {};
msg.manager = aMessage.target;
// Note: By the time we receive child-process-shutdown, the child process
// has already forgotten its permissions so we do this before the
// permissions check.
if (aMessage.name === "child-process-shutdown") {
let i;
if ((i = this._domManagers.indexOf(msg.manager)) != -1) {
this._domManagers.splice(i, 1);
}
return;
}
let msg = aMessage.json || {};
msg.manager = aMessage.target;
if (!aMessage.target.assertPermission("wifi-manage")) {
return;
}
switch (aMessage.name) {
case "WifiManager:getNetworks":
@ -2041,39 +2048,18 @@ WifiWorker.prototype = {
this.setPowerSavingMode(msg);
break;
case "WifiManager:getState": {
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
let i;
for (i = 0; i < this._domManagers.length; ++i) {
let obj = this._domManagers[i];
if (obj.manager === msg.manager) {
obj.count++;
break;
}
}
if (i === this._domManagers.length) {
this._domManagers.push({ manager: msg.manager, count: 1 });
if ((i = this._domManagers.indexOf(msg.manager)) === -1) {
this._domManagers.push(msg.manager);
}
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
return { network: net,
connectionInfo: this._lastConnectionInfo,
enabled: WifiManager.enabled,
status: translateState(WifiManager.state),
macAddress: this.macAddress };
}
case "WifiManager:managerFinished": {
for (let i = 0; i < this._domManagers.length; ++i) {
let obj = this._domManagers[i];
if (obj.manager === msg.manager) {
if (--obj.count === 0) {
this._domManagers.splice(i, 1);
}
break;
}
}
break;
}
}
},