зеркало из https://github.com/mozilla/gecko-dev.git
Bug 933360. Change GlobalPCList._list from an array to an object, and rewrite some teardown code r=jib
This commit is contained in:
Родитель
c15091f395
Коммит
07393b8d26
|
@ -26,7 +26,7 @@ const PC_STATS_CID = Components.ID("{7fe6e18b-0da3-4056-bf3b-440ef3809e06}");
|
||||||
// Global list of PeerConnection objects, so they can be cleaned up when
|
// Global list of PeerConnection objects, so they can be cleaned up when
|
||||||
// a page is torn down. (Maps inner window ID to an array of PC objects).
|
// a page is torn down. (Maps inner window ID to an array of PC objects).
|
||||||
function GlobalPCList() {
|
function GlobalPCList() {
|
||||||
this._list = [];
|
this._list = {};
|
||||||
this._networkdown = false; // XXX Need to query current state somehow
|
this._networkdown = false; // XXX Need to query current state somehow
|
||||||
Services.obs.addObserver(this, "inner-window-destroyed", true);
|
Services.obs.addObserver(this, "inner-window-destroyed", true);
|
||||||
Services.obs.addObserver(this, "profile-change-net-teardown", true);
|
Services.obs.addObserver(this, "profile-change-net-teardown", true);
|
||||||
|
@ -58,7 +58,7 @@ GlobalPCList.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
removeNullRefs: function(winID) {
|
removeNullRefs: function(winID) {
|
||||||
if (this._list === undefined || this._list[winID] === undefined) {
|
if (this._list[winID] === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._list[winID] = this._list[winID].filter(
|
this._list[winID] = this._list[winID].filter(
|
||||||
|
@ -71,19 +71,24 @@ GlobalPCList.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
observe: function(subject, topic, data) {
|
observe: function(subject, topic, data) {
|
||||||
if (topic == "inner-window-destroyed") {
|
let cleanupPcRef = function(pcref) {
|
||||||
let winID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
let pc = pcref.get();
|
||||||
if (this._list[winID]) {
|
if (pc) {
|
||||||
this._list[winID].forEach(function(pcref) {
|
pc._pc.close();
|
||||||
let pc = pcref.get();
|
delete pc._observer;
|
||||||
if (pc !== null) {
|
pc._pc = null;
|
||||||
pc._pc.close();
|
|
||||||
delete pc._observer;
|
|
||||||
pc._pc = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
delete this._list[winID];
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let cleanupWinId = function(list, winID) {
|
||||||
|
if (list.hasOwnProperty(winID)) {
|
||||||
|
list[winID].forEach(cleanupPcRef);
|
||||||
|
delete list[winID];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (topic == "inner-window-destroyed") {
|
||||||
|
cleanupWinId(this._list, subject.QueryInterface(Ci.nsISupportsPRUint64).data);
|
||||||
} else if (topic == "profile-change-net-teardown" ||
|
} else if (topic == "profile-change-net-teardown" ||
|
||||||
topic == "network:offline-about-to-go-offline") {
|
topic == "network:offline-about-to-go-offline") {
|
||||||
// Delete all peerconnections on shutdown - mostly synchronously (we
|
// Delete all peerconnections on shutdown - mostly synchronously (we
|
||||||
|
@ -92,17 +97,9 @@ GlobalPCList.prototype = {
|
||||||
// before we return to here.
|
// before we return to here.
|
||||||
// Also kill them if "Work Offline" is selected - more can be created
|
// Also kill them if "Work Offline" is selected - more can be created
|
||||||
// while offline, but attempts to connect them should fail.
|
// while offline, but attempts to connect them should fail.
|
||||||
let array;
|
for (let winId in this._list) {
|
||||||
while ((array = this._list.pop()) != undefined) {
|
cleanupWinId(this._list, winId);
|
||||||
array.forEach(function(pcref) {
|
}
|
||||||
let pc = pcref.get();
|
|
||||||
if (pc !== null) {
|
|
||||||
pc._pc.close();
|
|
||||||
delete pc._observer;
|
|
||||||
pc._pc = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
this._networkdown = true;
|
this._networkdown = true;
|
||||||
}
|
}
|
||||||
else if (topic == "network:offline-status-changed") {
|
else if (topic == "network:offline-status-changed") {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче