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

Unified Diff: Source/devtools/front_end/sdk/OverridesSupport.js

Issue 319143002: DevTools: introduce WebInspector.Throttler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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
« no previous file with comments | « Source/devtools/front_end/inspector.html ('k') | Source/devtools/scripts/frontend_modules.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/sdk/OverridesSupport.js
diff --git a/Source/devtools/front_end/sdk/OverridesSupport.js b/Source/devtools/front_end/sdk/OverridesSupport.js
index 483743e355267120eb2d50104418f555eb3db54e..b42849a2d186c60d66c0924e300a04cc71f9c2f2 100644
--- a/Source/devtools/front_end/sdk/OverridesSupport.js
+++ b/Source/devtools/front_end/sdk/OverridesSupport.js
@@ -42,6 +42,7 @@ WebInspector.OverridesSupport = function(responsiveDesignAvailable)
this._userAgent = "";
this._pageResizer = null;
this._initialized = false;
+ this._deviceMetricsThrottler = new WebInspector.Throttler(0);
WebInspector.targetManager.observeTargets(this);
this._responsiveDesignAvailable = responsiveDesignAvailable;
}
@@ -585,7 +586,7 @@ WebInspector.OverridesSupport.prototype = {
var overrideDeviceResolution = this.settings.overrideDeviceResolution.get();
var emulationEnabled = overrideDeviceResolution || this.settings.emulateViewport.get();
if (responsiveDesignAvailableAndDisabled || !emulationEnabled) {
- PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this));
+ PageAgent.clearDeviceMetricsOverride(apiCallback.bind(this, new Function()));
vsevik 2014/06/06 16:14:45 I think we use function() {} usually.
lushnikov 2014/06/06 16:38:15 Not relevant any more.
if (this._pageResizer && !emulationEnabled)
this._pageResizer.update(0, 0, 0);
this.maybeHasActiveOverridesChanged();
@@ -613,47 +614,37 @@ WebInspector.OverridesSupport.prototype = {
}
}
- // Do not emulate resolution more often than 10Hz.
- this._setDeviceMetricsTimers = (this._setDeviceMetricsTimers || 0) + 1;
if (overrideWidth || overrideHeight)
- setTimeout(setDeviceMetricsOverride.bind(this), 100);
+ this._deviceMetricsThrottler.schedule(setDeviceMetricsOverride.bind(this));
else
- setDeviceMetricsOverride.call(this);
+ setDeviceMetricsOverride.call(this, new Function());
/**
+ * @param {function()} finishCallback
* @this {WebInspector.OverridesSupport}
*/
- function setDeviceMetricsOverride()
+ function setDeviceMetricsOverride(finishCallback)
{
- // Drop heavy intermediate commands.
- this._setDeviceMetricsTimers--;
- var isExpensive = overrideWidth || overrideHeight;
- if (isExpensive && this._setDeviceMetricsTimers) {
- var commandThreshold = 100;
- var time = window.performance.now();
- if (time - this._lastExpensivePageAgentCommandTime < commandThreshold)
- return;
- this._lastExpensivePageAgentCommandTime = time;
- }
-
PageAgent.setDeviceMetricsOverride(
overrideWidth, overrideHeight, this.settings.deviceScaleFactor.get(),
this.settings.emulateViewport.get(), this._pageResizer ? false : this.settings.deviceFitWindow.get(),
this.settings.deviceTextAutosizing.get(), this._fontScaleFactor(overrideWidth || dipWidth, overrideHeight || dipHeight),
- apiCallback.bind(this));
+ apiCallback.bind(this, finishCallback));
}
this.maybeHasActiveOverridesChanged();
/**
+ * @param {function()} finishCallback
* @param {?Protocol.Error} error
* @this {WebInspector.OverridesSupport}
*/
- function apiCallback(error)
+ function apiCallback(finishCallback, error)
{
if (error) {
this._updateDeviceMetricsWarningMessage(WebInspector.UIString("Screen emulation is not available on this page."));
this._deviceMetricsOverrideAppliedForTest();
+ finishCallback();
return;
}
@@ -664,6 +655,7 @@ WebInspector.OverridesSupport.prototype = {
this._overrideDeviceResolution = overrideDeviceResolution;
this._emulateViewportEnabled = viewportEnabled;
this._deviceMetricsOverrideAppliedForTest();
+ finishCallback();
}
},
« no previous file with comments | « Source/devtools/front_end/inspector.html ('k') | Source/devtools/scripts/frontend_modules.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698