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

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

Issue 2938503002: DevTools: unify Network & CPU throttling (Closed)
Patch Set: nit Created 3 years, 5 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.SDKModelObserver<!SDK.EmulationModel>} 6 * @implements {SDK.SDKModelObserver<!SDK.EmulationModel>}
7 */ 7 */
8 MobileThrottling.CPUThrottlingManager = class extends Common.Object { 8 MobileThrottling.CPUThrottlingManager = class extends Common.Object {
dgozman 2017/06/30 00:54:16 Let's rename this one to ThrottlingManager, put in
chenwilliam 2017/06/30 22:01:11 Done.
9 constructor() { 9 constructor() {
10 super(); 10 super();
11 this._throttlingRate = 1; // No throttling 11 this._throttlingRate = MobileThrottling.CPUThrottlingRates.NoThrottling;
12 /** @type {!Set<!UI.ToolbarComboBox>} */ 12 /** @type {!Set<!UI.ToolbarComboBox>} */
13 this._controls = new Set(); 13 this._controls = new Set();
14 this._rates = [1, 2, 5, 10, 20]; 14 this._rates = [
15 MobileThrottling.CPUThrottlingRates.NoThrottling,
16 MobileThrottling.CPUThrottlingRates.MidTierMobile,
17 MobileThrottling.CPUThrottlingRates.LowEndMobile,
18 ];
15 SDK.targetManager.observeModels(SDK.EmulationModel, this); 19 SDK.targetManager.observeModels(SDK.EmulationModel, this);
16 } 20 }
17 21
18 /** 22 /**
19 * @param {number} index 23 * @return {number}
20 */ 24 */
21 _setRateIndex(index) { 25 rate() {
dgozman 2017/06/30 00:54:16 And rename this to cpuThrottlingRate().
chenwilliam 2017/06/30 22:01:11 Done.
22 this._throttlingRate = this._rates[index]; 26 return this._throttlingRate;
27 }
28
29 /**
30 * @param {number} rate
31 */
32 setRate(rate) {
33 this._throttlingRate = rate;
23 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel)) 34 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
24 emulationModel.setCPUThrottlingRate(this._throttlingRate); 35 emulationModel.setCPUThrottlingRate(this._throttlingRate);
25 var icon = null; 36 var icon = null;
26 if (this._throttlingRate !== 1) { 37 if (this._throttlingRate !== 1) {
27 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled) ; 38 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled) ;
28 icon = UI.Icon.create('smallicon-warning'); 39 icon = UI.Icon.create('smallicon-warning');
29 icon.title = Common.UIString('CPU throttling is enabled'); 40 icon.title = Common.UIString('CPU throttling is enabled');
30 } 41 }
42 var index = this._rates.indexOf(this._throttlingRate);
31 for (var control of this._controls) 43 for (var control of this._controls)
32 control.setSelectedIndex(index); 44 control.setSelectedIndex(index);
33 UI.inspectorView.setPanelIcon('timeline', icon); 45 UI.inspectorView.setPanelIcon('timeline', icon);
34 this.dispatchEventToListeners(MobileThrottling.CPUThrottlingManager.Events.R ateChanged); 46 this.dispatchEventToListeners(MobileThrottling.CPUThrottlingManager.Events.R ateChanged, this._throttlingRate);
35 } 47 }
36 48
37 /** 49 /**
38 * @return {number}
39 */
40 rate() {
41 return this._throttlingRate;
42 }
43
44 /**
45 * @override 50 * @override
46 * @param {!SDK.EmulationModel} emulationModel 51 * @param {!SDK.EmulationModel} emulationModel
47 */ 52 */
48 modelAdded(emulationModel) { 53 modelAdded(emulationModel) {
49 if (this._throttlingRate !== 1) 54 if (this._throttlingRate !== 1)
50 emulationModel.setCPUThrottlingRate(this._throttlingRate); 55 emulationModel.setCPUThrottlingRate(this._throttlingRate);
51 } 56 }
52 57
53 /** 58 /**
54 * @override 59 * @override
55 * @param {!SDK.EmulationModel} emulationModel 60 * @param {!SDK.EmulationModel} emulationModel
56 */ 61 */
57 modelRemoved(emulationModel) { 62 modelRemoved(emulationModel) {
58 } 63 }
59 64
60 /** 65 /**
61 * @return {!UI.ToolbarComboBox} 66 * @return {!UI.ToolbarComboBox}
62 */ 67 */
63 createControl() { 68 createControl() {
64 var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.targe t.selectedIndex)); 69 var control = new UI.ToolbarComboBox(event => this.setRate(this._rates[event .target.selectedIndex]));
65 this._controls.add(control); 70 this._controls.add(control);
66 var currentRate = this._throttlingRate; 71 var currentRate = this._throttlingRate;
67 72
68 for (var i = 0; i < this._rates.length; ++i) { 73 for (var i = 0; i < this._rates.length; ++i) {
69 var rate = this._rates[i]; 74 var rate = this._rates[i];
70 var title = rate === 1 ? Common.UIString('No throttling') : Common.UIStrin g('%d\xD7 slowdown', rate); 75 var title = rate === 1 ? Common.UIString('No throttling') : Common.UIStrin g('%d\xD7 slowdown', rate);
71 var option = control.createOption(title); 76 var option = control.createOption(title);
72 control.addOption(option); 77 control.addOption(option);
73 if (currentRate === rate) 78 if (currentRate === rate)
74 control.setSelectedIndex(i); 79 control.setSelectedIndex(i);
75 } 80 }
76 return control; 81 return control;
77 } 82 }
78 83
79 /** 84 /**
80 * @param {!UI.ToolbarComboBox} control 85 * @param {!UI.ToolbarComboBox} control
81 */ 86 */
82 disposeControl(control) { 87 disposeControl(control) {
83 this._controls.delete(control); 88 this._controls.delete(control);
84 } 89 }
85 }; 90 };
86 91
87 /** @enum {symbol} */ 92 /** @enum {symbol} */
88 MobileThrottling.CPUThrottlingManager.Events = { 93 MobileThrottling.CPUThrottlingManager.Events = {
89 RateChanged: Symbol('RateChanged') 94 RateChanged: Symbol('RateChanged')
90 }; 95 };
96
97 /** @type {!MobileThrottling.CPUThrottlingManager} */
98 MobileThrottling.cpuThrottlingManager;
dgozman 2017/06/30 00:54:16 Let's make this a lazy function to avoid instantia
chenwilliam 2017/06/30 22:01:11 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698