Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/CPUThrottlingManager.js

Issue 2843763004: [DevTools] Introduce EmulationModel which will encapsulate emulation (Closed)
Patch Set: +throttling Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.SDKModelObserver<!SDK.EmulationModel>}
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);
13 /** @type {!Set<!UI.ToolbarComboBox>} */ 12 /** @type {!Set<!UI.ToolbarComboBox>} */
14 this._controls = new Set(); 13 this._controls = new Set();
15 this._rates = [1, 2, 5, 10, 20]; 14 this._rates = [1, 2, 5, 10, 20];
15 SDK.targetManager.observeModels(SDK.EmulationModel, this);
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 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
24 emulationModel.setCPUThrottlingRate(this._throttlingRate);
24 var icon = null; 25 var icon = null;
25 if (this._throttlingRate !== 1) { 26 if (this._throttlingRate !== 1) {
26 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled) ; 27 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled) ;
27 icon = UI.Icon.create('smallicon-warning'); 28 icon = UI.Icon.create('smallicon-warning');
28 icon.title = Common.UIString('CPU throttling is enabled'); 29 icon.title = Common.UIString('CPU throttling is enabled');
29 } 30 }
30 for (var control of this._controls) 31 for (var control of this._controls)
31 control.setSelectedIndex(index); 32 control.setSelectedIndex(index);
32 UI.inspectorView.setPanelIcon('timeline', icon); 33 UI.inspectorView.setPanelIcon('timeline', icon);
33 this.dispatchEventToListeners(Components.CPUThrottlingManager.Events.RateCha nged); 34 this.dispatchEventToListeners(Components.CPUThrottlingManager.Events.RateCha nged);
34 } 35 }
35 36
36 /** 37 /**
37 * @return {number} 38 * @return {number}
38 */ 39 */
39 rate() { 40 rate() {
40 return this._throttlingRate; 41 return this._throttlingRate;
41 } 42 }
42 43
43 /** 44 /**
44 * @override 45 * @override
45 * @param {!SDK.Target} target 46 * @param {!SDK.EmulationModel} emulationModel
46 */ 47 */
47 targetAdded(target) { 48 modelAdded(emulationModel) {
48 if (this._throttlingRate !== 1) 49 if (this._throttlingRate !== 1)
49 target.emulationAgent().setCPUThrottlingRate(this._throttlingRate); 50 emulationModel.setCPUThrottlingRate(this._throttlingRate);
50 } 51 }
51 52
52 /** 53 /**
53 * @override 54 * @override
54 * @param {!SDK.Target} target 55 * @param {!SDK.EmulationModel} emulationModel
55 */ 56 */
56 targetRemoved(target) { 57 modelRemoved(emulationModel) {
57 } 58 }
58 59
59 /** 60 /**
60 * @return {!UI.ToolbarComboBox} 61 * @return {!UI.ToolbarComboBox}
61 */ 62 */
62 createControl() { 63 createControl() {
63 var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.targe t.selectedIndex)); 64 var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.targe t.selectedIndex));
64 this._controls.add(control); 65 this._controls.add(control);
65 var currentRate = this._throttlingRate; 66 var currentRate = this._throttlingRate;
66 67
(...skipping 13 matching lines...) Expand all
80 */ 81 */
81 disposeControl(control) { 82 disposeControl(control) {
82 this._controls.delete(control); 83 this._controls.delete(control);
83 } 84 }
84 }; 85 };
85 86
86 /** @enum {symbol} */ 87 /** @enum {symbol} */
87 Components.CPUThrottlingManager.Events = { 88 Components.CPUThrottlingManager.Events = {
88 RateChanged: Symbol('RateChanged') 89 RateChanged: Symbol('RateChanged')
89 }; 90 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/BUILD.gn ('k') | third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698