Index: chrome/browser/resources/net_internals/browser_bridge.js |
=================================================================== |
--- chrome/browser/resources/net_internals/browser_bridge.js (revision 94938) |
+++ chrome/browser/resources/net_internals/browser_bridge.js (working copy) |
@@ -66,6 +66,9 @@ |
// and no messages will be sent to the browser, either. Intended for use |
// when viewing log files. |
this.disabled_ = false; |
+ |
+ // Interval id returned by window.setInterval for polling timer. |
+ this.pollIntervalId_ = null; |
} |
cr.addSingletonGetter(BrowserBridge); |
@@ -93,12 +96,27 @@ |
sendReady: function() { |
this.send('notifyReady'); |
+ this.setPollInterval(POLL_INTERVAL_MS); |
+ }, |
- // Some of the data we are interested is not currently exposed as a |
- // stream, so we will poll the browser to find out when it changes and |
- // then notify the observers. |
- window.setInterval(this.checkForUpdatedInfo.bind(this, false), |
- POLL_INTERVAL_MS); |
+ /** |
+ * Some of the data we are interested is not currently exposed as a |
+ * stream. This starts polling those with active observers (visible |
+ * views) every |intervalMs|. Subsequent calls override previous calls |
+ * to this function. If |intervalMs| is 0, stops polling. Function only |
+ * exposed for unit testing. |
+ */ |
+ setPollInterval: function(intervalMs) { |
+ if (this.pollIntervalId_ !== null) { |
+ window.clearInterval(this.pollIntervalId_); |
+ this.pollIntervalId_ = null; |
+ } |
+ |
+ if (intervalMs > 0) { |
+ this.pollIntervalId_ = |
+ window.setInterval(this.checkForUpdatedInfo.bind(this, false), |
+ intervalMs); |
+ } |
}, |
sendGetProxySettings: function() { |