Bug 1497917 - Extract client creation to RuntimeHelper module;r=ladybenko,daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 09 Nov 2018 09:40:41 +0000
changeset 445398 dfd527956c4b0df389286e62b51f28e87b64676d
parent 445397 0620a6320abfcb9177f601c40af8d89a0dc89b0d
child 445399 1543fc07760a82e005b5e177be10af931d223403
push id35015
push userdluca@mozilla.com
push dateFri, 09 Nov 2018 17:45:20 +0000
treeherdermozilla-central@2f1158e5e0ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersladybenko, daisuke
bugs1497917
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1497917 - Extract client creation to RuntimeHelper module;r=ladybenko,daisuke Depends on D10095 The initial intent was to extract the logic to create the USB clients so that it could be mocked in our tests. However since USB clients share most of their logic with network clients, it did not make sense to extract USB without network. And once you have USB and network, there is no good reason to keep local client out. I don't think "runtime-helper.js" is a good module name here. The role of this module is to build clients for runtimes, but at the same time it is just a static helper. Could not find a good name, and we already have inconsistent module names in our modules/ folder so I did not want to introduce something like RuntimeClientBuilder of RuntimeClientProvider etc... One of the consequences is that once we start mocking this helper (in the next patch) we will also have to mock the this-firefox runtime. It has advantages and disadvantages but I think we can live with this for now. Differential Revision: https://phabricator.services.mozilla.com/D10096
devtools/client/aboutdebugging-new/src/actions/runtimes.js
devtools/client/aboutdebugging-new/src/modules/moz.build
devtools/client/aboutdebugging-new/src/modules/runtime-client-factory.js
--- a/devtools/client/aboutdebugging-new/src/actions/runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/actions/runtimes.js
@@ -1,26 +1,26 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const { ADB } = require("devtools/shared/adb/adb");
-const { DebuggerClient } = require("devtools/shared/client/debugger-client");
 const { DebuggerServer } = require("devtools/server/main");
 
 const Actions = require("./index");
 
 const {
   getCurrentRuntime,
   findRuntimeById,
 } = require("../modules/runtimes-state-helper");
 const { isSupportedDebugTarget } = require("../modules/debug-target-support");
 
+const { createClientForRuntime } = require("../modules/runtime-client-factory");
+
 const {
   CONNECT_RUNTIME_FAILURE,
   CONNECT_RUNTIME_START,
   CONNECT_RUNTIME_SUCCESS,
   DEBUG_TARGETS,
   DISCONNECT_RUNTIME_FAILURE,
   DISCONNECT_RUNTIME_START,
   DISCONNECT_RUNTIME_SUCCESS,
@@ -33,53 +33,16 @@ const {
   UPDATE_CONNECTION_PROMPT_SETTING_START,
   UPDATE_CONNECTION_PROMPT_SETTING_SUCCESS,
   USB_RUNTIMES_UPDATED,
   WATCH_RUNTIME_FAILURE,
   WATCH_RUNTIME_START,
   WATCH_RUNTIME_SUCCESS,
 } = require("../constants");
 
-async function createLocalClient() {
-  DebuggerServer.init();
-  DebuggerServer.registerAllActors();
-  const client = new DebuggerClient(DebuggerServer.connectPipe());
-  await client.connect();
-  return { client };
-}
-
-async function createNetworkClient(host, port) {
-  const transportDetails = { host, port };
-  const transport = await DebuggerClient.socketConnect(transportDetails);
-  const client = new DebuggerClient(transport);
-  await client.connect();
-  return { client, transportDetails };
-}
-
-async function createUSBClient(socketPath) {
-  const port = await ADB.prepareTCPConnection(socketPath);
-  return createNetworkClient("localhost", port);
-}
-
-async function createClientForRuntime(runtime) {
-  const { extra, type } = runtime;
-
-  if (type === RUNTIMES.THIS_FIREFOX) {
-    return createLocalClient();
-  } else if (type === RUNTIMES.NETWORK) {
-    const { host, port } = extra.connectionParameters;
-    return createNetworkClient(host, port);
-  } else if (type === RUNTIMES.USB) {
-    const { socketPath } = extra.connectionParameters;
-    return createUSBClient(socketPath);
-  }
-
-  return null;
-}
-
 async function getRuntimeInfo(runtime, client) {
   const { extra, type } = runtime;
   const { name, channel, version } = await client.getDeviceDescription();
   const icon =
     (channel === "release" || channel === "beta" || channel === "aurora")
       ? `chrome://devtools/skin/images/aboutdebugging-firefox-${ channel }.svg`
       : "chrome://devtools/skin/images/aboutdebugging-firefox-nightly.svg";
 
--- a/devtools/client/aboutdebugging-new/src/modules/moz.build
+++ b/devtools/client/aboutdebugging-new/src/modules/moz.build
@@ -4,12 +4,13 @@
 
 DevToolsModules(
     'client-wrapper.js',
     'debug-target-collapsibilities.js',
     'debug-target-support.js',
     'extensions-helper.js',
     'l10n.js',
     'network-locations.js',
+    'runtime-client-factory.js',
     'runtimes-state-helper.js',
     'test-helper.js',
     'usb-runtimes.js',
 )
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/src/modules/runtime-client-factory.js
@@ -0,0 +1,51 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { ADB } = require("devtools/shared/adb/adb");
+const { DebuggerClient } = require("devtools/shared/client/debugger-client");
+const { DebuggerServer } = require("devtools/server/main");
+const { ClientWrapper } = require("./client-wrapper");
+
+const { RUNTIMES } = require("../constants");
+
+async function createLocalClient() {
+  DebuggerServer.init();
+  DebuggerServer.registerAllActors();
+  const client = new DebuggerClient(DebuggerServer.connectPipe());
+  await client.connect();
+  return { client: new ClientWrapper(client) };
+}
+
+async function createNetworkClient(host, port) {
+  const transportDetails = { host, port };
+  const transport = await DebuggerClient.socketConnect(transportDetails);
+  const client = new DebuggerClient(transport);
+  await client.connect();
+  return { client: new ClientWrapper(client), transportDetails };
+}
+
+async function createUSBClient(socketPath) {
+  const port = await ADB.prepareTCPConnection(socketPath);
+  return createNetworkClient("localhost", port);
+}
+
+async function createClientForRuntime(runtime) {
+  const { extra, type } = runtime;
+
+  if (type === RUNTIMES.THIS_FIREFOX) {
+    return createLocalClient();
+  } else if (type === RUNTIMES.NETWORK) {
+    const { host, port } = extra.connectionParameters;
+    return createNetworkClient(host, port);
+  } else if (type === RUNTIMES.USB) {
+    const { socketPath } = extra.connectionParameters;
+    return createUSBClient(socketPath);
+  }
+
+  return null;
+}
+
+exports.createClientForRuntime = createClientForRuntime;