Bug 793361 - Apps, SystemMessages: free message manager references for killed children. r=fabrice

This commit is contained in:
Gregor Wagner
2012-10-01 13:29:59 -07:00
parent 448361ae9c
commit 0b4a36cbbb
6 changed files with 36 additions and 76 deletions

View File

@@ -187,8 +187,6 @@ WebappsRegistry.prototype = {
uninit: function() { uninit: function() {
this._mgmt = null; this._mgmt = null;
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
["Webapps:Install:Return:OK"]);
}, },
// mozIDOMApplicationRegistry2 implementation // mozIDOMApplicationRegistry2 implementation
@@ -484,9 +482,6 @@ WebappsApplication.prototype = {
uninit: function() { uninit: function() {
this._onprogress = null; this._onprogress = null;
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
["Webapps:Uninstall:Return:OK", "Webapps:OfflineCache",
"Webapps:PackageEvent"]);
}, },
_fireEvent: function(aName, aHandler) { _fireEvent: function(aName, aHandler) {
@@ -649,8 +644,6 @@ WebappsApplicationMgmt.prototype = {
uninit: function() { uninit: function() {
this._oninstall = null; this._oninstall = null;
this._onuninstall = null; this._onuninstall = null;
cpmm.sendAsyncMessage("Webapps:UnregisterForMessages",
["Webapps:Install:Return:OK", "Webapps:Uninstall:Return:OK"]);
}, },
applyDownload: function(aApp) { applyDownload: function(aApp) {

View File

@@ -159,9 +159,9 @@ let DOMApplicationRegistry = {
"Webapps:Launch", "Webapps:GetAll", "Webapps:Launch", "Webapps:GetAll",
"Webapps:InstallPackage", "Webapps:GetBasePath", "Webapps:InstallPackage", "Webapps:GetBasePath",
"Webapps:GetList", "Webapps:RegisterForMessages", "Webapps:GetList", "Webapps:RegisterForMessages",
"Webapps:UnregisterForMessages",
"Webapps:CancelDownload", "Webapps:CheckForUpdate", "Webapps:CancelDownload", "Webapps:CheckForUpdate",
"Webapps::Download", "Webapps::ApplyDownload"]; "Webapps::Download", "Webapps::ApplyDownload",
"child-process-shutdown"];
this.frameMessages = ["Webapps:ClearBrowserData"]; this.frameMessages = ["Webapps:ClearBrowserData"];
@@ -512,17 +512,17 @@ let DOMApplicationRegistry = {
}, this); }, this);
}, },
removeMessageListener: function(aMsgNames, aMm) {
aMsgNames.forEach(function (aMsgName) { removeMessageListener: function(aMm) {
if (!(aMsgName in this.children)) { for (let i = this.children.length - 1; i >= 0; i -= 1) {
return; msg = this.children[i];
}
let index; let index;
if ((index = this.children[aMsgName].indexOf(aMm)) != -1) { if ((index = msg.indexOf(aMm)) != -1) {
this.children[aMsgName].splice(index, 1); debug("Remove dead mm at index " + index);
msg.splice(index, 1);
} }
}, this); };
}, },
receiveMessage: function(aMessage) { receiveMessage: function(aMessage) {
@@ -542,7 +542,7 @@ let DOMApplicationRegistry = {
} }
} }
let msg = aMessage.json; let msg = aMessage.data || {};
let mm = aMessage.target; let mm = aMessage.target;
msg.mm = mm; msg.mm = mm;
@@ -585,9 +585,6 @@ let DOMApplicationRegistry = {
case "Webapps:RegisterForMessages": case "Webapps:RegisterForMessages":
this.addMessageListener(msg, mm); this.addMessageListener(msg, mm);
break; break;
case "Webapps:UnregisterForMessages":
this.removeMessageListener(msg, mm);
break;
case "Webapps:GetList": case "Webapps:GetList":
this.addMessageListener(["Webapps:AddApp", "Webapps:RemoveApp"], mm); this.addMessageListener(["Webapps:AddApp", "Webapps:RemoveApp"], mm);
return this.webapps; return this.webapps;
@@ -610,6 +607,9 @@ let DOMApplicationRegistry = {
this.onInitDone(); this.onInitDone();
} }
break; break;
case "child-process-shutdown":
this.removeMessageListener(mm);
break;
} }
}, },

View File

@@ -27,7 +27,7 @@ try {
const kMessages =["SystemMessageManager:GetPending", const kMessages =["SystemMessageManager:GetPending",
"SystemMessageManager:Register", "SystemMessageManager:Register",
"SystemMessageManager:Unregister"] "child-process-shutdown"]
function debug(aMsg) { function debug(aMsg) {
//dump("-- SystemMessageInternal " + Date.now() + " : " + aMsg + "\n"); //dump("-- SystemMessageInternal " + Date.now() + " : " + aMsg + "\n");
@@ -50,24 +50,12 @@ SystemMessageInternal.prototype = {
sendMessage: function sendMessage(aType, aMessage, aPageURI, aManifestURI) { sendMessage: function sendMessage(aType, aMessage, aPageURI, aManifestURI) {
debug("Broadcasting " + aType + " " + JSON.stringify(aMessage)); debug("Broadcasting " + aType + " " + JSON.stringify(aMessage));
if (this._listeners[aManifestURI.spec]) { if (this._listeners[aManifestURI.spec]) {
let i; this._listeners[aManifestURI.spec].forEach(function sendMsg(aListener) {
let listener; aListener.sendAsyncMessage("SystemMessageManager:Message",
for (i = this._listeners[aManifestURI.spec].length - 1; i >= 0; i -= 1) {
listener = this._listeners[aManifestURI.spec][i];
try {
listener.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType, { type: aType,
msg: aMessage, msg: aMessage,
manifest: aManifestURI.spec }) manifest: aManifestURI.spec })
} catch (e) { });
// Remove once 777508 lands.
let index;
if ((index = this._listeners[aManifestURI.spec].indexOf(listener)) != -1) {
this._listeners[aManifestURI.spec].splice(index, 1);
dump("Remove dead MessageManager!\n");
}
}
};
} }
this._pages.forEach(function sendMess_openPage(aPage) { this._pages.forEach(function sendMess_openPage(aPage) {
@@ -87,23 +75,12 @@ SystemMessageInternal.prototype = {
this._pages.forEach(function(aPage) { this._pages.forEach(function(aPage) {
if (aPage.type == aType) { if (aPage.type == aType) {
if (this._listeners[aPage.manifest]) { if (this._listeners[aPage.manifest]) {
let i; this._listeners[aPage.manifest].forEach(function sendMsg(aListener) {
for (i = this._listeners[aPage.manifest].length - 1; i >= 0; i -= 1) { aListener.sendAsyncMessage("SystemMessageManager:Message",
let listener = this._listeners[aPage.manifest][i];
try {
listener.sendAsyncMessage("SystemMessageManager:Message",
{ type: aType, { type: aType,
msg: aMessage, msg: aMessage,
manifest: aPage.manifest}) manifest: aPage.manifest})
} catch (e) { });
// Remove once 777508 lands.
let index;
if ((index = this._listeners[aPage.manifest].indexOf(listener)) != -1) {
this._listeners[aPage.manifest].splice(index, 1);
dump("Remove dead MessageManager!\n");
}
}
};
} }
this._processPage(aPage, aMessage); this._processPage(aPage, aMessage);
} }
@@ -133,7 +110,7 @@ SystemMessageInternal.prototype = {
this._listeners[manifest].push(aMessage.target); this._listeners[manifest].push(aMessage.target);
debug("listeners for " + manifest + " : " + this._listeners[manifest].length); debug("listeners for " + manifest + " : " + this._listeners[manifest].length);
break; break;
case "SystemMessageManager:Unregister": case "child-process-shutdown":
debug("Got Unregister from " + aMessage.target); debug("Got Unregister from " + aMessage.target);
let mm = aMessage.target; let mm = aMessage.target;
for (let manifest in this._listeners) { for (let manifest in this._listeners) {

View File

@@ -143,7 +143,6 @@ SystemMessageManager.prototype = {
}, },
uninit: function sysMessMgr_uninit() { uninit: function sysMessMgr_uninit() {
cpmm.sendAsyncMessage("SystemMessageManager:Unregister", { });
this._handlers = null; this._handlers = null;
this._pendings = null; this._pendings = null;
}, },

View File

@@ -29,7 +29,7 @@ let SettingsChangeNotifier = {
init: function() { init: function() {
debug("init"); debug("init");
this.children = []; this.children = [];
this._messages = ["Settings:Changed", "Settings:RegisterForMessages", "Settings:UnregisterForMessages"]; this._messages = ["Settings:Changed", "Settings:RegisterForMessages", "child-process-shutdown"];
this._messages.forEach((function(msgName) { this._messages.forEach((function(msgName) {
ppmm.addMessageListener(msgName, this); ppmm.addMessageListener(msgName, this);
}).bind(this)); }).bind(this));
@@ -68,24 +68,15 @@ let SettingsChangeNotifier = {
}, },
broadcastMessage: function broadcastMessage(aMsgName, aContent) { broadcastMessage: function broadcastMessage(aMsgName, aContent) {
let i; debug("Broadast");
for (i = this.children.length - 1; i >= 0; i -= 1) { this.children.forEach(function(msgMgr) {
let msgMgr = this.children[i];
try {
msgMgr.sendAsyncMessage(aMsgName, aContent); msgMgr.sendAsyncMessage(aMsgName, aContent);
} catch (e) { });
let index;
if ((index = this.children.indexOf(msgMgr)) != -1) {
this.children.splice(index, 1);
dump("Remove dead MessageManager!\n");
}
}
};
}, },
receiveMessage: function(aMessage) { receiveMessage: function(aMessage) {
debug("receiveMessage"); debug("receiveMessage");
let msg = aMessage.json; let msg = aMessage.data;
let mm = aMessage.target; let mm = aMessage.target;
switch (aMessage.name) { switch (aMessage.name) {
case "Settings:Changed": case "Settings:Changed":
@@ -104,10 +95,11 @@ let SettingsChangeNotifier = {
this.children.push(mm); this.children.push(mm);
} }
break; break;
case "Settings:UnregisterForMessages": case "child-process-shutdown":
debug("Unregister"); debug("Unregister");
let index; let index;
if ((index = this.children.indexOf(mm)) != -1) { if ((index = this.children.indexOf(mm)) != -1) {
debug("Unregister index: " + index);
this.children.splice(index, 1); this.children.splice(index, 1);
} }
break; break;

View File

@@ -342,7 +342,6 @@ SettingsManager.prototype = {
observe: function(aSubject, aTopic, aData) { observe: function(aSubject, aTopic, aData) {
debug("Topic: " + aTopic); debug("Topic: " + aTopic);
if (aTopic == "inner-window-destroyed") { if (aTopic == "inner-window-destroyed") {
cpmm.sendAsyncMessage("Settings:UnregisterForMessages");
let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data; let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
if (wId == this.innerWindowID) { if (wId == this.innerWindowID) {
Services.obs.removeObserver(this, "inner-window-destroyed"); Services.obs.removeObserver(this, "inner-window-destroyed");