Chromium Code Reviews| OLD | NEW |
|---|---|
| (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.TargetManager.Observer} | |
| 7 * @unrestricted | |
|
caseq
2017/01/12 02:59:12
nit: can you remove it?
| |
| 8 */ | |
| 9 Components.CPUThrottlingManager = class extends Common.Object { | |
| 10 constructor() { | |
| 11 super(); | |
| 12 this._throttlingRate = 1; // No throttling | |
| 13 SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser); | |
| 14 /** @type {!Set<!UI.ToolbarComboBox>} */ | |
| 15 this._controls = new Set(); | |
| 16 this._rates = [1, 2, 5, 10, 20]; | |
| 17 } | |
| 18 | |
| 19 /** | |
| 20 * @param {number} index | |
| 21 */ | |
| 22 _setRateIndex(index) { | |
| 23 this._throttlingRate = this._rates[index]; | |
| 24 SDK.targetManager.targets().forEach(target => target.emulationAgent().setCPU ThrottlingRate(this._throttlingRate)); | |
| 25 var icon = null; | |
| 26 if (this._throttlingRate !== 1) { | |
| 27 icon = UI.Icon.create('smallicon-warning'); | |
| 28 icon.title = Common.UIString('CPU throttling is enabled'); | |
| 29 } | |
| 30 for (var control of this._controls) | |
| 31 control.setSelectedIndex(index); | |
| 32 UI.inspectorView.setPanelIcon('timeline', icon); | |
| 33 this.dispatchEventToListeners(Components.CPUThrottlingManager.Events.RateCha nged); | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * @return {number} | |
| 38 */ | |
| 39 rate() { | |
| 40 return this._throttlingRate || 1; | |
|
caseq
2017/01/12 02:59:12
nit: "|| 1" is hopefully redundant.
| |
| 41 } | |
| 42 | |
| 43 /** | |
| 44 * @override | |
| 45 * @param {!SDK.Target} target | |
| 46 */ | |
| 47 targetAdded(target) { | |
| 48 if (this._throttlingRate !== 1) | |
| 49 target.emulationAgent().setCPUThrottlingRate(this._throttlingRate); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * @override | |
| 54 * @param {!SDK.Target} target | |
| 55 */ | |
| 56 targetRemoved(target) { | |
| 57 } | |
| 58 | |
| 59 /** | |
| 60 * @return {!UI.ToolbarComboBox} | |
| 61 */ | |
| 62 createControl() { | |
| 63 var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.targe t.selectedIndex)); | |
| 64 this._controls.add(control); | |
| 65 var currentRate = this._throttlingRate; | |
| 66 | |
| 67 for (var i = 0; i < this._rates.length; ++i) { | |
| 68 var rate = this._rates[i]; | |
| 69 var title = rate === 1 ? Common.UIString('No throttling') : Common.UIStrin g('%d\xD7 slowdown', rate); | |
| 70 var option = control.createOption(title); | |
| 71 control.addOption(option); | |
| 72 if (currentRate === rate) | |
| 73 control.setSelectedIndex(i); | |
| 74 } | |
| 75 return control; | |
| 76 } | |
| 77 | |
| 78 /** | |
| 79 * @param {!UI.ToolbarComboBox} control | |
| 80 */ | |
| 81 disposeControl(control) { | |
|
caseq
2017/01/12 02:59:12
unused?
| |
| 82 this._controls.delete(control); | |
| 83 } | |
| 84 }; | |
| 85 | |
| 86 /** @enum {symbol} */ | |
| 87 Components.CPUThrottlingManager.Events = { | |
| 88 RateChanged: Symbol('RateChanged') | |
| 89 }; | |
| OLD | NEW |