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

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

Issue 2915883002: DevTools: prepare to unify Network and CPU throttling UI (Closed)
Patch Set: gs Created 3 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @implements {SDK.SDKModelObserver<!SDK.EmulationModel>}
7 */
8 Components.CPUThrottlingManager = class extends Common.Object {
9 constructor() {
10 super();
11 this._throttlingRate = 1; // No throttling
12 /** @type {!Set<!UI.ToolbarComboBox>} */
13 this._controls = new Set();
14 this._rates = [1, 2, 5, 10, 20];
15 SDK.targetManager.observeModels(SDK.EmulationModel, this);
16 }
17
18 /**
19 * @param {number} index
20 */
21 _setRateIndex(index) {
22 this._throttlingRate = this._rates[index];
23 for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
24 emulationModel.setCPUThrottlingRate(this._throttlingRate);
25 var icon = null;
26 if (this._throttlingRate !== 1) {
27 Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled) ;
28 icon = UI.Icon.create('smallicon-warning');
29 icon.title = Common.UIString('CPU throttling is enabled');
30 }
31 for (var control of this._controls)
32 control.setSelectedIndex(index);
33 UI.inspectorView.setPanelIcon('timeline', icon);
34 this.dispatchEventToListeners(Components.CPUThrottlingManager.Events.RateCha nged);
35 }
36
37 /**
38 * @return {number}
39 */
40 rate() {
41 return this._throttlingRate;
42 }
43
44 /**
45 * @override
46 * @param {!SDK.EmulationModel} emulationModel
47 */
48 modelAdded(emulationModel) {
49 if (this._throttlingRate !== 1)
50 emulationModel.setCPUThrottlingRate(this._throttlingRate);
51 }
52
53 /**
54 * @override
55 * @param {!SDK.EmulationModel} emulationModel
56 */
57 modelRemoved(emulationModel) {
58 }
59
60 /**
61 * @return {!UI.ToolbarComboBox}
62 */
63 createControl() {
64 var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.targe t.selectedIndex));
65 this._controls.add(control);
66 var currentRate = this._throttlingRate;
67
68 for (var i = 0; i < this._rates.length; ++i) {
69 var rate = this._rates[i];
70 var title = rate === 1 ? Common.UIString('No throttling') : Common.UIStrin g('%d\xD7 slowdown', rate);
71 var option = control.createOption(title);
72 control.addOption(option);
73 if (currentRate === rate)
74 control.setSelectedIndex(i);
75 }
76 return control;
77 }
78
79 /**
80 * @param {!UI.ToolbarComboBox} control
81 */
82 disposeControl(control) {
83 this._controls.delete(control);
84 }
85 };
86
87 /** @enum {symbol} */
88 Components.CPUThrottlingManager.Events = {
89 RateChanged: Symbol('RateChanged')
90 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698