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

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

Issue 1186083003: [DevTools] Move network throttling to network panel. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merged in device mode Created 5 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/network/NetworkPanel.js ('k') | Source/devtools/front_end/ui/Toolbar.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/sdk/NetworkManager.js
diff --git a/Source/devtools/front_end/sdk/NetworkManager.js b/Source/devtools/front_end/sdk/NetworkManager.js
index 6f3fcbe1083ecf86f9c89f7e046df661a51783cb..f23e4766967ec3fc120e9a0cd4fa7c7e2b08ec03 100644
--- a/Source/devtools/front_end/sdk/NetworkManager.js
+++ b/Source/devtools/front_end/sdk/NetworkManager.js
@@ -44,6 +44,7 @@ WebInspector.NetworkManager = function(target)
this._networkAgent.setCacheDisabled(true);
if (WebInspector.moduleSetting("monitoringXHREnabled").get())
this._networkAgent.setMonitoringXHREnabled(true);
+ this._initNetworkConditions();
this._networkAgent.enable();
WebInspector.moduleSetting("cacheDisabled").addChangeListener(this._cacheDisabledSettingChanged, this);
@@ -67,6 +68,9 @@ WebInspector.NetworkManager._MIMETypes = {
"text/vtt": {"texttrack": true},
}
+/** @typedef {{throughput: number, latency: number}} */
+WebInspector.NetworkManager.Conditions;
+
WebInspector.NetworkManager.prototype = {
/**
* @param {string} url
@@ -101,6 +105,46 @@ WebInspector.NetworkManager.prototype = {
this._networkAgent.clearBrowserCookies();
},
+ _initNetworkConditions: function()
+ {
+ this._networkAgent.canEmulateNetworkConditions(callback.bind(this));
+
+ /**
+ * @this {WebInspector.NetworkManager}
+ */
+ function callback(error, canEmulate)
+ {
+ if (error || !canEmulate)
+ return;
+ WebInspector.moduleSetting("networkConditions").addChangeListener(this._networkConditionsSettingChanged, this);
+ var conditions = WebInspector.moduleSetting("networkConditions").get();
+ if (conditions.throughput < 0)
+ return;
+ this._updateNetworkConditions(conditions);
+ }
+ },
+
+ /**
+ * @param {!WebInspector.NetworkManager.Conditions} conditions
+ */
+ _updateNetworkConditions: function(conditions)
+ {
+ if (conditions.throughput < 0) {
+ this._networkAgent.emulateNetworkConditions(false, 0, 0, 0);
+ } else {
+ var offline = !conditions.throughput && !conditions.latency;
+ this._networkAgent.emulateNetworkConditions(!!offline, conditions.latency, conditions.throughput, conditions.throughput);
+ }
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _networkConditionsSettingChanged: function(event)
+ {
+ this._updateNetworkConditions(/** @type {!WebInspector.NetworkManager.Conditions} */ (event.data));
+ },
+
__proto__: WebInspector.SDKModel.prototype
}
@@ -596,10 +640,6 @@ WebInspector.MultitargetNetworkManager.prototype = {
networkAgent.setExtraHTTPHeaders(this._extraHeaders);
if (typeof this._userAgent !== "undefined")
networkAgent.setUserAgentOverride(this._userAgent);
- if (this._networkConditions) {
- networkAgent.emulateNetworkConditions(this._networkConditions.offline, this._networkConditions.latency,
- this._networkConditions.throughput, this._networkConditions.throughput);
- }
},
/**
@@ -629,20 +669,6 @@ WebInspector.MultitargetNetworkManager.prototype = {
this._userAgent = userAgent;
for (var target of WebInspector.targetManager.targets())
target.networkAgent().setUserAgentOverride(this._userAgent);
- },
-
- /**
- * @param {boolean} offline
- * @param {number} latency
- * @param {number} throughput
- */
- emulateNetworkConditions: function(offline, latency, throughput)
- {
- this._networkConditions = { offline: offline, latency: latency, throughput: throughput };
- for (var target of WebInspector.targetManager.targets()) {
- target.networkAgent().emulateNetworkConditions(this._networkConditions.offline, this._networkConditions.latency,
- this._networkConditions.throughput, this._networkConditions.throughput);
- }
}
}
« no previous file with comments | « Source/devtools/front_end/network/NetworkPanel.js ('k') | Source/devtools/front_end/ui/Toolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698