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