OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @implements {SDK.TargetManager.Observer} | 6 * @implements {SDK.TargetManager.Observer} |
7 */ | 7 */ |
8 Components.CPUThrottlingManager = class extends Common.Object { | 8 Components.CPUThrottlingManager = class extends Common.Object { |
9 constructor() { | 9 constructor() { |
10 super(); | 10 super(); |
11 this._throttlingRate = 1; // No throttling | 11 this._throttlingRate = 1; // No throttling |
12 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser); | 12 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser); |
13 /** @type {!Set<!UI.ToolbarComboBox>} */ | 13 /** @type {!Set<!UI.ToolbarComboBox>} */ |
14 this._controls = new Set(); | 14 this._controls = new Set(); |
15 this._rates = [1, 2, 5, 10, 20]; | 15 this._rates = [1, 2, 5, 10, 20]; |
16 } | 16 } |
17 | 17 |
18 /** | 18 /** |
19 * @param {number} index | 19 * @param {number} index |
20 */ | 20 */ |
21 _setRateIndex(index) { | 21 _setRateIndex(index) { |
22 this._throttlingRate = this._rates[index]; | 22 this._throttlingRate = this._rates[index]; |
23 SDK.targetManager.targets().forEach(target => target.emulationAgent().setCPU
ThrottlingRate(this._throttlingRate)); | 23 SDK.targetManager.targets().forEach(target => target.emulationAgent().setCPU
ThrottlingRate(this._throttlingRate)); |
24 var icon = null; | 24 var icon = null; |
25 if (this._throttlingRate !== 1) { | 25 if (this._throttlingRate !== 1) { |
| 26 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled)
; |
26 icon = UI.Icon.create('smallicon-warning'); | 27 icon = UI.Icon.create('smallicon-warning'); |
27 icon.title = Common.UIString('CPU throttling is enabled'); | 28 icon.title = Common.UIString('CPU throttling is enabled'); |
28 } | 29 } |
29 for (var control of this._controls) | 30 for (var control of this._controls) |
30 control.setSelectedIndex(index); | 31 control.setSelectedIndex(index); |
31 UI.inspectorView.setPanelIcon('timeline', icon); | 32 UI.inspectorView.setPanelIcon('timeline', icon); |
32 this.dispatchEventToListeners(Components.CPUThrottlingManager.Events.RateCha
nged); | 33 this.dispatchEventToListeners(Components.CPUThrottlingManager.Events.RateCha
nged); |
33 } | 34 } |
34 | 35 |
35 /** | 36 /** |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 */ | 80 */ |
80 disposeControl(control) { | 81 disposeControl(control) { |
81 this._controls.delete(control); | 82 this._controls.delete(control); |
82 } | 83 } |
83 }; | 84 }; |
84 | 85 |
85 /** @enum {symbol} */ | 86 /** @enum {symbol} */ |
86 Components.CPUThrottlingManager.Events = { | 87 Components.CPUThrottlingManager.Events = { |
87 RateChanged: Symbol('RateChanged') | 88 RateChanged: Symbol('RateChanged') |
88 }; | 89 }; |
OLD | NEW |