Bug 1488375 - Use target.getFront to instantiate MemoryFront; r=ochameau
☠☠ backed out by e9e765c5d7f7 ☠ ☠
authoryulia <ystartsev@mozilla.com>
Fri, 12 Oct 2018 13:38:21 +0000
changeset 496615 94ccc53c61a75edd4c218d70ab37b69e25b452df
parent 496614 5b5ed02f86c785f0b78999f8ca94baf057eaf799
child 496616 2fe9ae64504697968b89d5ec4ef0d027a0dc46fa
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1488375
milestone64.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 1488375 - Use target.getFront to instantiate MemoryFront; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D7097
devtools/client/memory/panel.js
devtools/server/tests/mochitest/memory-helpers.js
devtools/shared/fronts/memory.js
--- a/devtools/client/memory/panel.js
+++ b/devtools/client/memory/panel.js
@@ -1,16 +1,15 @@
 /* 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 EventEmitter = require("devtools/shared/event-emitter");
-const { MemoryFront } = require("devtools/shared/fronts/memory");
 const { Cu } = require("chrome");
 const HeapAnalysesClient = require("devtools/shared/heapsnapshot/HeapAnalysesClient");
 
 function MemoryPanel(iframeWindow, toolbox) {
   this.panelWin = iframeWindow;
   this._toolbox = toolbox;
 
   const { BrowserLoader } = Cu.import("resource://devtools/client/shared/browser-loader.js", {});
@@ -26,21 +25,17 @@ function MemoryPanel(iframeWindow, toolb
 MemoryPanel.prototype = {
   async open() {
     if (this._opening) {
       return this._opening;
     }
 
     this.panelWin.gToolbox = this._toolbox;
     this.panelWin.gTarget = this.target;
-
-    const rootForm = await this.target.root;
-    this.panelWin.gFront = new MemoryFront(this.target.client,
-                                           this.target.form,
-                                           rootForm);
+    this.panelWin.gFront = this.target.getFront("memory");
     this.panelWin.gHeapAnalysesClient = new HeapAnalysesClient();
 
     await this.panelWin.gFront.attach();
 
     this._opening = this.initializer.initialize().then(() => {
       this.isReady = true;
       this.emit("ready");
       return this;
--- a/devtools/server/tests/mochitest/memory-helpers.js
+++ b/devtools/server/tests/mochitest/memory-helpers.js
@@ -1,41 +1,37 @@
 /* exported Task, startServerAndGetSelectedTabMemory, destroyServerAndFinish,
    waitForTime, waitUntil */
 "use strict";
 
 const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
 const Services = require("Services");
-const { DebuggerClient } = require("devtools/shared/client/debugger-client");
 const { DebuggerServer } = require("devtools/server/main");
-
-const { MemoryFront } = require("devtools/shared/fronts/memory");
+const { TargetFactory } = require("devtools/client/framework/target");
 
 // Always log packets when running tests.
 Services.prefs.setBoolPref("devtools.debugger.log", true);
 var gReduceTimePrecision = Services.prefs.getBoolPref("privacy.reduceTimerPrecision");
 Services.prefs.setBoolPref("privacy.reduceTimerPrecision", false);
 SimpleTest.registerCleanupFunction(function() {
   Services.prefs.clearUserPref("devtools.debugger.log");
   Services.prefs.setBoolPref("privacy.reduceTimerPrecision", gReduceTimePrecision);
 });
 
-function startServerAndGetSelectedTabMemory() {
-  DebuggerServer.init();
-  DebuggerServer.registerAllActors();
-  const client = new DebuggerClient(DebuggerServer.connectPipe());
+async function getTargetForSelectedTab() {
+  const browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
+  const target = await TargetFactory.forTab(browserWindow.gBrowser.selectedTab);
+  return target;
+}
 
-  return client.connect()
-    .then(() => client.listTabs())
-    .then(response => {
-      const form = response.tabs[response.selected];
-      const memory = MemoryFront(client, form, response);
-
-      return { memory, client };
-    });
+async function startServerAndGetSelectedTabMemory() {
+  const target = await getTargetForSelectedTab();
+  const memory = target.getFront("memory");
+  const client = target.client;
+  return {memory, client};
 }
 
 function destroyServerAndFinish(client) {
   client.close().then(() => {
     DebuggerServer.destroy();
     SimpleTest.finish();
   });
 }
--- a/devtools/shared/fronts/memory.js
+++ b/devtools/shared/fronts/memory.js
@@ -7,23 +7,21 @@ const { memorySpec } = require("devtools
 const protocol = require("devtools/shared/protocol");
 
 loader.lazyRequireGetter(this, "FileUtils",
                          "resource://gre/modules/FileUtils.jsm", true);
 loader.lazyRequireGetter(this, "HeapSnapshotFileUtils",
                          "devtools/shared/heapsnapshot/HeapSnapshotFileUtils");
 
 const MemoryFront = protocol.FrontClassWithSpec(memorySpec, {
-  initialize: function(client, form, rootForm = null) {
+  initialize: function(client, form) {
     protocol.Front.prototype.initialize.call(this, client, form);
     this._client = client;
     this.actorID = form.memoryActor;
-    this.heapSnapshotFileActorID = rootForm
-      ? rootForm.heapSnapshotFileActor
-      : null;
+    this.heapSnapshotFileActorID = null;
     this.manage(this);
   },
 
   /**
    * Save a heap snapshot, transfer it from the server to the client if the
    * server and client do not share a file system, and return the local file
    * path to the heap snapshot.
    *
@@ -57,19 +55,20 @@ const MemoryFront = protocol.FrontClassW
    * Given that we have taken a heap snapshot with the given id, transfer the
    * heap snapshot file to the client. The path to the client's local file is
    * returned.
    *
    * @param {String} snapshotId
    *
    * @returns Promise<String>
    */
-  transferHeapSnapshot: protocol.custom(function(snapshotId) {
+  transferHeapSnapshot: protocol.custom(async function(snapshotId) {
     if (!this.heapSnapshotFileActorID) {
-      throw new Error("MemoryFront initialized without a rootForm");
+      const form = await this._client.mainRoot.rootForm;
+      this.heapSnapshotFileActorID = form.heapSnapshotFileActor;
     }
 
     const request = this._client.request({
       to: this.heapSnapshotFileActorID,
       type: "transferHeapSnapshot",
       snapshotId
     });