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

Side by Side Diff: chrome/browser/resources/net_internals/browser_bridge.js

Issue 679103004: Add function to get network stack state from a URLRequestContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to comments Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/net_internals/net_internals_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Populated by constants from the browser. Used only by this file.
6 var NetInfoSources = null;
7
5 /** 8 /**
6 * This class provides a "bridge" for communicating between the javascript and 9 * This class provides a "bridge" for communicating between the javascript and
7 * the browser. 10 * the browser.
8 */ 11 */
9 var BrowserBridge = (function() { 12 var BrowserBridge = (function() {
10 'use strict'; 13 'use strict';
11 14
12 /** 15 /**
13 * Delay in milliseconds between updates of certain browser information. 16 * Delay in milliseconds between updates of certain browser information.
14 */ 17 */
(...skipping 11 matching lines...) Expand all
26 this.constantsObservers_ = []; 29 this.constantsObservers_ = [];
27 this.crosONCFileParseObservers_ = []; 30 this.crosONCFileParseObservers_ = [];
28 this.storeDebugLogsObservers_ = []; 31 this.storeDebugLogsObservers_ = [];
29 this.setNetworkDebugModeObservers_ = []; 32 this.setNetworkDebugModeObservers_ = [];
30 // Unprocessed data received before the constants. This serves to protect 33 // Unprocessed data received before the constants. This serves to protect
31 // against passing along data before having information on how to interpret 34 // against passing along data before having information on how to interpret
32 // it. 35 // it.
33 this.earlyReceivedData_ = []; 36 this.earlyReceivedData_ = [];
34 37
35 this.pollableDataHelpers_ = {}; 38 this.pollableDataHelpers_ = {};
36 this.pollableDataHelpers_.proxySettings = 39
37 new PollableDataHelper('onProxySettingsChanged', 40 // Add PollableDataHelpers for NetInfoSources, which retrieve information
38 this.sendGetProxySettings.bind(this)); 41 // directly from the network stack.
39 this.pollableDataHelpers_.badProxies = 42 this.addNetInfoPollableDataHelper('proxySettings',
40 new PollableDataHelper('onBadProxiesChanged', 43 'onProxySettingsChanged');
41 this.sendGetBadProxies.bind(this)); 44 this.addNetInfoPollableDataHelper('badProxies', 'onBadProxiesChanged');
42 this.pollableDataHelpers_.httpCacheInfo = 45 this.addNetInfoPollableDataHelper('hostResolverInfo',
43 new PollableDataHelper('onHttpCacheInfoChanged', 46 'onHostResolverInfoChanged');
44 this.sendGetHttpCacheInfo.bind(this)); 47 this.addNetInfoPollableDataHelper('socketPoolInfo',
45 this.pollableDataHelpers_.hostResolverInfo = 48 'onSocketPoolInfoChanged');
46 new PollableDataHelper('onHostResolverInfoChanged', 49 this.addNetInfoPollableDataHelper('spdySessionInfo',
47 this.sendGetHostResolverInfo.bind(this)); 50 'onSpdySessionInfoChanged');
48 this.pollableDataHelpers_.socketPoolInfo = 51 this.addNetInfoPollableDataHelper('spdyStatus', 'onSpdyStatusChanged');
49 new PollableDataHelper('onSocketPoolInfoChanged', 52 this.addNetInfoPollableDataHelper('spdyAlternateProtocolMappings',
50 this.sendGetSocketPoolInfo.bind(this)); 53 'onSpdyAlternateProtocolMappingsChanged');
54 this.addNetInfoPollableDataHelper('quicInfo', 'onQuicInfoChanged');
55 this.addNetInfoPollableDataHelper('httpCacheInfo',
56 'onHttpCacheInfoChanged');
57
58 // Add other PollableDataHelpers.
51 this.pollableDataHelpers_.sessionNetworkStats = 59 this.pollableDataHelpers_.sessionNetworkStats =
52 new PollableDataHelper('onSessionNetworkStatsChanged', 60 new PollableDataHelper('onSessionNetworkStatsChanged',
53 this.sendGetSessionNetworkStats.bind(this)); 61 this.sendGetSessionNetworkStats.bind(this));
54 this.pollableDataHelpers_.historicNetworkStats = 62 this.pollableDataHelpers_.historicNetworkStats =
55 new PollableDataHelper('onHistoricNetworkStatsChanged', 63 new PollableDataHelper('onHistoricNetworkStatsChanged',
56 this.sendGetHistoricNetworkStats.bind(this)); 64 this.sendGetHistoricNetworkStats.bind(this));
57 this.pollableDataHelpers_.quicInfo =
58 new PollableDataHelper('onQuicInfoChanged',
59 this.sendGetQuicInfo.bind(this));
60 this.pollableDataHelpers_.spdySessionInfo =
61 new PollableDataHelper('onSpdySessionInfoChanged',
62 this.sendGetSpdySessionInfo.bind(this));
63 this.pollableDataHelpers_.spdyStatus =
64 new PollableDataHelper('onSpdyStatusChanged',
65 this.sendGetSpdyStatus.bind(this));
66 this.pollableDataHelpers_.spdyAlternateProtocolMappings =
67 new PollableDataHelper('onSpdyAlternateProtocolMappingsChanged',
68 this.sendGetSpdyAlternateProtocolMappings.bind(
69 this));
70 if (cr.isWindows) { 65 if (cr.isWindows) {
71 this.pollableDataHelpers_.serviceProviders = 66 this.pollableDataHelpers_.serviceProviders =
72 new PollableDataHelper('onServiceProvidersChanged', 67 new PollableDataHelper('onServiceProvidersChanged',
73 this.sendGetServiceProviders.bind(this)); 68 this.sendGetServiceProviders.bind(this));
74 } 69 }
75 this.pollableDataHelpers_.prerenderInfo = 70 this.pollableDataHelpers_.prerenderInfo =
76 new PollableDataHelper('onPrerenderInfoChanged', 71 new PollableDataHelper('onPrerenderInfoChanged',
77 this.sendGetPrerenderInfo.bind(this)); 72 this.sendGetPrerenderInfo.bind(this));
78 this.pollableDataHelpers_.extensionInfo = 73 this.pollableDataHelpers_.extensionInfo =
79 new PollableDataHelper('onExtensionInfoChanged', 74 new PollableDataHelper('onExtensionInfoChanged',
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 this.pollIntervalId_ = null; 128 this.pollIntervalId_ = null;
134 } 129 }
135 130
136 if (intervalMs > 0) { 131 if (intervalMs > 0) {
137 this.pollIntervalId_ = 132 this.pollIntervalId_ =
138 window.setInterval(this.checkForUpdatedInfo.bind(this, false), 133 window.setInterval(this.checkForUpdatedInfo.bind(this, false),
139 intervalMs); 134 intervalMs);
140 } 135 }
141 }, 136 },
142 137
143 sendGetProxySettings: function() { 138 sendGetNetInfo: function(netInfoSource) {
144 // The browser will call receivedProxySettings on completion. 139 // If don't have constants yet, don't do anything yet.
145 this.send('getProxySettings'); 140 if (NetInfoSources)
141 this.send('getNetInfo', [NetInfoSources[netInfoSource]]);
146 }, 142 },
147 143
148 sendReloadProxySettings: function() { 144 sendReloadProxySettings: function() {
149 this.send('reloadProxySettings'); 145 this.send('reloadProxySettings');
150 }, 146 },
151 147
152 sendGetBadProxies: function() {
153 // The browser will call receivedBadProxies on completion.
154 this.send('getBadProxies');
155 },
156
157 sendGetHostResolverInfo: function() {
158 // The browser will call receivedHostResolverInfo on completion.
159 this.send('getHostResolverInfo');
160 },
161
162 sendClearBadProxies: function() { 148 sendClearBadProxies: function() {
163 this.send('clearBadProxies'); 149 this.send('clearBadProxies');
164 }, 150 },
165 151
166 sendClearHostResolverCache: function() { 152 sendClearHostResolverCache: function() {
167 this.send('clearHostResolverCache'); 153 this.send('clearHostResolverCache');
168 }, 154 },
169 155
170 sendClearBrowserCache: function() { 156 sendClearBrowserCache: function() {
171 this.send('clearBrowserCache'); 157 this.send('clearBrowserCache');
(...skipping 15 matching lines...) Expand all
187 sendHSTSAdd: function(domain, sts_include_subdomains, 173 sendHSTSAdd: function(domain, sts_include_subdomains,
188 pkp_include_subdomains, pins) { 174 pkp_include_subdomains, pins) {
189 this.send('hstsAdd', [domain, sts_include_subdomains, 175 this.send('hstsAdd', [domain, sts_include_subdomains,
190 pkp_include_subdomains, pins]); 176 pkp_include_subdomains, pins]);
191 }, 177 },
192 178
193 sendHSTSDelete: function(domain) { 179 sendHSTSDelete: function(domain) {
194 this.send('hstsDelete', [domain]); 180 this.send('hstsDelete', [domain]);
195 }, 181 },
196 182
197 sendGetHttpCacheInfo: function() {
198 this.send('getHttpCacheInfo');
199 },
200
201 sendGetSocketPoolInfo: function() {
202 this.send('getSocketPoolInfo');
203 },
204
205 sendGetSessionNetworkStats: function() { 183 sendGetSessionNetworkStats: function() {
206 this.send('getSessionNetworkStats'); 184 this.send('getSessionNetworkStats');
207 }, 185 },
208 186
209 sendGetHistoricNetworkStats: function() { 187 sendGetHistoricNetworkStats: function() {
210 this.send('getHistoricNetworkStats'); 188 this.send('getHistoricNetworkStats');
211 }, 189 },
212 190
213 sendCloseIdleSockets: function() { 191 sendCloseIdleSockets: function() {
214 this.send('closeIdleSockets'); 192 this.send('closeIdleSockets');
215 }, 193 },
216 194
217 sendFlushSocketPools: function() { 195 sendFlushSocketPools: function() {
218 this.send('flushSocketPools'); 196 this.send('flushSocketPools');
219 }, 197 },
220 198
221 sendGetQuicInfo: function() {
222 this.send('getQuicInfo');
223 },
224
225 sendGetSpdySessionInfo: function() {
226 this.send('getSpdySessionInfo');
227 },
228
229 sendGetSpdyStatus: function() {
230 this.send('getSpdyStatus');
231 },
232
233 sendGetSpdyAlternateProtocolMappings: function() {
234 this.send('getSpdyAlternateProtocolMappings');
235 },
236
237 sendGetServiceProviders: function() { 199 sendGetServiceProviders: function() {
238 this.send('getServiceProviders'); 200 this.send('getServiceProviders');
239 }, 201 },
240 202
241 sendGetPrerenderInfo: function() { 203 sendGetPrerenderInfo: function() {
242 this.send('getPrerenderInfo'); 204 this.send('getPrerenderInfo');
243 }, 205 },
244 206
245 sendGetExtensionInfo: function() { 207 sendGetExtensionInfo: function() {
246 this.send('getExtensionInfo'); 208 this.send('getExtensionInfo');
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 if (this.earlyReceivedData_ != null) { 259 if (this.earlyReceivedData_ != null) {
298 for (var i = 0; i < this.earlyReceivedData_.length; i++) { 260 for (var i = 0; i < this.earlyReceivedData_.length; i++) {
299 var command = this.earlyReceivedData_[i]; 261 var command = this.earlyReceivedData_[i];
300 this[command.command](command.params); 262 this[command.command](command.params);
301 } 263 }
302 this.earlyReceivedData_ = null; 264 this.earlyReceivedData_ = null;
303 } 265 }
304 }, 266 },
305 267
306 receivedConstants: function(constants) { 268 receivedConstants: function(constants) {
269 NetInfoSources = constants.netInfoSources;
307 for (var i = 0; i < this.constantsObservers_.length; i++) 270 for (var i = 0; i < this.constantsObservers_.length; i++)
308 this.constantsObservers_[i].onReceivedConstants(constants); 271 this.constantsObservers_[i].onReceivedConstants(constants);
272 // May have been waiting for the constants to be received before getting
273 // information for the currently displayed tab.
274 this.checkForUpdatedInfo();
309 }, 275 },
310 276
311 receivedLogEntries: function(logEntries) { 277 receivedLogEntries: function(logEntries) {
312 EventsTracker.getInstance().addLogEntries(logEntries); 278 EventsTracker.getInstance().addLogEntries(logEntries);
313 }, 279 },
314 280
315 receivedProxySettings: function(proxySettings) { 281 receivedNetInfo: function(netInfo) {
316 this.pollableDataHelpers_.proxySettings.update(proxySettings); 282 // Dispatch |netInfo| to the various PollableDataHelpers listening to
317 }, 283 // each field it contains.
318 284 //
319 receivedBadProxies: function(badProxies) { 285 // Currently information is only received from one source at a time, but
320 this.pollableDataHelpers_.badProxies.update(badProxies); 286 // the API does allow for data from more that one to be requested at once.
321 }, 287 for (var source in netInfo)
322 288 this.pollableDataHelpers_[source].update(netInfo[source]);
323 receivedHostResolverInfo: function(hostResolverInfo) {
324 this.pollableDataHelpers_.hostResolverInfo.update(hostResolverInfo);
325 },
326
327 receivedSocketPoolInfo: function(socketPoolInfo) {
328 this.pollableDataHelpers_.socketPoolInfo.update(socketPoolInfo);
329 }, 289 },
330 290
331 receivedSessionNetworkStats: function(sessionNetworkStats) { 291 receivedSessionNetworkStats: function(sessionNetworkStats) {
332 this.pollableDataHelpers_.sessionNetworkStats.update(sessionNetworkStats); 292 this.pollableDataHelpers_.sessionNetworkStats.update(sessionNetworkStats);
333 }, 293 },
334 294
335 receivedHistoricNetworkStats: function(historicNetworkStats) { 295 receivedHistoricNetworkStats: function(historicNetworkStats) {
336 this.pollableDataHelpers_.historicNetworkStats.update( 296 this.pollableDataHelpers_.historicNetworkStats.update(
337 historicNetworkStats); 297 historicNetworkStats);
338 }, 298 },
339 299
340 receivedQuicInfo: function(quicInfo) {
341 this.pollableDataHelpers_.quicInfo.update(quicInfo);
342 },
343
344 receivedSpdySessionInfo: function(spdySessionInfo) {
345 this.pollableDataHelpers_.spdySessionInfo.update(spdySessionInfo);
346 },
347
348 receivedSpdyStatus: function(spdyStatus) {
349 this.pollableDataHelpers_.spdyStatus.update(spdyStatus);
350 },
351
352 receivedSpdyAlternateProtocolMappings:
353 function(spdyAlternateProtocolMappings) {
354 this.pollableDataHelpers_.spdyAlternateProtocolMappings.update(
355 spdyAlternateProtocolMappings);
356 },
357
358 receivedServiceProviders: function(serviceProviders) { 300 receivedServiceProviders: function(serviceProviders) {
359 this.pollableDataHelpers_.serviceProviders.update(serviceProviders); 301 this.pollableDataHelpers_.serviceProviders.update(serviceProviders);
360 }, 302 },
361 303
362 receivedStartConnectionTestSuite: function() { 304 receivedStartConnectionTestSuite: function() {
363 for (var i = 0; i < this.connectionTestsObservers_.length; i++) 305 for (var i = 0; i < this.connectionTestsObservers_.length; i++)
364 this.connectionTestsObservers_[i].onStartedConnectionTestSuite(); 306 this.connectionTestsObservers_[i].onStartedConnectionTestSuite();
365 }, 307 },
366 308
367 receivedStartConnectionTestExperiment: function(experiment) { 309 receivedStartConnectionTestExperiment: function(experiment) {
(...skipping 28 matching lines...) Expand all
396 receivedStoreDebugLogs: function(status) { 338 receivedStoreDebugLogs: function(status) {
397 for (var i = 0; i < this.storeDebugLogsObservers_.length; i++) 339 for (var i = 0; i < this.storeDebugLogsObservers_.length; i++)
398 this.storeDebugLogsObservers_[i].onStoreDebugLogs(status); 340 this.storeDebugLogsObservers_[i].onStoreDebugLogs(status);
399 }, 341 },
400 342
401 receivedSetNetworkDebugMode: function(status) { 343 receivedSetNetworkDebugMode: function(status) {
402 for (var i = 0; i < this.setNetworkDebugModeObservers_.length; i++) 344 for (var i = 0; i < this.setNetworkDebugModeObservers_.length; i++)
403 this.setNetworkDebugModeObservers_[i].onSetNetworkDebugMode(status); 345 this.setNetworkDebugModeObservers_[i].onSetNetworkDebugMode(status);
404 }, 346 },
405 347
406 receivedHttpCacheInfo: function(info) {
407 this.pollableDataHelpers_.httpCacheInfo.update(info);
408 },
409
410 receivedPrerenderInfo: function(prerenderInfo) { 348 receivedPrerenderInfo: function(prerenderInfo) {
411 this.pollableDataHelpers_.prerenderInfo.update(prerenderInfo); 349 this.pollableDataHelpers_.prerenderInfo.update(prerenderInfo);
412 }, 350 },
413 351
414 receivedExtensionInfo: function(extensionInfo) { 352 receivedExtensionInfo: function(extensionInfo) {
415 this.pollableDataHelpers_.extensionInfo.update(extensionInfo); 353 this.pollableDataHelpers_.extensionInfo.update(extensionInfo);
416 }, 354 },
417 355
418 getSystemLogCallback: function(systemLog) { 356 getSystemLogCallback: function(systemLog) {
419 this.pollableDataHelpers_.systemLog.update(systemLog); 357 this.pollableDataHelpers_.systemLog.update(systemLog);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 }, 643 },
706 644
707 /** 645 /**
708 * Calls all startUpdate functions and, if |callback| is non-null, 646 * Calls all startUpdate functions and, if |callback| is non-null,
709 * calls it with the results of all updates. 647 * calls it with the results of all updates.
710 */ 648 */
711 updateAllInfo: function(callback) { 649 updateAllInfo: function(callback) {
712 if (callback) 650 if (callback)
713 new UpdateAllObserver(callback, this.pollableDataHelpers_); 651 new UpdateAllObserver(callback, this.pollableDataHelpers_);
714 this.checkForUpdatedInfo(true); 652 this.checkForUpdatedInfo(true);
715 } 653 },
654
655 /**
656 * Adds a PollableDataHelper that listens to the specified NetInfoSource.
657 */
658 addNetInfoPollableDataHelper: function(sourceName, observerMethodName) {
659 this.pollableDataHelpers_[sourceName] = new PollableDataHelper(
660 observerMethodName, this.sendGetNetInfo.bind(this, sourceName));
661 },
716 }; 662 };
717 663
718 /** 664 /**
719 * This is a helper class used by BrowserBridge, to keep track of: 665 * This is a helper class used by BrowserBridge, to keep track of:
720 * - the list of observers interested in some piece of data. 666 * - the list of observers interested in some piece of data.
721 * - the last known value of that piece of data. 667 * - the last known value of that piece of data.
722 * - the name of the callback method to invoke on observers. 668 * - the name of the callback method to invoke on observers.
723 * - the update function. 669 * - the update function.
724 * @constructor 670 * @constructor
725 */ 671 */
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 helper.removeObserver(this); 791 helper.removeObserver(this);
846 --this.observingCount_; 792 --this.observingCount_;
847 this.updatedData_[name] = data; 793 this.updatedData_[name] = data;
848 if (this.observingCount_ == 0) 794 if (this.observingCount_ == 0)
849 this.callback_(this.updatedData_); 795 this.callback_(this.updatedData_);
850 } 796 }
851 }; 797 };
852 798
853 return BrowserBridge; 799 return BrowserBridge;
854 })(); 800 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/net_internals/net_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698