From d5de9a0d886caa6ecf8f29861663cd49f7ef2b24 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 3 Sep 2020 13:55:49 +0100 Subject: [PATCH] [globals] self.SDK.isolateManager R=aerotwist@chromium.org Bug: 1058320 Change-Id: Id455a3c9e5c9a9f220f7a933279196dc5e66f2cb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2391250 Auto-Submit: Tim van der Lippe Commit-Queue: Jack Franklin Reviewed-by: Jack Franklin --- front_end/profiler/IsolateSelector.js | 12 +++++++----- front_end/profiler/LiveHeapProfileView.js | 2 +- front_end/sdk/IsolateManager.js | 20 +++++++++++++++----- front_end/sdk/sdk-legacy.js | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/front_end/profiler/IsolateSelector.js b/front_end/profiler/IsolateSelector.js index ed6f7cb64c..7e718cce2e 100644 --- a/front_end/profiler/IsolateSelector.js +++ b/front_end/profiler/IsolateSelector.js @@ -39,7 +39,7 @@ export class IsolateSelector extends UI.Widget.VBox { this._totalTrendDiv.title = ls`Total page JS heap size change trend over the last ${trendIntervalMinutes} minutes.`; this._totalValueDiv.title = ls`Total page JS heap size across all VM instances.`; - self.SDK.isolateManager.observeIsolates(this); + SDK.IsolateManager.IsolateManager.instance().observeIsolates(this); SDK.SDKModel.TargetManager.instance().addEventListener(SDK.SDKModel.Events.NameChanged, this._targetChanged, this); SDK.SDKModel.TargetManager.instance().addEventListener( SDK.SDKModel.Events.InspectedURLChanged, this._targetChanged, this); @@ -49,14 +49,16 @@ export class IsolateSelector extends UI.Widget.VBox { * @override */ wasShown() { - self.SDK.isolateManager.addEventListener(SDK.IsolateManager.Events.MemoryChanged, this._heapStatsChanged, this); + SDK.IsolateManager.IsolateManager.instance().addEventListener( + SDK.IsolateManager.Events.MemoryChanged, this._heapStatsChanged, this); } /** * @override */ willHide() { - self.SDK.isolateManager.removeEventListener(SDK.IsolateManager.Events.MemoryChanged, this._heapStatsChanged, this); + SDK.IsolateManager.IsolateManager.instance().removeEventListener( + SDK.IsolateManager.Events.MemoryChanged, this._heapStatsChanged, this); } /** @@ -108,7 +110,7 @@ export class IsolateSelector extends UI.Widget.VBox { if (!model) { return; } - const isolate = self.SDK.isolateManager.isolateByModel(model); + const isolate = SDK.IsolateManager.IsolateManager.instance().isolateByModel(model); const item = isolate && this._itemByIsolate.get(isolate); if (item) { item.updateTitle(); @@ -130,7 +132,7 @@ export class IsolateSelector extends UI.Widget.VBox { _updateTotal() { let total = 0; let trend = 0; - for (const isolate of self.SDK.isolateManager.isolates()) { + for (const isolate of SDK.IsolateManager.IsolateManager.instance().isolates()) { total += isolate.usedHeapSize(); trend += isolate.usedHeapSizeGrowRate(); } diff --git a/front_end/profiler/LiveHeapProfileView.js b/front_end/profiler/LiveHeapProfileView.js index 516f438d7f..7177560d09 100644 --- a/front_end/profiler/LiveHeapProfileView.js +++ b/front_end/profiler/LiveHeapProfileView.js @@ -114,7 +114,7 @@ export class LiveHeapProfileView extends UI.Widget.VBox { async _poll() { const pollId = this._currentPollId; do { - const isolates = Array.from(self.SDK.isolateManager.isolates()); + const isolates = Array.from(SDK.IsolateManager.IsolateManager.instance().isolates()); const profiles = await Promise.all( isolates.map(isolate => isolate.heapProfilerModel() && isolate.heapProfilerModel().getSamplingProfile())); if (this._currentPollId !== pollId) { diff --git a/front_end/sdk/IsolateManager.js b/front_end/sdk/IsolateManager.js index 7876a84a13..2b29ac61ab 100644 --- a/front_end/sdk/IsolateManager.js +++ b/front_end/sdk/IsolateManager.js @@ -8,15 +8,15 @@ import {HeapProfilerModel} from './HeapProfilerModel.js'; // eslint-disable-lin import {RuntimeModel} from './RuntimeModel.js'; import {SDKModelObserver, TargetManager} from './SDKModel.js'; // eslint-disable-line no-unused-vars +/** @type {!IsolateManager} */ +let isolateManagerInstance; + /** * @implements {SDKModelObserver} */ export class IsolateManager extends Common.ObjectWrapper.ObjectWrapper { constructor() { super(); - // @ts-ignore - // TODO(crbug.com/1058320): Replace self.SDK.isolateManager global. - console.assert(!self.SDK.isolateManager, 'Use self.SDK.isolateManager singleton.'); /** @type {!Map} */ this._isolates = new Map(); // _isolateIdByModel contains null while the isolateId is being retrieved. @@ -28,6 +28,17 @@ export class IsolateManager extends Common.ObjectWrapper.ObjectWrapper { this._pollId = 0; } + /** + * @param {{forceNew: boolean}} opts + */ + static instance({forceNew} = {forceNew: false}) { + if (!isolateManagerInstance || forceNew) { + isolateManagerInstance = new IsolateManager(); + } + + return isolateManagerInstance; + } + /** * @param {!Observer} observer */ @@ -225,8 +236,7 @@ export class Isolate { } this._usedHeapSize = usage.usedSize; this._memoryTrend.add(this._usedHeapSize); - // @ts-ignore Replace with IsolateManager.instance. - self.SDK.isolateManager.dispatchEventToListeners(Events.MemoryChanged, this); + IsolateManager.instance().dispatchEventToListeners(Events.MemoryChanged, this); } /** diff --git a/front_end/sdk/sdk-legacy.js b/front_end/sdk/sdk-legacy.js index 738308f4bf..fa762b7551 100644 --- a/front_end/sdk/sdk-legacy.js +++ b/front_end/sdk/sdk-legacy.js @@ -251,5 +251,5 @@ SDK.TracingModel.DevToolsMetadataEventCategory = SDKModule.TracingModel.DevTools SDK.TracingModel.Event = SDKModule.TracingModel.Event; self.SDK.targetManager = SDKModule.SDKModel.TargetManager.instance(); -self.SDK.isolateManager = new SDKModule.IsolateManager.IsolateManager(); +self.SDK.isolateManager = SDKModule.IsolateManager.IsolateManager.instance({forceNew: true}); self.SDK.domModelUndoStack = SDKModule.DOMModel.DOMModelUndoStack.instance();