Bug 1473513 - refactor main.js to use protocol.js pools; r=ochameau
MozReview-Commit-ID: FNMK4f553yI
--- a/devtools/client/debugger/test/mochitest/browser_dbg_globalactor.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg_globalactor.js
@@ -39,19 +39,21 @@ add_task(async function() {
is(response.pong, "pong", "Actor should respond to requests.");
// Make sure that lazily-created actors are created only once.
let count = 0;
for (const connID of Object.getOwnPropertyNames(DebuggerServer._connections)) {
const conn = DebuggerServer._connections[connID];
const actorPrefix = conn._prefix + "testOne";
for (let pool of conn._extraPools) {
- count += Object.keys(pool._actors).filter(e => {
- return e.startsWith(actorPrefix);
- }).length;
+ for (const actor of pool.poolChildren()) {
+ if (actor.actorID.startsWith(actorPrefix)) {
+ count++;
+ }
+ }
}
}
is(count, 1,
"Only one actor exists in all pools. One global actor.");
await client.close();
});
--- a/devtools/server/main.js
+++ b/devtools/server/main.js
@@ -5,17 +5,17 @@
"use strict";
/**
* Toolkit glue for the remote debugging protocol, loaded into the
* debugging global.
*/
var { Ci, Cc } = require("chrome");
var Services = require("Services");
-var { ActorPool } = require("devtools/server/actors/common");
+var { Pool } = require("devtools/shared/protocol");
var { ActorRegistry } = require("devtools/server/actor-registry");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { dumpn } = DevToolsUtils;
loader.lazyRequireGetter(this, "DebuggerSocket", "devtools/shared/security/socket", true);
loader.lazyRequireGetter(this, "Authentication", "devtools/shared/security/auth");
loader.lazyRequireGetter(this, "LocalDebuggerTransport", "devtools/shared/transport/local-transport", true);
loader.lazyRequireGetter(this, "ChildDebuggerTransport", "devtools/shared/transport/child-transport", true);
@@ -966,17 +966,17 @@ exports.DebuggerServer = DebuggerServer;
* Packet transport for the debugging protocol.
*/
function DebuggerServerConnection(prefix, transport) {
this._prefix = prefix;
this._transport = transport;
this._transport.hooks = this;
this._nextID = 1;
- this._actorPool = new ActorPool(this);
+ this._actorPool = new Pool(this);
this._extraPools = [this._actorPool];
// Responses to a given actor must be returned the the client
// in the same order as the requests that they're replying to, but
// Implementations might finish serving requests in a different
// order. To keep things in order we generate a promise for each
// request, chained to the promise for the request before it.
// This map stores the latest request promise in the chain, keyed
@@ -1078,24 +1078,24 @@ DebuggerServerConnection.prototype = {
}
}
},
/**
* Add an actor to the default actor pool for this connection.
*/
addActor(actor) {
- this._actorPool.addActor(actor);
+ this._actorPool.manage(actor);
},
/**
* Remove an actor to the default actor pool for this connection.
*/
removeActor(actor) {
- this._actorPool.removeActor(actor);
+ this._actorPool.unmanage(actor);
},
/**
* Match the api expected by the protocol library.
*/
unmanage(actor) {
return this.removeActor(actor);
},
--- a/devtools/server/tests/unit/test_protocol_children.js
+++ b/devtools/server/tests/unit/test_protocol_children.js
@@ -243,18 +243,16 @@ var RootActor = protocol.ActorClassWithS
return "[root actor]";
},
initialize: function(conn) {
rootActor = this;
this.actorID = "root";
this._children = {};
protocol.Actor.prototype.initialize.call(this, conn);
- // Root actor owns itself.
- this.manage(this);
},
sayHello: simpleHello,
getChild: function(id) {
if (id in this._children) {
return this._children[id];
}
@@ -349,17 +347,17 @@ function run_test() {
"applicationType": "xpcshell-tests",
"traits": []});
Assert.equal(applicationType, "xpcshell-tests");
const rootFront = RootFront(client);
let childFront = null;
const expectRootChildren = size => {
- Assert.equal(rootActor._poolMap.size, size + 1);
+ Assert.equal(rootActor._poolMap.size, size);
Assert.equal(rootFront._poolMap.size, size + 1);
if (childFront) {
Assert.equal(childFront._poolMap.size, 0);
}
};
rootFront.getChild("child1").then(ret => {
trace.expectSend({"type": "getChild", "str": "child1", "to": "<actorid>"});