Bug 1492700 - Stop sending adb-addon updates from Devices.jsm;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 27 Nov 2018 12:49:11 +0000
changeset 507470 5199632a4ada777750accd0e0e2a0faa96b12d7e
parent 507469 f5f900b18101005db07d9b201dc15205c596c451
child 507471 7590eb03b4ff904b41bdc7f8a17a73eda4f06da7
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1492700
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 1492700 - Stop sending adb-addon updates from Devices.jsm;r=daisuke Depends on D12758 Differential Revision: https://phabricator.services.mozilla.com/D12759
devtools/client/webide/modules/runtime-list.js
devtools/client/webide/test/test_addons.html
devtools/shared/adb/adb-scanner.js
devtools/shared/apps/Devices.jsm
--- a/devtools/client/webide/modules/runtime-list.js
+++ b/devtools/client/webide/modules/runtime-list.js
@@ -3,17 +3,18 @@
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const Services = require("Services");
 const {AppManager} = require("devtools/client/webide/modules/app-manager");
 const EventEmitter = require("devtools/shared/event-emitter");
 const {RuntimeScanners, WiFiScanner} = require("devtools/client/webide/modules/runtimes");
-const {Devices} = require("resource://devtools/shared/apps/Devices.jsm");
+const { adbAddon, ADB_ADDON_STATES } = require("devtools/shared/adb/adb-addon");
+
 const Strings = Services.strings.createBundle("chrome://devtools/locale/webide.properties");
 
 var RuntimeList;
 
 module.exports = RuntimeList = function(window, parentWindow) {
   EventEmitter.decorate(this);
   this._doc = window.document;
   this._UI = parentWindow.UI;
@@ -136,29 +137,29 @@ RuntimeList.prototype = {
     const usbListNode = doc.querySelector("#runtime-panel-usb");
     const wifiListNode = doc.querySelector("#runtime-panel-wifi");
     const otherListNode = doc.querySelector("#runtime-panel-other");
     const noADBExtensionNode = doc.querySelector("#runtime-panel-noadbextension");
     const noUSBNode = doc.querySelector("#runtime-panel-nousbdevice");
     noADBExtensionNode.textContent =
       Strings.formatStringFromName("runtimePanel_noadbextension", ["ADB Extension"], 1);
 
-    if (Devices.adbExtensionInstalled) {
+    if (adbAddon.status === ADB_ADDON_STATES.INSTALLED) {
       noADBExtensionNode.setAttribute("hidden", "true");
     } else {
       noADBExtensionNode.removeAttribute("hidden");
     }
 
     const runtimeList = AppManager.runtimeList;
 
     if (!runtimeList) {
       return;
     }
 
-    if (runtimeList.usb.length === 0 && Devices.adbExtensionInstalled) {
+    if (runtimeList.usb.length === 0 && adbAddon.status === ADB_ADDON_STATES.INSTALLED) {
       noUSBNode.removeAttribute("hidden");
     } else {
       noUSBNode.setAttribute("hidden", "true");
     }
 
     for (const [type, parent] of [
       ["usb", usbListNode],
       ["wifi", wifiListNode],
--- a/devtools/client/webide/test/test_addons.html
+++ b/devtools/client/webide/test/test_addons.html
@@ -16,47 +16,50 @@
 
     <script type="application/javascript">
       // XXX Bug 1072167 - When updating after migration, fix the no-undef issues.
       /* eslint-disable no-undef */
 
       window.onload = function() {
         SimpleTest.waitForExplicitFinish();
 
-        const {Devices} = ChromeUtils.import("resource://devtools/shared/apps/Devices.jsm", {});
+        const { adbAddon, ADB_ADDON_STATES } = require("devtools/shared/adb/adb-addon");
+        function isAdbAddonInstalled() {
+          return adbAddon.status === ADB_ADDON_STATES.INSTALLED;
+        }
 
         function uninstallADBFromUI(doc) {
           return new Promise((resolve, reject) => {
-            Devices.on("addon-status-updated", function onUpdate() {
+            adbAddon.on("update", function onUpdate() {
               nextTick().then(() => {
                 const li = doc.querySelector('[status="uninstalled"][addon="adb"]');
                 if (li) {
-                  Devices.off("addon-status-updated", onUpdate);
+                  adbAddon.off("update", onUpdate);
                   resolve();
                 } else {
                   reject("Can't find item");
                 }
               });
             });
             const li = doc.querySelector('[status="installed"][addon="adb"]');
             li.querySelector(".uninstall-button").click();
           });
         }
 
         (async function() {
-          ok(!Devices.adbExtensionInstalled, "ADB extension not installed");
+          ok(!isAdbAddonInstalled(), "ADB extension not installed");
 
           const win = await openWebIDE(true);
 
           // ADB is installed asynchronously after starting WebIDE.
-          while (!Devices.adbExtensionInstalled) {
-            await Devices.once("addon-status-updated");
+          while (!isAdbAddonInstalled()) {
+            await adbAddon.once("update");
           }
 
-          ok(Devices.adbExtensionInstalled, "ADB extension has been auto-installed");
+          ok(isAdbAddonInstalled(), "ADB extension has been auto-installed");
 
           await nextTick();
 
           const addonDoc = getAddonsDocument(win);
           const w = addonDoc.querySelector(".warning");
           let display = addonDoc.defaultView.getComputedStyle(w).display;
           is(display, "none", "Warning about missing ADB hidden");
 
--- a/devtools/shared/adb/adb-scanner.js
+++ b/devtools/shared/adb/adb-scanner.js
@@ -23,30 +23,29 @@ class ADBScanner extends EventEmitter {
   }
 
   enable() {
     EventEmitter.on(ADB, "device-connected", this._onDeviceConnected);
     EventEmitter.on(ADB, "device-disconnected", this._onDeviceDisconnected);
 
     Devices.on("register", this._updateRuntimes);
     Devices.on("unregister", this._updateRuntimes);
-    Devices.on("addon-status-updated", this._updateRuntimes);
 
     ADB.start().then(() => {
       ADB.trackDevices();
     });
     this._updateRuntimes();
   }
 
   disable() {
     EventEmitter.off(ADB, "device-connected", this._onDeviceConnected);
     EventEmitter.off(ADB, "device-disconnected", this._onDeviceDisconnected);
     Devices.off("register", this._updateRuntimes);
     Devices.off("unregister", this._updateRuntimes);
-    Devices.off("addon-status-updated", this._updateRuntimes);
+    this._updateRuntimes();
   }
 
   _emitUpdated() {
     this.emit("runtime-list-updated");
   }
 
   _onDeviceConnected(deviceId) {
     const device = new Device(deviceId);
--- a/devtools/shared/apps/Devices.jsm
+++ b/devtools/shared/apps/Devices.jsm
@@ -7,34 +7,19 @@
 const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
 const EventEmitter = require("devtools/shared/event-emitter");
 const { adbAddon, ADB_ADDON_STATES } = require("devtools/shared/adb/adb-addon");
 
 /* exported EXPORTED_SYMBOLS */
 
 const EXPORTED_SYMBOLS = ["Devices"];
 
-var addonInstalled = adbAddon.status === ADB_ADDON_STATES.INSTALLED;
-
 const Devices = {
   _devices: {},
 
-  get adbExtensionInstalled() {
-    return addonInstalled;
-  },
-  set adbExtensionInstalled(v) {
-    addonInstalled = v;
-    if (!addonInstalled) {
-      for (const name in this._devices) {
-        this.unregister(name);
-      }
-    }
-    this.emit("addon-status-updated", v);
-  },
-
   register: function(name, device) {
     this._devices[name] = device;
     this.emit("register");
   },
 
   unregister: function(name) {
     delete this._devices[name];
     this.emit("unregister");
@@ -44,17 +29,22 @@ const Devices = {
     return Object.keys(this._devices).sort();
   },
 
   getByName: function(name) {
     return this._devices[name];
   },
 
   updateAdbAddonStatus: function() {
-    this.adbExtensionInstalled = adbAddon.status === ADB_ADDON_STATES.INSTALLED;
+    const installed = adbAddon.status === ADB_ADDON_STATES.INSTALLED;
+    if (!installed) {
+      for (const name in this._devices) {
+        this.unregister(name);
+      }
+    }
   },
 };
 
 Object.defineProperty(this, "Devices", {
   value: Devices,
   enumerable: true,
   writable: false,
 });