Skip to content

Commit f946feb

Browse files
szuendDevtools-frontend LUCI CQ
authored andcommitted
Reland "[sdk] Pass Settings/TargetManager via ctor to CPUThrottlingManager"
This is a reland of commit f278127 We can reland as-is. The source of CI flakiness was caused by something else. Original change's description: > [sdk] Pass Settings/TargetManager via ctor to CPUThrottlingManager > > R=bmeurer@chromium.org > > Bug: 490892816 > Change-Id: Ic46660906568858ae50c3bded62b600be8e12c3d > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7652496 > Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> > Auto-Submit: Simon Zünd <szuend@chromium.org> > Commit-Queue: Simon Zünd <szuend@chromium.org> > Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Bug: 490892816 Change-Id: Icbfbfd0967804604348fc174ea3e1b816a3c950e Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7671799 Auto-Submit: Simon Zünd <szuend@chromium.org> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
1 parent 13dd889 commit f946feb

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

front_end/core/sdk/CPUThrottlingManager.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,27 @@ let throttlingManagerInstance: CPUThrottlingManager|undefined;
3939

4040
export class CPUThrottlingManager extends Common.ObjectWrapper.ObjectWrapper<EventTypes> implements
4141
SDKModelObserver<EmulationModel> {
42+
readonly #targetManager: TargetManager;
4243
#cpuThrottlingOption: CPUThrottlingOption;
4344
#calibratedThrottlingSetting: Common.Settings.Setting<CalibratedCPUThrottling>;
4445
#hardwareConcurrency?: number;
4546
#pendingMainTargetPromise?: (r: number) => void;
4647

47-
private constructor() {
48+
private constructor(settings: Common.Settings.Settings, targetManager: TargetManager) {
4849
super();
50+
this.#targetManager = targetManager;
4951
this.#cpuThrottlingOption = NoThrottlingOption;
50-
this.#calibratedThrottlingSetting = Common.Settings.Settings.instance().createSetting<CalibratedCPUThrottling>(
52+
this.#calibratedThrottlingSetting = settings.createSetting<CalibratedCPUThrottling>(
5153
'calibrated-cpu-throttling', {}, Common.Settings.SettingStorageType.GLOBAL);
5254
this.#calibratedThrottlingSetting.addChangeListener(this.#onCalibratedSettingChanged, this);
53-
TargetManager.instance().observeModels(EmulationModel, this);
55+
targetManager.observeModels(EmulationModel, this);
5456
}
5557

5658
static instance(opts: {forceNew: boolean|null} = {forceNew: null}): CPUThrottlingManager {
5759
const {forceNew} = opts;
5860
if (!throttlingManagerInstance || forceNew) {
59-
throttlingManagerInstance = new CPUThrottlingManager();
61+
throttlingManagerInstance =
62+
new CPUThrottlingManager(Common.Settings.Settings.instance(), TargetManager.instance());
6063
}
6164

6265
return throttlingManagerInstance;
@@ -88,7 +91,7 @@ export class CPUThrottlingManager extends Common.ObjectWrapper.ObjectWrapper<Eve
8891
return;
8992
}
9093

91-
for (const emulationModel of TargetManager.instance().models(EmulationModel)) {
94+
for (const emulationModel of this.#targetManager.models(EmulationModel)) {
9295
void emulationModel.setCPUThrottlingRate(rate);
9396
}
9497
this.dispatchEventToListeners(Events.RATE_CHANGED, rate);
@@ -100,15 +103,15 @@ export class CPUThrottlingManager extends Common.ObjectWrapper.ObjectWrapper<Eve
100103
}
101104

102105
this.#cpuThrottlingOption = option;
103-
for (const emulationModel of TargetManager.instance().models(EmulationModel)) {
106+
for (const emulationModel of this.#targetManager.models(EmulationModel)) {
104107
void emulationModel.setCPUThrottlingRate(this.#cpuThrottlingOption.rate());
105108
}
106109
this.dispatchEventToListeners(Events.RATE_CHANGED, this.#cpuThrottlingOption.rate());
107110
}
108111

109112
setHardwareConcurrency(concurrency: number): void {
110113
this.#hardwareConcurrency = concurrency;
111-
for (const emulationModel of TargetManager.instance().models(EmulationModel)) {
114+
for (const emulationModel of this.#targetManager.models(EmulationModel)) {
112115
void emulationModel.setHardwareConcurrency(concurrency);
113116
}
114117
this.dispatchEventToListeners(Events.HARDWARE_CONCURRENCY_CHANGED, this.#hardwareConcurrency);
@@ -119,14 +122,14 @@ export class CPUThrottlingManager extends Common.ObjectWrapper.ObjectWrapper<Eve
119122
// target may error. So if we get any errors here at all, assume that we do
120123
// not have a target.
121124
try {
122-
return TargetManager.instance().primaryPageTarget() !== null;
125+
return this.#targetManager.primaryPageTarget() !== null;
123126
} catch {
124127
return false;
125128
}
126129
}
127130

128131
async getHardwareConcurrency(): Promise<number> {
129-
const target = TargetManager.instance().primaryPageTarget();
132+
const target = this.#targetManager.primaryPageTarget();
130133
const existingCallback = this.#pendingMainTargetPromise;
131134

132135
// If the main target hasn't attached yet, block callers until it appears.

0 commit comments

Comments
 (0)