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

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

Issue 2627103004: DevTools: make cpu throttling manager a control factory we can reuse. (Closed)
Patch Set: for landing Created 3 years, 11 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/components/CPUThrottlingManager.js
diff --git a/third_party/WebKit/Source/devtools/front_end/components/CPUThrottlingManager.js b/third_party/WebKit/Source/devtools/front_end/components/CPUThrottlingManager.js
new file mode 100644
index 0000000000000000000000000000000000000000..4ce1d5b0aac31b3d5a23bed17675c544ece06efd
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/components/CPUThrottlingManager.js
@@ -0,0 +1,88 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @implements {SDK.TargetManager.Observer}
+ */
+Components.CPUThrottlingManager = class extends Common.Object {
+ constructor() {
+ super();
+ this._throttlingRate = 1; // No throttling
+ SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
+ /** @type {!Set<!UI.ToolbarComboBox>} */
+ this._controls = new Set();
+ this._rates = [1, 2, 5, 10, 20];
+ }
+
+ /**
+ * @param {number} index
+ */
+ _setRateIndex(index) {
+ this._throttlingRate = this._rates[index];
+ SDK.targetManager.targets().forEach(target => target.emulationAgent().setCPUThrottlingRate(this._throttlingRate));
+ var icon = null;
+ if (this._throttlingRate !== 1) {
+ icon = UI.Icon.create('smallicon-warning');
+ icon.title = Common.UIString('CPU throttling is enabled');
+ }
+ for (var control of this._controls)
+ control.setSelectedIndex(index);
+ UI.inspectorView.setPanelIcon('timeline', icon);
+ this.dispatchEventToListeners(Components.CPUThrottlingManager.Events.RateChanged);
+ }
+
+ /**
+ * @return {number}
+ */
+ rate() {
+ return this._throttlingRate;
+ }
+
+ /**
+ * @override
+ * @param {!SDK.Target} target
+ */
+ targetAdded(target) {
dgozman 2017/01/13 03:03:18 This goes against our common scheme, which would b
+ if (this._throttlingRate !== 1)
+ target.emulationAgent().setCPUThrottlingRate(this._throttlingRate);
+ }
+
+ /**
+ * @override
+ * @param {!SDK.Target} target
+ */
+ targetRemoved(target) {
+ }
+
+ /**
+ * @return {!UI.ToolbarComboBox}
+ */
+ createControl() {
+ var control = new UI.ToolbarComboBox(event => this._setRateIndex(event.target.selectedIndex));
+ this._controls.add(control);
+ var currentRate = this._throttlingRate;
+
+ for (var i = 0; i < this._rates.length; ++i) {
+ var rate = this._rates[i];
+ var title = rate === 1 ? Common.UIString('No throttling') : Common.UIString('%d\xD7 slowdown', rate);
+ var option = control.createOption(title);
+ control.addOption(option);
+ if (currentRate === rate)
+ control.setSelectedIndex(i);
+ }
+ return control;
+ }
+
+ /**
+ * @param {!UI.ToolbarComboBox} control
+ */
+ disposeControl(control) {
+ this._controls.delete(control);
+ }
+};
+
+/** @enum {symbol} */
+Components.CPUThrottlingManager.Events = {
+ RateChanged: Symbol('RateChanged')
+};
« no previous file with comments | « third_party/WebKit/Source/devtools/BUILD.gn ('k') | third_party/WebKit/Source/devtools/front_end/components/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698