Bug 1473513 - refactor main.js to use protocol.js pools; r=ochameau draft
authoryulia <ystartsev@mozilla.com>
Thu, 09 Aug 2018 11:45:00 +0200
changeset 830721 5c4005041d8b65cd4e7f08e4edd8b2c57e7642c8
parent 830720 5988ed48f4d4cfc077c7bc768a546698f3e5d541
child 830722 358847f12aa241dd6048d418f14538dbbef43983
push id118849
push userbmo:ystartsev@mozilla.com
push dateWed, 22 Aug 2018 10:34:16 +0000
reviewersochameau
bugs1473513
milestone63.0a1
Bug 1473513 - refactor main.js to use protocol.js pools; r=ochameau MozReview-Commit-ID: FNMK4f553yI
devtools/client/debugger/test/mochitest/browser_dbg_globalactor.js
devtools/server/main.js
devtools/server/tests/unit/test_protocol_children.js
--- 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>"});