| 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 MobileThrottling.MobileThrottlingSelector = class { |
| 6 /** |
| 7 * @param {function(!Array<!MobileThrottling.MobileThrottlingConditionsGroup>)
:!MobileThrottling.ConditionsList} populateCallback |
| 8 * @param {function(number)} selectCallback |
| 9 */ |
| 10 constructor(populateCallback, selectCallback) { |
| 11 this._populateCallback = populateCallback; |
| 12 this._selectCallback = selectCallback; |
| 13 MobileThrottling.throttlingManager().addEventListener( |
| 14 MobileThrottling.ThrottlingManager.Events.RateChanged, this._conditionsC
hanged, this); |
| 15 SDK.multitargetNetworkManager.addEventListener( |
| 16 SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._conditions
Changed, this); |
| 17 /** @type {!MobileThrottling.ConditionsList} */ |
| 18 this._options = this._populateOptions(); |
| 19 this._conditionsChanged(); |
| 20 } |
| 21 |
| 22 /** |
| 23 * @param {!MobileThrottling.Conditions} conditions |
| 24 */ |
| 25 optionSelected(conditions) { |
| 26 SDK.multitargetNetworkManager.setNetworkConditions(conditions.network); |
| 27 MobileThrottling.throttlingManager().setCPUThrottlingRate(conditions.cpuThro
ttlingRate); |
| 28 } |
| 29 |
| 30 /** |
| 31 * @return {!MobileThrottling.ConditionsList} |
| 32 */ |
| 33 _populateOptions() { |
| 34 var disabledGroup = {title: Common.UIString('Disabled'), items: [MobileThrot
tling.NoThrottlingConditions]}; |
| 35 var presetsGroup = {title: Common.UIString('Presets'), items: MobileThrottli
ng.mobilePresets}; |
| 36 var advancedGroup = {title: Common.UIString('Advanced'), items: MobileThrott
ling.advancedMobilePresets}; |
| 37 return this._populateCallback([disabledGroup, presetsGroup, advancedGroup]); |
| 38 } |
| 39 |
| 40 _conditionsChanged() { |
| 41 var networkConditions = SDK.multitargetNetworkManager.networkConditions(); |
| 42 var cpuThrottlingRate = MobileThrottling.throttlingManager().cpuThrottlingRa
te(); |
| 43 for (var index = 0; index < this._options.length; ++index) { |
| 44 var option = this._options[index]; |
| 45 if (option && option.network === networkConditions && option.cpuThrottling
Rate === cpuThrottlingRate) { |
| 46 this._selectCallback(index); |
| 47 return; |
| 48 } |
| 49 } |
| 50 this._selectCallback(this._options.indexOf(MobileThrottling.CustomConditions
)); |
| 51 } |
| 52 }; |
| OLD | NEW |