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

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: rebaseline 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 {
9 constructor() { 9 constructor() {
10 super(); 10 super();
11 this._throttlingRate = 1; // No throttling 11 MobileThrottling.cpuThrottlingRateSetting().addChangeListener(this._rateChan ged, this);
12
12 /** @type {!Set<!UI.ToolbarComboBox>} */ 13 /** @type {!Set<!UI.ToolbarComboBox>} */
13 this._controls = new Set(); 14 this._controls = new Set();
14 this._rates = [1, 2, 5, 10, 20]; 15 this._rates = [
16 MobileThrottling.CPUThrottlingRates.NoThrottling,
17 MobileThrottling.CPUThrottlingRates.MidTierMobile,
18 MobileThrottling.CPUThrottlingRates.LowEndMobile,
19 ];
15 SDK.targetManager.observeModels(SDK.EmulationModel, this); 20 SDK.targetManager.observeModels(SDK.EmulationModel, this);
16 } 21 }
17 22
18 /** 23 /**
19 * @param {number} index 24 * @param {!Common.Event} event
20 */ 25 */
21 _setRateIndex(index) { 26 _rateChanged(event) {
22 this._throttlingRate = this._rates[index]; 27 var rate = /** @type {number} */ (event.data);
23 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel)) 28 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
24 emulationModel.setCPUThrottlingRate(this._throttlingRate); 29 emulationModel.setCPUThrottlingRate(rate);
25 var icon = null; 30 var icon = null;
26 if (this._throttlingRate !== 1) { 31 if (rate !== 1) {
27 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled) ; 32 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled) ;
28 icon = UI.Icon.create('smallicon-warning'); 33 icon = UI.Icon.create('smallicon-warning');
29 icon.title = Common.UIString('CPU throttling is enabled'); 34 icon.title = Common.UIString('CPU throttling is enabled');
30 } 35 }
36 var index = this._rates.indexOf(rate);
31 for (var control of this._controls) 37 for (var control of this._controls)
32 control.setSelectedIndex(index); 38 control.setSelectedIndex(index);
33 UI.inspectorView.setPanelIcon('timeline', icon); 39 UI.inspectorView.setPanelIcon('timeline', icon);
34 this.dispatchEventToListeners(MobileThrottling.CPUThrottlingManager.Events.R ateChanged);
35 } 40 }
36 41
37 /** 42 /**
38 * @return {number}
39 */
40 rate() {
41 return this._throttlingRate;
42 }
43
44 /**
45 * @override 43 * @override
46 * @param {!SDK.EmulationModel} emulationModel 44 * @param {!SDK.EmulationModel} emulationModel
47 */ 45 */
48 modelAdded(emulationModel) { 46 modelAdded(emulationModel) {
49 if (this._throttlingRate !== 1) 47 var rate = MobileThrottling.cpuThrottlingRateSetting().get();
50 emulationModel.setCPUThrottlingRate(this._throttlingRate); 48 if (rate !== 1)
49 emulationModel.setCPUThrottlingRate(rate);
51 } 50 }
52 51
53 /** 52 /**
54 * @override 53 * @override
55 * @param {!SDK.EmulationModel} emulationModel 54 * @param {!SDK.EmulationModel} emulationModel
56 */ 55 */
57 modelRemoved(emulationModel) { 56 modelRemoved(emulationModel) {
58 } 57 }
59 58
60 /** 59 /**
61 * @return {!UI.ToolbarComboBox} 60 * @return {!UI.ToolbarComboBox}
62 */ 61 */
63 createControl() { 62 createControl() {
64 var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.targe t.selectedIndex)); 63 var control = new UI.ToolbarComboBox(
64 event => MobileThrottling.cpuThrottlingRateSetting().set(this._rates[eve nt.target.selectedIndex]));
65 this._controls.add(control); 65 this._controls.add(control);
66 var currentRate = this._throttlingRate; 66 var currentRate = MobileThrottling.cpuThrottlingRateSetting().get();
67 67
68 for (var i = 0; i < this._rates.length; ++i) { 68 for (var i = 0; i < this._rates.length; ++i) {
69 var rate = this._rates[i]; 69 var rate = this._rates[i];
70 var title = rate === 1 ? Common.UIString('No throttling') : Common.UIStrin g('%d\xD7 slowdown', rate); 70 var title = rate === 1 ? Common.UIString('No throttling') : Common.UIStrin g('%d\xD7 slowdown', rate);
71 var option = control.createOption(title); 71 var option = control.createOption(title);
72 control.addOption(option); 72 control.addOption(option);
73 if (currentRate === rate) 73 if (currentRate === rate)
74 control.setSelectedIndex(i); 74 control.setSelectedIndex(i);
75 } 75 }
76 return control; 76 return control;
77 } 77 }
78 78
79 /** 79 /**
80 * @param {!UI.ToolbarComboBox} control 80 * @param {!UI.ToolbarComboBox} control
81 */ 81 */
82 disposeControl(control) { 82 disposeControl(control) {
83 this._controls.delete(control); 83 this._controls.delete(control);
84 } 84 }
85 }; 85 };
86 86
87 /** @enum {symbol} */ 87 /** @enum {symbol} */
88 MobileThrottling.CPUThrottlingManager.Events = { 88 MobileThrottling.CPUThrottlingManager.Events = {
89 RateChanged: Symbol('RateChanged') 89 RateChanged: Symbol('RateChanged')
90 }; 90 };
91
92 /** @type {!MobileThrottling.CPUThrottlingManager} */
93 MobileThrottling.cpuThrottlingManager;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698