Bug 1315044 - Cache ContentActor forms to prevent creating new one when calling RootActor.getProcess multiple times. r=jryans

MozReview-Commit-ID: 3YyShRXQhel

--HG--
extra : rebase_source : 670ce6dc1b4c451bdb59dcebfa859d6089ed2624
This commit is contained in:
Alexandre Poirot 2016-11-04 08:05:15 -07:00
Родитель 4c7f0577fe
Коммит c1adf2fe24
3 изменённых файлов: 35 добавлений и 6 удалений

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

@ -103,6 +103,7 @@ function RootActor(aConnection, aParameters) {
this.conn.addActorPool(this._globalActorPool);
this._chromeActor = null;
this._processActors = new Map();
}
RootActor.prototype = {
@ -230,6 +231,7 @@ RootActor.prototype = {
this._globalActorPool = null;
this._parameters = null;
this._chromeActor = null;
this._processActors.clear();
},
/* The 'listTabs' request and the 'tabListChanged' notification. */
@ -471,13 +473,24 @@ RootActor.prototype = {
return { form: this._chromeActor.form() };
} else {
let mm = ppmm.getChildAt(aRequest.id);
let { id } = aRequest;
let mm = ppmm.getChildAt(id);
if (!mm) {
return { error: "noProcess",
message: "There is no process with id '" + aRequest.id + "'." };
message: "There is no process with id '" + id + "'." };
}
return DebuggerServer.connectToContent(this.conn, mm)
.then(form => ({ form }));
let form = this._processActors.get(id);
if (form) {
return { form };
}
let onDestroy = () => {
this._processActors.delete(id);
};
return DebuggerServer.connectToContent(this.conn, mm, onDestroy)
.then(form => {
this._processActors.set(id, form);
return { form };
});
}
},

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

@ -715,7 +715,7 @@ var DebuggerServer = {
return this._onConnection(transport, prefix, true);
},
connectToContent(connection, mm) {
connectToContent(connection, mm, onDestroy) {
let deferred = SyncPromise.defer();
let prefix = connection.allocID("content-process");
@ -764,6 +764,10 @@ var DebuggerServer = {
// Nothing to do
}
}
if (onDestroy) {
onDestroy(mm);
}
}
let onMessageManagerClose = DevToolsUtils.makeInfallible((subject, topic, data) => {

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

@ -97,12 +97,24 @@ function runTests() {
text: "var a = 42; a"
}, function (response) {
ok(response.result, 42, "console.eval worked");
cleanup();
getProcessAgain(actor, content.id);
});
});
});
}
// Assert that calling client.getProcess against the same process id is
// returning the same actor.
function getProcessAgain(firstActor, id) {
client.getProcess(id).then(response => {
let actor = response.form;
is(actor, firstActor,
"Second call to getProcess with the same id returns the same form");
cleanup();
});
}
function cleanup() {
client.close().then(function () {
DebuggerServer.destroy();