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

Unified Diff: third_party/WebKit/Source/devtools/front_end/mobile_throttling/CPUThrottlingManager.js

Issue 2938503002: DevTools: unify Network & CPU throttling (Closed)
Patch Set: rebaseline 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/mobile_throttling/CPUThrottlingManager.js
diff --git a/third_party/WebKit/Source/devtools/front_end/mobile_throttling/CPUThrottlingManager.js b/third_party/WebKit/Source/devtools/front_end/mobile_throttling/CPUThrottlingManager.js
index 412e9e9fe212a57f4e1bf03cccb92b32a89b965f..4fe643eb8fb20ebb3465e37095f00bbe5c5c1fa8 100644
--- a/third_party/WebKit/Source/devtools/front_end/mobile_throttling/CPUThrottlingManager.js
+++ b/third_party/WebKit/Source/devtools/front_end/mobile_throttling/CPUThrottlingManager.js
@@ -8,37 +8,35 @@
MobileThrottling.CPUThrottlingManager = class extends Common.Object {
constructor() {
super();
- this._throttlingRate = 1; // No throttling
+ MobileThrottling.cpuThrottlingRateSetting().addChangeListener(this._rateChanged, this);
+
/** @type {!Set<!UI.ToolbarComboBox>} */
this._controls = new Set();
- this._rates = [1, 2, 5, 10, 20];
+ this._rates = [
+ MobileThrottling.CPUThrottlingRates.NoThrottling,
+ MobileThrottling.CPUThrottlingRates.MidTierMobile,
+ MobileThrottling.CPUThrottlingRates.LowEndMobile,
+ ];
SDK.targetManager.observeModels(SDK.EmulationModel, this);
}
/**
- * @param {number} index
+ * @param {!Common.Event} event
*/
- _setRateIndex(index) {
- this._throttlingRate = this._rates[index];
+ _rateChanged(event) {
+ var rate = /** @type {number} */ (event.data);
for (var emulationModel of SDK.targetManager.models(SDK.EmulationModel))
- emulationModel.setCPUThrottlingRate(this._throttlingRate);
+ emulationModel.setCPUThrottlingRate(rate);
var icon = null;
- if (this._throttlingRate !== 1) {
+ if (rate !== 1) {
Host.userMetrics.actionTaken(Host.UserMetrics.Action.CpuThrottlingEnabled);
icon = UI.Icon.create('smallicon-warning');
icon.title = Common.UIString('CPU throttling is enabled');
}
+ var index = this._rates.indexOf(rate);
for (var control of this._controls)
control.setSelectedIndex(index);
UI.inspectorView.setPanelIcon('timeline', icon);
- this.dispatchEventToListeners(MobileThrottling.CPUThrottlingManager.Events.RateChanged);
- }
-
- /**
- * @return {number}
- */
- rate() {
- return this._throttlingRate;
}
/**
@@ -46,8 +44,9 @@ MobileThrottling.CPUThrottlingManager = class extends Common.Object {
* @param {!SDK.EmulationModel} emulationModel
*/
modelAdded(emulationModel) {
- if (this._throttlingRate !== 1)
- emulationModel.setCPUThrottlingRate(this._throttlingRate);
+ var rate = MobileThrottling.cpuThrottlingRateSetting().get();
+ if (rate !== 1)
+ emulationModel.setCPUThrottlingRate(rate);
}
/**
@@ -61,9 +60,10 @@ MobileThrottling.CPUThrottlingManager = class extends Common.Object {
* @return {!UI.ToolbarComboBox}
*/
createControl() {
- var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.target.selectedIndex));
+ var control = new UI.ToolbarComboBox(
+ event => MobileThrottling.cpuThrottlingRateSetting().set(this._rates[event.target.selectedIndex]));
this._controls.add(control);
- var currentRate = this._throttlingRate;
+ var currentRate = MobileThrottling.cpuThrottlingRateSetting().get();
for (var i = 0; i < this._rates.length; ++i) {
var rate = this._rates[i];
@@ -88,3 +88,6 @@ MobileThrottling.CPUThrottlingManager = class extends Common.Object {
MobileThrottling.CPUThrottlingManager.Events = {
RateChanged: Symbol('RateChanged')
};
+
+/** @type {!MobileThrottling.CPUThrottlingManager} */
+MobileThrottling.cpuThrottlingManager;

Powered by Google App Engine
This is Rietveld 408576698