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

Side by Side Diff: chrome/browser/ui/webui/net_internals/net_internals_ui.cc

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
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 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" 5 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "content/public/browser/browser_thread.h" 49 #include "content/public/browser/browser_thread.h"
50 #include "content/public/browser/notification_details.h" 50 #include "content/public/browser/notification_details.h"
51 #include "content/public/browser/resource_dispatcher_host.h" 51 #include "content/public/browser/resource_dispatcher_host.h"
52 #include "content/public/browser/web_contents.h" 52 #include "content/public/browser/web_contents.h"
53 #include "content/public/browser/web_ui.h" 53 #include "content/public/browser/web_ui.h"
54 #include "content/public/browser/web_ui_data_source.h" 54 #include "content/public/browser/web_ui_data_source.h"
55 #include "content/public/browser/web_ui_message_handler.h" 55 #include "content/public/browser/web_ui_message_handler.h"
56 #include "grit/net_internals_resources.h" 56 #include "grit/net_internals_resources.h"
57 #include "net/base/net_errors.h" 57 #include "net/base/net_errors.h"
58 #include "net/base/net_log_logger.h" 58 #include "net/base/net_log_logger.h"
59 #include "net/base/net_log_util.h"
59 #include "net/base/net_util.h" 60 #include "net/base/net_util.h"
60 #include "net/disk_cache/disk_cache.h" 61 #include "net/disk_cache/disk_cache.h"
61 #include "net/dns/host_cache.h" 62 #include "net/dns/host_cache.h"
62 #include "net/dns/host_resolver.h" 63 #include "net/dns/host_resolver.h"
63 #include "net/http/http_cache.h" 64 #include "net/http/http_cache.h"
64 #include "net/http/http_network_layer.h" 65 #include "net/http/http_network_layer.h"
65 #include "net/http/http_network_session.h" 66 #include "net/http/http_network_session.h"
66 #include "net/http/http_server_properties.h" 67 #include "net/http/http_server_properties.h"
67 #include "net/http/http_stream_factory.h" 68 #include "net/http/http_stream_factory.h"
68 #include "net/http/transport_security_state.h" 69 #include "net/http/transport_security_state.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 net::NetLog::LogLevel log_level) { 156 net::NetLog::LogLevel log_level) {
156 return request->GetStateAsValue(); 157 return request->GetStateAsValue();
157 } 158 }
158 159
159 // Returns true if |request1| was created before |request2|. 160 // Returns true if |request1| was created before |request2|.
160 bool RequestCreatedBefore(const net::URLRequest* request1, 161 bool RequestCreatedBefore(const net::URLRequest* request1,
161 const net::URLRequest* request2) { 162 const net::URLRequest* request2) {
162 return request1->creation_time() < request2->creation_time(); 163 return request1->creation_time() < request2->creation_time();
163 } 164 }
164 165
165 // Returns the disk cache backend for |context| if there is one, or NULL.
166 disk_cache::Backend* GetDiskCacheBackend(net::URLRequestContext* context) {
167 if (!context->http_transaction_factory())
168 return NULL;
169
170 net::HttpCache* http_cache = context->http_transaction_factory()->GetCache();
171 if (!http_cache)
172 return NULL;
173
174 return http_cache->GetCurrentBackend();
175 }
176
177 // Returns the http network session for |context| if there is one. 166 // Returns the http network session for |context| if there is one.
178 // Otherwise, returns NULL. 167 // Otherwise, returns NULL.
179 net::HttpNetworkSession* GetHttpNetworkSession( 168 net::HttpNetworkSession* GetHttpNetworkSession(
180 net::URLRequestContext* context) { 169 net::URLRequestContext* context) {
181 if (!context->http_transaction_factory()) 170 if (!context->http_transaction_factory())
182 return NULL; 171 return NULL;
183 172
184 return context->http_transaction_factory()->GetSession(); 173 return context->http_transaction_factory()->GetSession();
185 } 174 }
186 175
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // Called when the WebUI is deleted. Prevents calling Javascript functions 366 // Called when the WebUI is deleted. Prevents calling Javascript functions
378 // afterwards. Called on UI thread. 367 // afterwards. Called on UI thread.
379 void OnWebUIDeleted(); 368 void OnWebUIDeleted();
380 369
381 //-------------------------------- 370 //--------------------------------
382 // Javascript message handlers: 371 // Javascript message handlers:
383 //-------------------------------- 372 //--------------------------------
384 373
385 void OnRendererReady(const base::ListValue* list); 374 void OnRendererReady(const base::ListValue* list);
386 375
387 void OnGetProxySettings(const base::ListValue* list); 376 void OnGetNetInfo(const base::ListValue* list);
388 void OnReloadProxySettings(const base::ListValue* list); 377 void OnReloadProxySettings(const base::ListValue* list);
389 void OnGetBadProxies(const base::ListValue* list);
390 void OnClearBadProxies(const base::ListValue* list); 378 void OnClearBadProxies(const base::ListValue* list);
391 void OnGetHostResolverInfo(const base::ListValue* list);
392 void OnClearHostResolverCache(const base::ListValue* list); 379 void OnClearHostResolverCache(const base::ListValue* list);
393 void OnEnableIPv6(const base::ListValue* list); 380 void OnEnableIPv6(const base::ListValue* list);
394 void OnStartConnectionTests(const base::ListValue* list); 381 void OnStartConnectionTests(const base::ListValue* list);
395 void OnHSTSQuery(const base::ListValue* list); 382 void OnHSTSQuery(const base::ListValue* list);
396 void OnHSTSAdd(const base::ListValue* list); 383 void OnHSTSAdd(const base::ListValue* list);
397 void OnHSTSDelete(const base::ListValue* list); 384 void OnHSTSDelete(const base::ListValue* list);
398 void OnGetHttpCacheInfo(const base::ListValue* list);
399 void OnGetSocketPoolInfo(const base::ListValue* list);
400 void OnGetSessionNetworkStats(const base::ListValue* list); 385 void OnGetSessionNetworkStats(const base::ListValue* list);
401 void OnCloseIdleSockets(const base::ListValue* list); 386 void OnCloseIdleSockets(const base::ListValue* list);
402 void OnFlushSocketPools(const base::ListValue* list); 387 void OnFlushSocketPools(const base::ListValue* list);
403 void OnGetSpdySessionInfo(const base::ListValue* list);
404 void OnGetSpdyStatus(const base::ListValue* list);
405 void OnGetSpdyAlternateProtocolMappings(const base::ListValue* list);
406 void OnGetQuicInfo(const base::ListValue* list);
407 #if defined(OS_WIN) 388 #if defined(OS_WIN)
408 void OnGetServiceProviders(const base::ListValue* list); 389 void OnGetServiceProviders(const base::ListValue* list);
409 #endif 390 #endif
410 void OnSetLogLevel(const base::ListValue* list); 391 void OnSetLogLevel(const base::ListValue* list);
411 392
412 // ChromeNetLog::ThreadSafeObserver implementation: 393 // ChromeNetLog::ThreadSafeObserver implementation:
413 void OnAddEntry(const net::NetLog::Entry& entry) override; 394 void OnAddEntry(const net::NetLog::Entry& entry) override;
414 395
415 // ConnectionTester::Delegate implementation: 396 // ConnectionTester::Delegate implementation:
416 void OnStartConnectionTestSuite() override; 397 void OnStartConnectionTestSuite() override;
(...skipping 30 matching lines...) Expand all
447 // Must be called on the IO Thread. 428 // Must be called on the IO Thread.
448 void PostPendingEntries(); 429 void PostPendingEntries();
449 430
450 // Adds entries with the states of ongoing URL requests. 431 // Adds entries with the states of ongoing URL requests.
451 void PrePopulateEventList(); 432 void PrePopulateEventList();
452 433
453 net::URLRequestContext* GetMainContext() { 434 net::URLRequestContext* GetMainContext() {
454 return main_context_getter_->GetURLRequestContext(); 435 return main_context_getter_->GetURLRequestContext();
455 } 436 }
456 437
438 // |info_sources| is an or'd together list of the net::NetInfoSources to
439 // send information about. Information is sent to Javascript in the form of
440 // a single dictionary with information about all requests sources.
441 void SendNetInfo(int info_sources);
442
457 // Pointer to the UI-thread message handler. Only access this from 443 // Pointer to the UI-thread message handler. Only access this from
458 // the UI thread. 444 // the UI thread.
459 base::WeakPtr<NetInternalsMessageHandler> handler_; 445 base::WeakPtr<NetInternalsMessageHandler> handler_;
460 446
461 // The global IOThread, which contains the global NetLog to observer. 447 // The global IOThread, which contains the global NetLog to observer.
462 IOThread* io_thread_; 448 IOThread* io_thread_;
463 449
464 // The main URLRequestContextGetter for the tab's profile. 450 // The main URLRequestContextGetter for the tab's profile.
465 scoped_refptr<net::URLRequestContextGetter> main_context_getter_; 451 scoped_refptr<net::URLRequestContextGetter> main_context_getter_;
466 452
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 prerender_manager_ = prerender_manager->AsWeakPtr(); 511 prerender_manager_ = prerender_manager->AsWeakPtr();
526 } else { 512 } else {
527 prerender_manager_ = base::WeakPtr<prerender::PrerenderManager>(); 513 prerender_manager_ = base::WeakPtr<prerender::PrerenderManager>();
528 } 514 }
529 515
530 web_ui()->RegisterMessageCallback( 516 web_ui()->RegisterMessageCallback(
531 "notifyReady", 517 "notifyReady",
532 base::Bind(&NetInternalsMessageHandler::OnRendererReady, 518 base::Bind(&NetInternalsMessageHandler::OnRendererReady,
533 base::Unretained(this))); 519 base::Unretained(this)));
534 web_ui()->RegisterMessageCallback( 520 web_ui()->RegisterMessageCallback(
535 "getProxySettings", 521 "getNetInfo",
536 base::Bind(&IOThreadImpl::CallbackHelper, 522 base::Bind(&IOThreadImpl::CallbackHelper,
537 &IOThreadImpl::OnGetProxySettings, proxy_)); 523 &IOThreadImpl::OnGetNetInfo, proxy_));
538 web_ui()->RegisterMessageCallback( 524 web_ui()->RegisterMessageCallback(
539 "reloadProxySettings", 525 "reloadProxySettings",
540 base::Bind(&IOThreadImpl::CallbackHelper, 526 base::Bind(&IOThreadImpl::CallbackHelper,
541 &IOThreadImpl::OnReloadProxySettings, proxy_)); 527 &IOThreadImpl::OnReloadProxySettings, proxy_));
542 web_ui()->RegisterMessageCallback( 528 web_ui()->RegisterMessageCallback(
543 "getBadProxies",
544 base::Bind(&IOThreadImpl::CallbackHelper,
545 &IOThreadImpl::OnGetBadProxies, proxy_));
546 web_ui()->RegisterMessageCallback(
547 "clearBadProxies", 529 "clearBadProxies",
548 base::Bind(&IOThreadImpl::CallbackHelper, 530 base::Bind(&IOThreadImpl::CallbackHelper,
549 &IOThreadImpl::OnClearBadProxies, proxy_)); 531 &IOThreadImpl::OnClearBadProxies, proxy_));
550 web_ui()->RegisterMessageCallback( 532 web_ui()->RegisterMessageCallback(
551 "getHostResolverInfo",
552 base::Bind(&IOThreadImpl::CallbackHelper,
553 &IOThreadImpl::OnGetHostResolverInfo, proxy_));
554 web_ui()->RegisterMessageCallback(
555 "clearHostResolverCache", 533 "clearHostResolverCache",
556 base::Bind(&IOThreadImpl::CallbackHelper, 534 base::Bind(&IOThreadImpl::CallbackHelper,
557 &IOThreadImpl::OnClearHostResolverCache, proxy_)); 535 &IOThreadImpl::OnClearHostResolverCache, proxy_));
558 web_ui()->RegisterMessageCallback( 536 web_ui()->RegisterMessageCallback(
559 "enableIPv6", 537 "enableIPv6",
560 base::Bind(&IOThreadImpl::CallbackHelper, 538 base::Bind(&IOThreadImpl::CallbackHelper,
561 &IOThreadImpl::OnEnableIPv6, proxy_)); 539 &IOThreadImpl::OnEnableIPv6, proxy_));
562 web_ui()->RegisterMessageCallback( 540 web_ui()->RegisterMessageCallback(
563 "startConnectionTests", 541 "startConnectionTests",
564 base::Bind(&IOThreadImpl::CallbackHelper, 542 base::Bind(&IOThreadImpl::CallbackHelper,
565 &IOThreadImpl::OnStartConnectionTests, proxy_)); 543 &IOThreadImpl::OnStartConnectionTests, proxy_));
566 web_ui()->RegisterMessageCallback( 544 web_ui()->RegisterMessageCallback(
567 "hstsQuery", 545 "hstsQuery",
568 base::Bind(&IOThreadImpl::CallbackHelper, 546 base::Bind(&IOThreadImpl::CallbackHelper,
569 &IOThreadImpl::OnHSTSQuery, proxy_)); 547 &IOThreadImpl::OnHSTSQuery, proxy_));
570 web_ui()->RegisterMessageCallback( 548 web_ui()->RegisterMessageCallback(
571 "hstsAdd", 549 "hstsAdd",
572 base::Bind(&IOThreadImpl::CallbackHelper, 550 base::Bind(&IOThreadImpl::CallbackHelper,
573 &IOThreadImpl::OnHSTSAdd, proxy_)); 551 &IOThreadImpl::OnHSTSAdd, proxy_));
574 web_ui()->RegisterMessageCallback( 552 web_ui()->RegisterMessageCallback(
575 "hstsDelete", 553 "hstsDelete",
576 base::Bind(&IOThreadImpl::CallbackHelper, 554 base::Bind(&IOThreadImpl::CallbackHelper,
577 &IOThreadImpl::OnHSTSDelete, proxy_)); 555 &IOThreadImpl::OnHSTSDelete, proxy_));
578 web_ui()->RegisterMessageCallback( 556 web_ui()->RegisterMessageCallback(
579 "getHttpCacheInfo",
580 base::Bind(&IOThreadImpl::CallbackHelper,
581 &IOThreadImpl::OnGetHttpCacheInfo, proxy_));
582 web_ui()->RegisterMessageCallback(
583 "getSocketPoolInfo",
584 base::Bind(&IOThreadImpl::CallbackHelper,
585 &IOThreadImpl::OnGetSocketPoolInfo, proxy_));
586 web_ui()->RegisterMessageCallback(
587 "getSessionNetworkStats", 557 "getSessionNetworkStats",
588 base::Bind(&IOThreadImpl::CallbackHelper, 558 base::Bind(&IOThreadImpl::CallbackHelper,
589 &IOThreadImpl::OnGetSessionNetworkStats, proxy_)); 559 &IOThreadImpl::OnGetSessionNetworkStats, proxy_));
590 web_ui()->RegisterMessageCallback( 560 web_ui()->RegisterMessageCallback(
591 "closeIdleSockets", 561 "closeIdleSockets",
592 base::Bind(&IOThreadImpl::CallbackHelper, 562 base::Bind(&IOThreadImpl::CallbackHelper,
593 &IOThreadImpl::OnCloseIdleSockets, proxy_)); 563 &IOThreadImpl::OnCloseIdleSockets, proxy_));
594 web_ui()->RegisterMessageCallback( 564 web_ui()->RegisterMessageCallback(
595 "flushSocketPools", 565 "flushSocketPools",
596 base::Bind(&IOThreadImpl::CallbackHelper, 566 base::Bind(&IOThreadImpl::CallbackHelper,
597 &IOThreadImpl::OnFlushSocketPools, proxy_)); 567 &IOThreadImpl::OnFlushSocketPools, proxy_));
598 web_ui()->RegisterMessageCallback(
599 "getSpdySessionInfo",
600 base::Bind(&IOThreadImpl::CallbackHelper,
601 &IOThreadImpl::OnGetSpdySessionInfo, proxy_));
602 web_ui()->RegisterMessageCallback(
603 "getSpdyStatus",
604 base::Bind(&IOThreadImpl::CallbackHelper,
605 &IOThreadImpl::OnGetSpdyStatus, proxy_));
606 web_ui()->RegisterMessageCallback(
607 "getSpdyAlternateProtocolMappings",
608 base::Bind(&IOThreadImpl::CallbackHelper,
609 &IOThreadImpl::OnGetSpdyAlternateProtocolMappings, proxy_));
610 web_ui()->RegisterMessageCallback(
611 "getQuicInfo",
612 base::Bind(&IOThreadImpl::CallbackHelper,
613 &IOThreadImpl::OnGetQuicInfo, proxy_));
614 #if defined(OS_WIN) 568 #if defined(OS_WIN)
615 web_ui()->RegisterMessageCallback( 569 web_ui()->RegisterMessageCallback(
616 "getServiceProviders", 570 "getServiceProviders",
617 base::Bind(&IOThreadImpl::CallbackHelper, 571 base::Bind(&IOThreadImpl::CallbackHelper,
618 &IOThreadImpl::OnGetServiceProviders, proxy_)); 572 &IOThreadImpl::OnGetServiceProviders, proxy_));
619 #endif 573 #endif
620 574
621 web_ui()->RegisterMessageCallback( 575 web_ui()->RegisterMessageCallback(
622 "setLogLevel", 576 "setLogLevel",
623 base::Bind(&IOThreadImpl::CallbackHelper, 577 base::Bind(&IOThreadImpl::CallbackHelper,
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 // Add entries for ongoing URL requests. 865 // Add entries for ongoing URL requests.
912 PrePopulateEventList(); 866 PrePopulateEventList();
913 867
914 if (!net_log()) { 868 if (!net_log()) {
915 // Register with network stack to observe events. 869 // Register with network stack to observe events.
916 io_thread_->net_log()->AddThreadSafeObserver(this, 870 io_thread_->net_log()->AddThreadSafeObserver(this,
917 net::NetLog::LOG_ALL_BUT_BYTES); 871 net::NetLog::LOG_ALL_BUT_BYTES);
918 } 872 }
919 } 873 }
920 874
921 void NetInternalsMessageHandler::IOThreadImpl::OnGetProxySettings( 875 void NetInternalsMessageHandler::IOThreadImpl::OnGetNetInfo(
922 const base::ListValue* list) { 876 const base::ListValue* list) {
923 DCHECK(!list); 877 DCHECK(list);
924 net::ProxyService* proxy_service = GetMainContext()->proxy_service(); 878 int info_sources;
925 879 if (!list->GetInteger(0, &info_sources))
926 base::DictionaryValue* dict = new base::DictionaryValue(); 880 return;
927 if (proxy_service->fetched_config().is_valid()) 881 SendNetInfo(info_sources);
928 dict->Set("original", proxy_service->fetched_config().ToValue());
929 if (proxy_service->config().is_valid())
930 dict->Set("effective", proxy_service->config().ToValue());
931
932 SendJavascriptCommand("receivedProxySettings", dict);
933 } 882 }
934 883
935 void NetInternalsMessageHandler::IOThreadImpl::OnReloadProxySettings( 884 void NetInternalsMessageHandler::IOThreadImpl::OnReloadProxySettings(
936 const base::ListValue* list) { 885 const base::ListValue* list) {
937 DCHECK(!list); 886 DCHECK(!list);
938 GetMainContext()->proxy_service()->ForceReloadProxyConfig(); 887 GetMainContext()->proxy_service()->ForceReloadProxyConfig();
939 888
940 // Cause the renderer to be notified of the new values. 889 // Cause the renderer to be notified of the new values.
941 OnGetProxySettings(NULL); 890 SendNetInfo(net::NET_INFO_PROXY_SETTINGS);
942 }
943
944 void NetInternalsMessageHandler::IOThreadImpl::OnGetBadProxies(
945 const base::ListValue* list) {
946 DCHECK(!list);
947
948 const net::ProxyRetryInfoMap& bad_proxies_map =
949 GetMainContext()->proxy_service()->proxy_retry_info();
950
951 base::ListValue* dict_list = new base::ListValue();
952
953 for (net::ProxyRetryInfoMap::const_iterator it = bad_proxies_map.begin();
954 it != bad_proxies_map.end(); ++it) {
955 const std::string& proxy_uri = it->first;
956 const net::ProxyRetryInfo& retry_info = it->second;
957
958 base::DictionaryValue* dict = new base::DictionaryValue();
959 dict->SetString("proxy_uri", proxy_uri);
960 dict->SetString("bad_until",
961 net::NetLog::TickCountToString(retry_info.bad_until));
962
963 dict_list->Append(dict);
964 }
965
966 SendJavascriptCommand("receivedBadProxies", dict_list);
967 } 891 }
968 892
969 void NetInternalsMessageHandler::IOThreadImpl::OnClearBadProxies( 893 void NetInternalsMessageHandler::IOThreadImpl::OnClearBadProxies(
970 const base::ListValue* list) { 894 const base::ListValue* list) {
971 DCHECK(!list); 895 DCHECK(!list);
972 GetMainContext()->proxy_service()->ClearBadProxiesCache(); 896 GetMainContext()->proxy_service()->ClearBadProxiesCache();
973 897
974 // Cause the renderer to be notified of the new values. 898 // Cause the renderer to be notified of the new values.
975 OnGetBadProxies(NULL); 899 SendNetInfo(net::NET_INFO_BAD_PROXIES);
976 }
977
978 void NetInternalsMessageHandler::IOThreadImpl::OnGetHostResolverInfo(
979 const base::ListValue* list) {
980 DCHECK(!list);
981 net::URLRequestContext* context = GetMainContext();
982 net::HostCache* cache = GetHostResolverCache(context);
983
984 if (!cache) {
985 SendJavascriptCommand("receivedHostResolverInfo", NULL);
986 return;
987 }
988
989 base::DictionaryValue* dict = new base::DictionaryValue();
990
991 base::Value* dns_config = context->host_resolver()->GetDnsConfigAsValue();
992 if (dns_config)
993 dict->Set("dns_config", dns_config);
994
995 dict->SetInteger(
996 "default_address_family",
997 static_cast<int>(context->host_resolver()->GetDefaultAddressFamily()));
998
999 base::DictionaryValue* cache_info_dict = new base::DictionaryValue();
1000
1001 cache_info_dict->SetInteger(
1002 "capacity",
1003 static_cast<int>(cache->max_entries()));
1004
1005 base::ListValue* entry_list = new base::ListValue();
1006
1007 net::HostCache::EntryMap::Iterator it(cache->entries());
1008 for (; it.HasNext(); it.Advance()) {
1009 const net::HostCache::Key& key = it.key();
1010 const net::HostCache::Entry& entry = it.value();
1011
1012 base::DictionaryValue* entry_dict = new base::DictionaryValue();
1013
1014 entry_dict->SetString("hostname", key.hostname);
1015 entry_dict->SetInteger("address_family",
1016 static_cast<int>(key.address_family));
1017 entry_dict->SetString("expiration",
1018 net::NetLog::TickCountToString(it.expiration()));
1019
1020 if (entry.error != net::OK) {
1021 entry_dict->SetInteger("error", entry.error);
1022 } else {
1023 // Append all of the resolved addresses.
1024 base::ListValue* address_list = new base::ListValue();
1025 for (size_t i = 0; i < entry.addrlist.size(); ++i) {
1026 address_list->AppendString(entry.addrlist[i].ToStringWithoutPort());
1027 }
1028 entry_dict->Set("addresses", address_list);
1029 }
1030
1031 entry_list->Append(entry_dict);
1032 }
1033
1034 cache_info_dict->Set("entries", entry_list);
1035 dict->Set("cache", cache_info_dict);
1036
1037 SendJavascriptCommand("receivedHostResolverInfo", dict);
1038 } 900 }
1039 901
1040 void NetInternalsMessageHandler::IOThreadImpl::OnClearHostResolverCache( 902 void NetInternalsMessageHandler::IOThreadImpl::OnClearHostResolverCache(
1041 const base::ListValue* list) { 903 const base::ListValue* list) {
1042 DCHECK(!list); 904 DCHECK(!list);
1043 net::HostCache* cache = GetHostResolverCache(GetMainContext()); 905 net::HostCache* cache = GetHostResolverCache(GetMainContext());
1044 906
1045 if (cache) 907 if (cache)
1046 cache->clear(); 908 cache->clear();
1047 909
1048 // Cause the renderer to be notified of the new values. 910 // Cause the renderer to be notified of the new values.
1049 OnGetHostResolverInfo(NULL); 911 SendNetInfo(net::NET_INFO_HOST_RESOLVER);
1050 } 912 }
1051 913
1052 void NetInternalsMessageHandler::IOThreadImpl::OnEnableIPv6( 914 void NetInternalsMessageHandler::IOThreadImpl::OnEnableIPv6(
1053 const base::ListValue* list) { 915 const base::ListValue* list) {
1054 DCHECK(!list); 916 DCHECK(!list);
1055 net::HostResolver* host_resolver = GetMainContext()->host_resolver(); 917 net::HostResolver* host_resolver = GetMainContext()->host_resolver();
1056 918
1057 host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_UNSPECIFIED); 919 host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_UNSPECIFIED);
1058 920
1059 // Cause the renderer to be notified of the new value. 921 // Cause the renderer to be notified of the new value.
1060 OnGetHostResolverInfo(NULL); 922 SendNetInfo(net::NET_INFO_HOST_RESOLVER);
1061 } 923 }
1062 924
1063 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests( 925 void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests(
1064 const base::ListValue* list) { 926 const base::ListValue* list) {
1065 // |value| should be: [<URL to test>]. 927 // |value| should be: [<URL to test>].
1066 base::string16 url_str; 928 base::string16 url_str;
1067 CHECK(list->GetString(0, &url_str)); 929 CHECK(list->GetString(0, &url_str));
1068 930
1069 // Try to fix-up the user provided URL into something valid. 931 // Try to fix-up the user provided URL into something valid.
1070 // For example, turn "www.google.com" into "http://www.google.com". 932 // For example, turn "www.google.com" into "http://www.google.com".
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 return; 1062 return;
1201 } 1063 }
1202 net::TransportSecurityState* transport_security_state = 1064 net::TransportSecurityState* transport_security_state =
1203 GetMainContext()->transport_security_state(); 1065 GetMainContext()->transport_security_state();
1204 if (!transport_security_state) 1066 if (!transport_security_state)
1205 return; 1067 return;
1206 1068
1207 transport_security_state->DeleteDynamicDataForHost(domain); 1069 transport_security_state->DeleteDynamicDataForHost(domain);
1208 } 1070 }
1209 1071
1210 void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpCacheInfo(
1211 const base::ListValue* list) {
1212 DCHECK(!list);
1213 base::DictionaryValue* info_dict = new base::DictionaryValue();
1214 base::DictionaryValue* stats_dict = new base::DictionaryValue();
1215
1216 disk_cache::Backend* disk_cache = GetDiskCacheBackend(GetMainContext());
1217
1218 if (disk_cache) {
1219 // Extract the statistics key/value pairs from the backend.
1220 base::StringPairs stats;
1221 disk_cache->GetStats(&stats);
1222 for (size_t i = 0; i < stats.size(); ++i) {
1223 stats_dict->SetStringWithoutPathExpansion(
1224 stats[i].first, stats[i].second);
1225 }
1226 }
1227
1228 info_dict->Set("stats", stats_dict);
1229
1230 SendJavascriptCommand("receivedHttpCacheInfo", info_dict);
1231 }
1232
1233 void NetInternalsMessageHandler::IOThreadImpl::OnGetSocketPoolInfo(
1234 const base::ListValue* list) {
1235 DCHECK(!list);
1236 net::HttpNetworkSession* http_network_session =
1237 GetHttpNetworkSession(GetMainContext());
1238
1239 base::Value* socket_pool_info = NULL;
1240 if (http_network_session)
1241 socket_pool_info = http_network_session->SocketPoolInfoToValue();
1242
1243 SendJavascriptCommand("receivedSocketPoolInfo", socket_pool_info);
1244 }
1245
1246 void NetInternalsMessageHandler::IOThreadImpl::OnGetSessionNetworkStats( 1072 void NetInternalsMessageHandler::IOThreadImpl::OnGetSessionNetworkStats(
1247 const base::ListValue* list) { 1073 const base::ListValue* list) {
1248 DCHECK(!list); 1074 DCHECK(!list);
1249 net::HttpNetworkSession* http_network_session = 1075 net::HttpNetworkSession* http_network_session =
1250 GetHttpNetworkSession(main_context_getter_->GetURLRequestContext()); 1076 GetHttpNetworkSession(main_context_getter_->GetURLRequestContext());
1251 1077
1252 base::Value* network_info = NULL; 1078 base::Value* network_info = NULL;
1253 if (http_network_session) { 1079 if (http_network_session) {
1254 ChromeNetworkDelegate* net_delegate = 1080 ChromeNetworkDelegate* net_delegate =
1255 static_cast<ChromeNetworkDelegate*>( 1081 static_cast<ChromeNetworkDelegate*>(
(...skipping 18 matching lines...) Expand all
1274 void NetInternalsMessageHandler::IOThreadImpl::OnCloseIdleSockets( 1100 void NetInternalsMessageHandler::IOThreadImpl::OnCloseIdleSockets(
1275 const base::ListValue* list) { 1101 const base::ListValue* list) {
1276 DCHECK(!list); 1102 DCHECK(!list);
1277 net::HttpNetworkSession* http_network_session = 1103 net::HttpNetworkSession* http_network_session =
1278 GetHttpNetworkSession(GetMainContext()); 1104 GetHttpNetworkSession(GetMainContext());
1279 1105
1280 if (http_network_session) 1106 if (http_network_session)
1281 http_network_session->CloseIdleConnections(); 1107 http_network_session->CloseIdleConnections();
1282 } 1108 }
1283 1109
1284 void NetInternalsMessageHandler::IOThreadImpl::OnGetSpdySessionInfo(
1285 const base::ListValue* list) {
1286 DCHECK(!list);
1287 net::HttpNetworkSession* http_network_session =
1288 GetHttpNetworkSession(GetMainContext());
1289
1290 base::Value* spdy_info = http_network_session ?
1291 http_network_session->SpdySessionPoolInfoToValue() : NULL;
1292 SendJavascriptCommand("receivedSpdySessionInfo", spdy_info);
1293 }
1294
1295 void NetInternalsMessageHandler::IOThreadImpl::OnGetSpdyStatus(
1296 const base::ListValue* list) {
1297 DCHECK(!list);
1298 base::DictionaryValue* status_dict = new base::DictionaryValue();
1299
1300 net::HttpNetworkSession* http_network_session =
1301 GetHttpNetworkSession(GetMainContext());
1302
1303 status_dict->SetBoolean("spdy_enabled",
1304 net::HttpStreamFactory::spdy_enabled());
1305 status_dict->SetBoolean(
1306 "use_alternate_protocols",
1307 http_network_session->params().use_alternate_protocols);
1308 status_dict->SetBoolean("force_spdy_over_ssl",
1309 http_network_session->params().force_spdy_over_ssl);
1310 status_dict->SetBoolean("force_spdy_always",
1311 http_network_session->params().force_spdy_always);
1312
1313 std::vector<std::string> next_protos;
1314 http_network_session->GetNextProtos(&next_protos);
1315 std::string next_protos_string = JoinString(next_protos, ',');
1316 status_dict->SetString("next_protos", next_protos_string);
1317
1318 SendJavascriptCommand("receivedSpdyStatus", status_dict);
1319 }
1320
1321 void
1322 NetInternalsMessageHandler::IOThreadImpl::OnGetSpdyAlternateProtocolMappings(
1323 const base::ListValue* list) {
1324 DCHECK(!list);
1325 base::ListValue* dict_list = new base::ListValue();
1326
1327 const net::HttpServerProperties& http_server_properties =
1328 *GetMainContext()->http_server_properties();
1329
1330 const net::AlternateProtocolMap& map =
1331 http_server_properties.alternate_protocol_map();
1332
1333 for (net::AlternateProtocolMap::const_iterator it = map.begin();
1334 it != map.end(); ++it) {
1335 base::DictionaryValue* dict = new base::DictionaryValue();
1336 dict->SetString("host_port_pair", it->first.ToString());
1337 dict->SetString("alternate_protocol", it->second.ToString());
1338 dict_list->Append(dict);
1339 }
1340
1341 SendJavascriptCommand("receivedSpdyAlternateProtocolMappings", dict_list);
1342 }
1343
1344 void NetInternalsMessageHandler::IOThreadImpl::OnGetQuicInfo(
1345 const base::ListValue* list) {
1346 DCHECK(!list);
1347 net::HttpNetworkSession* http_network_session =
1348 GetHttpNetworkSession(GetMainContext());
1349
1350 base::Value* quic_info = http_network_session ?
1351 http_network_session->QuicInfoToValue() : NULL;
1352 SendJavascriptCommand("receivedQuicInfo", quic_info);
1353 }
1354
1355 #if defined(OS_WIN) 1110 #if defined(OS_WIN)
1356 void NetInternalsMessageHandler::IOThreadImpl::OnGetServiceProviders( 1111 void NetInternalsMessageHandler::IOThreadImpl::OnGetServiceProviders(
1357 const base::ListValue* list) { 1112 const base::ListValue* list) {
1358 DCHECK(!list); 1113 DCHECK(!list);
1359 1114
1360 base::DictionaryValue* service_providers = new base::DictionaryValue(); 1115 base::DictionaryValue* service_providers = new base::DictionaryValue();
1361 1116
1362 WinsockLayeredServiceProviderList layered_providers; 1117 WinsockLayeredServiceProviderList layered_providers;
1363 GetWinsockLayeredServiceProviders(&layered_providers); 1118 GetWinsockLayeredServiceProviders(&layered_providers);
1364 base::ListValue* layered_provider_list = new base::ListValue(); 1119 base::ListValue* layered_provider_list = new base::ListValue();
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 &callback); 1432 &callback);
1678 net::NetLog::Entry entry(&entry_data, request->net_log().GetLogLevel()); 1433 net::NetLog::Entry entry(&entry_data, request->net_log().GetLogLevel());
1679 1434
1680 // Have to add |entry| to the queue synchronously, as there may already 1435 // Have to add |entry| to the queue synchronously, as there may already
1681 // be posted tasks queued up to add other events for |request|, which we 1436 // be posted tasks queued up to add other events for |request|, which we
1682 // want |entry| to precede. 1437 // want |entry| to precede.
1683 AddEntryToQueue(entry.ToValue()); 1438 AddEntryToQueue(entry.ToValue());
1684 } 1439 }
1685 } 1440 }
1686 1441
1442 void NetInternalsMessageHandler::IOThreadImpl::SendNetInfo(int info_sources) {
1443 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1444 SendJavascriptCommand(
1445 "receivedNetInfo",
1446 net::GetNetInfo(GetMainContext(), info_sources).release());
1447 }
1448
1687 } // namespace 1449 } // namespace
1688 1450
1689 1451
1690 //////////////////////////////////////////////////////////////////////////////// 1452 ////////////////////////////////////////////////////////////////////////////////
1691 // 1453 //
1692 // NetInternalsUI 1454 // NetInternalsUI
1693 // 1455 //
1694 //////////////////////////////////////////////////////////////////////////////// 1456 ////////////////////////////////////////////////////////////////////////////////
1695 1457
1696 // static 1458 // static
1697 base::Value* NetInternalsUI::GetConstants() { 1459 base::Value* NetInternalsUI::GetConstants() {
1698 base::DictionaryValue* constants_dict = net::NetLogLogger::GetConstants(); 1460 scoped_ptr<base::DictionaryValue> constants_dict = net::GetNetConstants();
1699 DCHECK(constants_dict); 1461 DCHECK(constants_dict);
1700 1462
1701 // Add a dictionary with the version of the client and its command line 1463 // Add a dictionary with the version of the client and its command line
1702 // arguments. 1464 // arguments.
1703 { 1465 {
1704 base::DictionaryValue* dict = new base::DictionaryValue(); 1466 base::DictionaryValue* dict = new base::DictionaryValue();
1705 1467
1706 chrome::VersionInfo version_info; 1468 chrome::VersionInfo version_info;
1707 1469
1708 // We have everything we need to send the right values. 1470 // We have everything we need to send the right values.
1709 dict->SetString("name", version_info.Name()); 1471 dict->SetString("name", version_info.Name());
1710 dict->SetString("version", version_info.Version()); 1472 dict->SetString("version", version_info.Version());
1711 dict->SetString("cl", version_info.LastChange()); 1473 dict->SetString("cl", version_info.LastChange());
1712 dict->SetString("version_mod", 1474 dict->SetString("version_mod",
1713 chrome::VersionInfo::GetVersionStringModifier()); 1475 chrome::VersionInfo::GetVersionStringModifier());
1714 dict->SetString("official", 1476 dict->SetString("official",
1715 version_info.IsOfficialBuild() ? "official" : "unofficial"); 1477 version_info.IsOfficialBuild() ? "official" : "unofficial");
1716 dict->SetString("os_type", version_info.OSType()); 1478 dict->SetString("os_type", version_info.OSType());
1717 dict->SetString("command_line", 1479 dict->SetString("command_line",
1718 CommandLine::ForCurrentProcess()->GetCommandLineString()); 1480 CommandLine::ForCurrentProcess()->GetCommandLineString());
1719 1481
1720 constants_dict->Set("clientInfo", dict); 1482 constants_dict->Set("clientInfo", dict);
1721 } 1483 }
1722 1484
1723 return constants_dict; 1485 return constants_dict.release();
1724 } 1486 }
1725 1487
1726 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1488 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1727 : WebUIController(web_ui) { 1489 : WebUIController(web_ui) {
1728 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1490 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1729 1491
1730 // Set up the chrome://net-internals/ source. 1492 // Set up the chrome://net-internals/ source.
1731 Profile* profile = Profile::FromWebUI(web_ui); 1493 Profile* profile = Profile::FromWebUI(web_ui);
1732 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); 1494 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource());
1733 } 1495 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/net_internals/browser_bridge.js ('k') | net/base/net_info_source_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698