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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/mobile_throttling/MobileThrottlingSelector.js

Issue 2938503002: DevTools: unify Network & CPU throttling (Closed)
Patch Set: update test 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
(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 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698