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

Unified Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelinePanel.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/timeline/TimelinePanel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/timeline/TimelinePanel.js b/third_party/WebKit/Source/devtools/front_end/timeline/TimelinePanel.js
index ea13f19990dc01b1d2a46d05f1eb9fbbfeac0563..2db2d0259afd923999baad60d7fff7b59392566a 100644
--- a/third_party/WebKit/Source/devtools/front_end/timeline/TimelinePanel.js
+++ b/third_party/WebKit/Source/devtools/front_end/timeline/TimelinePanel.js
@@ -71,7 +71,7 @@ Timeline.TimelinePanel = class extends UI.Panel {
this._irModel = new TimelineModel.TimelineIRModel();
/** @type {!Array<!{title: string, model: !SDK.TracingModel}>} */
this._extensionTracingModels = [];
- this._cpuThrottlingManager = new Timeline.CPUThrottlingManager();
+ this._cpuThrottlingManager = new Components.CPUThrottlingManager();
/** @type {!Array<!Timeline.TimelineModeView>} */
this._currentViews = [];
@@ -129,18 +129,18 @@ Timeline.TimelinePanel = class extends UI.Panel {
this._configureThrottlingSetting, 'largeicon-settings-gear', Common.UIString('Configure throttling'));
SDK.multitargetNetworkManager.addEventListener(
SDK.MultitargetNetworkManager.Events.ConditionsChanged, this._updateConfigureThrottlingButton.bind(this));
+ this._cpuThrottlingManager.addEventListener(
+ Components.CPUThrottlingManager.Events.RateChanged, this._updateConfigureThrottlingButton.bind(this));
this._throttlingToolbar = new UI.Toolbar('', this.element);
- this._cpuThrottlingCombobox = new UI.ToolbarComboBox(this._onCPUThrottlingChanged.bind(this));
this._throttlingToolbar.appendText(Common.UIString('Network:'));
this._throttlingToolbar.appendToolbarItem(this._createNetworkConditionsSelect());
this._throttlingToolbar.appendSeparator();
this._throttlingToolbar.appendText(Common.UIString('CPU:'));
- this._throttlingToolbar.appendToolbarItem(this._cpuThrottlingCombobox);
+ this._throttlingToolbar.appendToolbarItem(this._cpuThrottlingManager.createControl());
this._throttlingToolbar.appendToolbarItem(new UI.ToolbarSeparator(true));
var hideToolbarItem = new UI.ToolbarButton(Common.UIString('Close'), 'largeicon-delete');
hideToolbarItem.addEventListener(UI.ToolbarButton.Events.Click, () => this._configureThrottlingSetting.set(false));
this._throttlingToolbar.appendToolbarItem(hideToolbarItem);
- this._populateCPUThrottingCombobox();
this._configureThrottlingSetting.addChangeListener(this._updateThrottlingToolbarVisibility.bind(this));
this._updateThrottlingToolbarVisibility();
@@ -369,28 +369,6 @@ Timeline.TimelinePanel = class extends UI.Panel {
return toolbarItem;
}
- _populateCPUThrottingCombobox() {
- var cpuThrottlingCombobox = this._cpuThrottlingCombobox;
- cpuThrottlingCombobox.removeOptions();
- var currentRate = this._cpuThrottlingManager.rate();
- var hasSelection = false;
- /**
- * @param {string} name
- * @param {number} value
- */
- function addOption(name, value) {
- var option = cpuThrottlingCombobox.createOption(name, '', String(value));
- cpuThrottlingCombobox.addOption(option);
- if (hasSelection || (value && value !== currentRate))
- return;
- cpuThrottlingCombobox.select(option);
- hasSelection = true;
- }
- addOption(Common.UIString('No throttling'), 1);
- for (const rate of [2, 5, 10, 20])
- addOption(Common.UIString('%d\xD7 slowdown', rate), rate);
- }
-
_prepareToLoadTimeline() {
console.assert(this._state === Timeline.TimelinePanel.State.Idle);
this._setState(Timeline.TimelinePanel.State.Loading);
@@ -505,14 +483,6 @@ Timeline.TimelinePanel = class extends UI.Panel {
this.select(null);
}
- _onCPUThrottlingChanged() {
- if (!this._cpuThrottlingManager)
- return;
- var text = this._cpuThrottlingCombobox.selectedOption().value;
- this._cpuThrottlingManager.setRate(Number.parseFloat(text));
- this._updateConfigureThrottlingButton();
- }
-
_updateThrottlingToolbarVisibility() {
this._throttlingToolbar.element.classList.toggle('hidden', !this._configureThrottlingSetting.get());
}
@@ -1878,54 +1848,3 @@ Timeline.TimelineFilters.Events = {
};
Timeline.TimelineFilters._durationFilterPresetsMs = [0, 1, 15];
-
-/**
- * @implements {SDK.TargetManager.Observer}
- * @unrestricted
- */
-Timeline.CPUThrottlingManager = class extends Common.Object {
- constructor() {
- super();
- this._targets = [];
- this._throttlingRate = 1.; // No throttling
- SDK.targetManager.observeTargets(this, SDK.Target.Capability.Browser);
- }
-
- /**
- * @param {number} value
- */
- setRate(value) {
- this._throttlingRate = value;
- this._targets.forEach(target => target.emulationAgent().setCPUThrottlingRate(value));
- var icon = null;
- if (value !== 1) {
- icon = UI.Icon.create('smallicon-warning');
- icon.title = Common.UIString('CPU throttling is enabled');
- }
- UI.inspectorView.setPanelIcon('timeline', icon);
- }
-
- /**
- * @return {number}
- */
- rate() {
- return this._throttlingRate;
- }
-
- /**
- * @override
- * @param {!SDK.Target} target
- */
- targetAdded(target) {
- this._targets.push(target);
- target.emulationAgent().setCPUThrottlingRate(this._throttlingRate);
- }
-
- /**
- * @override
- * @param {!SDK.Target} target
- */
- targetRemoved(target) {
- this._targets.remove(target, true);
- }
-};

Powered by Google App Engine
This is Rietveld 408576698