| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 #include "base/utf_string_conversions.h" | 29 #include "base/utf_string_conversions.h" |
| 30 #include "base/values.h" | 30 #include "base/values.h" |
| 31 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
| 32 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 32 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 33 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 33 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 34 #include "chrome/browser/download/download_util.h" | 34 #include "chrome/browser/download/download_util.h" |
| 35 #include "chrome/browser/io_thread.h" | 35 #include "chrome/browser/io_thread.h" |
| 36 #include "chrome/browser/net/chrome_net_log.h" | 36 #include "chrome/browser/net/chrome_net_log.h" |
| 37 #include "chrome/browser/net/chrome_network_delegate.h" | 37 #include "chrome/browser/net/chrome_network_delegate.h" |
| 38 #include "chrome/browser/net/connection_tester.h" | 38 #include "chrome/browser/net/connection_tester.h" |
| 39 #include "chrome/browser/net/net_log_temp_file.h" |
| 39 #include "chrome/browser/net/url_fixer_upper.h" | 40 #include "chrome/browser/net/url_fixer_upper.h" |
| 40 #include "chrome/browser/prerender/prerender_manager.h" | 41 #include "chrome/browser/prerender/prerender_manager.h" |
| 41 #include "chrome/browser/prerender/prerender_manager_factory.h" | 42 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 42 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
| 43 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 44 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 44 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 45 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 45 #include "chrome/common/cancelable_task_tracker.h" | 46 #include "chrome/common/cancelable_task_tracker.h" |
| 46 #include "chrome/common/chrome_notification_types.h" | 47 #include "chrome/common/chrome_notification_types.h" |
| 47 #include "chrome/common/chrome_paths.h" | 48 #include "chrome/common/chrome_paths.h" |
| 48 #include "chrome/common/chrome_version_info.h" | 49 #include "chrome/common/chrome_version_info.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 185 } |
| 185 | 186 |
| 186 ChromeWebUIDataSource* CreateNetInternalsHTMLSource() { | 187 ChromeWebUIDataSource* CreateNetInternalsHTMLSource() { |
| 187 ChromeWebUIDataSource* source = | 188 ChromeWebUIDataSource* source = |
| 188 new ChromeWebUIDataSource(chrome::kChromeUINetInternalsHost); | 189 new ChromeWebUIDataSource(chrome::kChromeUINetInternalsHost); |
| 189 | 190 |
| 190 source->set_default_resource(IDR_NET_INTERNALS_INDEX_HTML); | 191 source->set_default_resource(IDR_NET_INTERNALS_INDEX_HTML); |
| 191 source->add_resource_path("help.html", IDR_NET_INTERNALS_HELP_HTML); | 192 source->add_resource_path("help.html", IDR_NET_INTERNALS_HELP_HTML); |
| 192 source->add_resource_path("help.js", IDR_NET_INTERNALS_HELP_JS); | 193 source->add_resource_path("help.js", IDR_NET_INTERNALS_HELP_JS); |
| 193 source->add_resource_path("index.js", IDR_NET_INTERNALS_INDEX_JS); | 194 source->add_resource_path("index.js", IDR_NET_INTERNALS_INDEX_JS); |
| 195 source->add_resource_path("mobile.html", IDR_NET_INTERNALS_MOBILE_HTML); |
| 196 source->add_resource_path("mobile.js", IDR_NET_INTERNALS_MOBILE_JS); |
| 194 source->set_json_path("strings.js"); | 197 source->set_json_path("strings.js"); |
| 195 return source; | 198 return source; |
| 196 } | 199 } |
| 197 | 200 |
| 198 #if defined(OS_CHROMEOS) | 201 #if defined(OS_CHROMEOS) |
| 199 // Small helper class used to create temporary log file and pass its | 202 // Small helper class used to create temporary log file and pass its |
| 200 // handle and error status to callback. | 203 // handle and error status to callback. |
| 201 // Use case: | 204 // Use case: |
| 202 // DebugLogFileHelper* helper = new DebugLogFileHelper(); | 205 // DebugLogFileHelper* helper = new DebugLogFileHelper(); |
| 203 // base::WorkerPool::PostTaskAndReply(FROM_HERE, | 206 // base::WorkerPool::PostTaskAndReply(FROM_HERE, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 void OnRunIPv6Probe(const ListValue* list); | 505 void OnRunIPv6Probe(const ListValue* list); |
| 503 void OnClearHostResolverCache(const ListValue* list); | 506 void OnClearHostResolverCache(const ListValue* list); |
| 504 void OnEnableIPv6(const ListValue* list); | 507 void OnEnableIPv6(const ListValue* list); |
| 505 void OnStartConnectionTests(const ListValue* list); | 508 void OnStartConnectionTests(const ListValue* list); |
| 506 void OnHSTSQuery(const ListValue* list); | 509 void OnHSTSQuery(const ListValue* list); |
| 507 void OnHSTSAdd(const ListValue* list); | 510 void OnHSTSAdd(const ListValue* list); |
| 508 void OnHSTSDelete(const ListValue* list); | 511 void OnHSTSDelete(const ListValue* list); |
| 509 void OnGetHttpCacheInfo(const ListValue* list); | 512 void OnGetHttpCacheInfo(const ListValue* list); |
| 510 void OnGetSocketPoolInfo(const ListValue* list); | 513 void OnGetSocketPoolInfo(const ListValue* list); |
| 511 void OnGetSessionNetworkStats(const ListValue* list); | 514 void OnGetSessionNetworkStats(const ListValue* list); |
| 515 void OnGetMobileNetLogInfo(const ListValue* list); |
| 516 void OnStartNetLog(const ListValue* list); |
| 517 void OnStopNetLog(const ListValue* list); |
| 518 void OnSendNetLog(const ListValue* list); |
| 512 void OnCloseIdleSockets(const ListValue* list); | 519 void OnCloseIdleSockets(const ListValue* list); |
| 513 void OnFlushSocketPools(const ListValue* list); | 520 void OnFlushSocketPools(const ListValue* list); |
| 514 void OnGetSpdySessionInfo(const ListValue* list); | 521 void OnGetSpdySessionInfo(const ListValue* list); |
| 515 void OnGetSpdyStatus(const ListValue* list); | 522 void OnGetSpdyStatus(const ListValue* list); |
| 516 void OnGetSpdyAlternateProtocolMappings(const ListValue* list); | 523 void OnGetSpdyAlternateProtocolMappings(const ListValue* list); |
| 517 #if defined(OS_WIN) | 524 #if defined(OS_WIN) |
| 518 void OnGetServiceProviders(const ListValue* list); | 525 void OnGetServiceProviders(const ListValue* list); |
| 519 #endif | 526 #endif |
| 520 void OnGetHttpPipeliningStatus(const ListValue* list); | 527 void OnGetHttpPipeliningStatus(const ListValue* list); |
| 521 void OnSetLogLevel(const ListValue* list); | 528 void OnSetLogLevel(const ListValue* list); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 561 |
| 555 // Sends all pending entries to the page via Javascript, and clears the list | 562 // Sends all pending entries to the page via Javascript, and clears the list |
| 556 // of pending entries. Sending multiple entries at once results in a | 563 // of pending entries. Sending multiple entries at once results in a |
| 557 // significant reduction of CPU usage when a lot of events are happening. | 564 // significant reduction of CPU usage when a lot of events are happening. |
| 558 // Must be called on the IO Thread. | 565 // Must be called on the IO Thread. |
| 559 void PostPendingEntries(); | 566 void PostPendingEntries(); |
| 560 | 567 |
| 561 // Adds entries with the states of ongoing URL requests. | 568 // Adds entries with the states of ongoing URL requests. |
| 562 void PrePopulateEventList(); | 569 void PrePopulateEventList(); |
| 563 | 570 |
| 571 // Calls NetLogTempFile's ProcessCommand and updates the MobileNetLogInfo. |
| 572 void ProcessNetLogCommand(NetLogTempFile::Command command); |
| 573 |
| 564 net::URLRequestContext* GetMainContext() { | 574 net::URLRequestContext* GetMainContext() { |
| 565 return main_context_getter_->GetURLRequestContext(); | 575 return main_context_getter_->GetURLRequestContext(); |
| 566 } | 576 } |
| 567 | 577 |
| 568 // Pointer to the UI-thread message handler. Only access this from | 578 // Pointer to the UI-thread message handler. Only access this from |
| 569 // the UI thread. | 579 // the UI thread. |
| 570 base::WeakPtr<NetInternalsMessageHandler> handler_; | 580 base::WeakPtr<NetInternalsMessageHandler> handler_; |
| 571 | 581 |
| 572 // The global IOThread, which contains the global NetLog to observer. | 582 // The global IOThread, which contains the global NetLog to observer. |
| 573 IOThread* io_thread_; | 583 IOThread* io_thread_; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 &IOThreadImpl::OnGetHttpCacheInfo, proxy_)); | 706 &IOThreadImpl::OnGetHttpCacheInfo, proxy_)); |
| 697 web_ui()->RegisterMessageCallback( | 707 web_ui()->RegisterMessageCallback( |
| 698 "getSocketPoolInfo", | 708 "getSocketPoolInfo", |
| 699 base::Bind(&IOThreadImpl::CallbackHelper, | 709 base::Bind(&IOThreadImpl::CallbackHelper, |
| 700 &IOThreadImpl::OnGetSocketPoolInfo, proxy_)); | 710 &IOThreadImpl::OnGetSocketPoolInfo, proxy_)); |
| 701 web_ui()->RegisterMessageCallback( | 711 web_ui()->RegisterMessageCallback( |
| 702 "getSessionNetworkStats", | 712 "getSessionNetworkStats", |
| 703 base::Bind(&IOThreadImpl::CallbackHelper, | 713 base::Bind(&IOThreadImpl::CallbackHelper, |
| 704 &IOThreadImpl::OnGetSessionNetworkStats, proxy_)); | 714 &IOThreadImpl::OnGetSessionNetworkStats, proxy_)); |
| 705 web_ui()->RegisterMessageCallback( | 715 web_ui()->RegisterMessageCallback( |
| 716 "getMobileNetLogInfo", |
| 717 base::Bind(&IOThreadImpl::CallbackHelper, |
| 718 &IOThreadImpl::OnGetMobileNetLogInfo, proxy_)); |
| 719 web_ui()->RegisterMessageCallback( |
| 720 "startNetLog", |
| 721 base::Bind(&IOThreadImpl::CallbackHelper, |
| 722 &IOThreadImpl::OnStartNetLog, proxy_)); |
| 723 web_ui()->RegisterMessageCallback( |
| 724 "stopNetLog", |
| 725 base::Bind(&IOThreadImpl::CallbackHelper, |
| 726 &IOThreadImpl::OnStopNetLog, proxy_)); |
| 727 web_ui()->RegisterMessageCallback( |
| 728 "sendNetLog", |
| 729 base::Bind(&IOThreadImpl::CallbackHelper, |
| 730 &IOThreadImpl::OnSendNetLog, proxy_)); |
| 731 web_ui()->RegisterMessageCallback( |
| 706 "closeIdleSockets", | 732 "closeIdleSockets", |
| 707 base::Bind(&IOThreadImpl::CallbackHelper, | 733 base::Bind(&IOThreadImpl::CallbackHelper, |
| 708 &IOThreadImpl::OnCloseIdleSockets, proxy_)); | 734 &IOThreadImpl::OnCloseIdleSockets, proxy_)); |
| 709 web_ui()->RegisterMessageCallback( | 735 web_ui()->RegisterMessageCallback( |
| 710 "flushSocketPools", | 736 "flushSocketPools", |
| 711 base::Bind(&IOThreadImpl::CallbackHelper, | 737 base::Bind(&IOThreadImpl::CallbackHelper, |
| 712 &IOThreadImpl::OnFlushSocketPools, proxy_)); | 738 &IOThreadImpl::OnFlushSocketPools, proxy_)); |
| 713 web_ui()->RegisterMessageCallback( | 739 web_ui()->RegisterMessageCallback( |
| 714 "getSpdySessionInfo", | 740 "getSpdySessionInfo", |
| 715 base::Bind(&IOThreadImpl::CallbackHelper, | 741 base::Bind(&IOThreadImpl::CallbackHelper, |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 // |method| cannot take ownership of |list_copy|. | 985 // |method| cannot take ownership of |list_copy|. |
| 960 ListValue* list_copy = (list && list->GetSize()) ? list->DeepCopy() : NULL; | 986 ListValue* list_copy = (list && list->GetSize()) ? list->DeepCopy() : NULL; |
| 961 | 987 |
| 962 BrowserThread::PostTask( | 988 BrowserThread::PostTask( |
| 963 BrowserThread::IO, FROM_HERE, | 989 BrowserThread::IO, FROM_HERE, |
| 964 base::Bind(method, io_thread, base::Owned(list_copy))); | 990 base::Bind(method, io_thread, base::Owned(list_copy))); |
| 965 } | 991 } |
| 966 | 992 |
| 967 void NetInternalsMessageHandler::IOThreadImpl::Detach() { | 993 void NetInternalsMessageHandler::IOThreadImpl::Detach() { |
| 968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 995 |
| 996 // Cancel any in-progress requests to collect net_log into temporary file. |
| 997 NetLogTempFile::GetInstance()->ProcessCommand(NetLogTempFile::DO_STOP); |
| 998 |
| 969 // Unregister with network stack to observe events. | 999 // Unregister with network stack to observe events. |
| 970 if (net_log()) | 1000 if (net_log()) |
| 971 net_log()->RemoveThreadSafeObserver(this); | 1001 net_log()->RemoveThreadSafeObserver(this); |
| 972 | 1002 |
| 973 // Cancel any in-progress connection tests. | 1003 // Cancel any in-progress connection tests. |
| 974 connection_tester_.reset(); | 1004 connection_tester_.reset(); |
| 975 } | 1005 } |
| 976 | 1006 |
| 977 void NetInternalsMessageHandler::IOThreadImpl::OnWebUIDeleted() { | 1007 void NetInternalsMessageHandler::IOThreadImpl::OnWebUIDeleted() { |
| 978 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1008 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 void NetInternalsMessageHandler::IOThreadImpl::OnFlushSocketPools( | 1373 void NetInternalsMessageHandler::IOThreadImpl::OnFlushSocketPools( |
| 1344 const ListValue* list) { | 1374 const ListValue* list) { |
| 1345 DCHECK(!list); | 1375 DCHECK(!list); |
| 1346 net::HttpNetworkSession* http_network_session = | 1376 net::HttpNetworkSession* http_network_session = |
| 1347 GetHttpNetworkSession(GetMainContext()); | 1377 GetHttpNetworkSession(GetMainContext()); |
| 1348 | 1378 |
| 1349 if (http_network_session) | 1379 if (http_network_session) |
| 1350 http_network_session->CloseAllConnections(); | 1380 http_network_session->CloseAllConnections(); |
| 1351 } | 1381 } |
| 1352 | 1382 |
| 1383 void NetInternalsMessageHandler::IOThreadImpl::OnGetMobileNetLogInfo( |
| 1384 const ListValue* list) { |
| 1385 DCHECK(!list); |
| 1386 SendJavascriptCommand("receivedMobileNetLogInfo", |
| 1387 NetLogTempFile::GetInstance()->NetLogTempFileToValue()); |
| 1388 } |
| 1389 |
| 1390 void NetInternalsMessageHandler::IOThreadImpl::OnStartNetLog( |
| 1391 const ListValue* list) { |
| 1392 DCHECK(!list); |
| 1393 ProcessNetLogCommand(NetLogTempFile::DO_START); |
| 1394 } |
| 1395 |
| 1396 void NetInternalsMessageHandler::IOThreadImpl::OnStopNetLog( |
| 1397 const ListValue* list) { |
| 1398 DCHECK(!list); |
| 1399 ProcessNetLogCommand(NetLogTempFile::DO_STOP); |
| 1400 } |
| 1401 |
| 1402 void NetInternalsMessageHandler::IOThreadImpl::OnSendNetLog( |
| 1403 const ListValue* list) { |
| 1404 DCHECK(!list); |
| 1405 ProcessNetLogCommand(NetLogTempFile::DO_SEND); |
| 1406 } |
| 1407 |
| 1353 void NetInternalsMessageHandler::IOThreadImpl::OnCloseIdleSockets( | 1408 void NetInternalsMessageHandler::IOThreadImpl::OnCloseIdleSockets( |
| 1354 const ListValue* list) { | 1409 const ListValue* list) { |
| 1355 DCHECK(!list); | 1410 DCHECK(!list); |
| 1356 net::HttpNetworkSession* http_network_session = | 1411 net::HttpNetworkSession* http_network_session = |
| 1357 GetHttpNetworkSession(GetMainContext()); | 1412 GetHttpNetworkSession(GetMainContext()); |
| 1358 | 1413 |
| 1359 if (http_network_session) | 1414 if (http_network_session) |
| 1360 http_network_session->CloseIdleConnections(); | 1415 http_network_session->CloseIdleConnections(); |
| 1361 } | 1416 } |
| 1362 | 1417 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1750 &callback, | 1805 &callback, |
| 1751 request->net_log().GetLogLevel()); | 1806 request->net_log().GetLogLevel()); |
| 1752 | 1807 |
| 1753 // Have to add |entry| to the queue synchronously, as there may already | 1808 // Have to add |entry| to the queue synchronously, as there may already |
| 1754 // be posted tasks queued up to add other events for |request|, which we | 1809 // be posted tasks queued up to add other events for |request|, which we |
| 1755 // want |entry| to precede. | 1810 // want |entry| to precede. |
| 1756 AddEntryToQueue(entry.ToValue()); | 1811 AddEntryToQueue(entry.ToValue()); |
| 1757 } | 1812 } |
| 1758 } | 1813 } |
| 1759 | 1814 |
| 1815 void NetInternalsMessageHandler::IOThreadImpl::ProcessNetLogCommand( |
| 1816 NetLogTempFile::Command command) { |
| 1817 NetLogTempFile::GetInstance()->ProcessCommand(command); |
| 1818 SendJavascriptCommand("receivedMobileNetLogInfo", |
| 1819 NetLogTempFile::GetInstance()->NetLogTempFileToValue()); |
| 1820 } |
| 1821 |
| 1760 } // namespace | 1822 } // namespace |
| 1761 | 1823 |
| 1762 | 1824 |
| 1763 //////////////////////////////////////////////////////////////////////////////// | 1825 //////////////////////////////////////////////////////////////////////////////// |
| 1764 // | 1826 // |
| 1765 // NetInternalsUI | 1827 // NetInternalsUI |
| 1766 // | 1828 // |
| 1767 //////////////////////////////////////////////////////////////////////////////// | 1829 //////////////////////////////////////////////////////////////////////////////// |
| 1768 | 1830 |
| 1769 // static | 1831 // static |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 } | 1975 } |
| 1914 | 1976 |
| 1915 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1977 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
| 1916 : WebUIController(web_ui) { | 1978 : WebUIController(web_ui) { |
| 1917 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1979 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
| 1918 | 1980 |
| 1919 // Set up the chrome://net-internals/ source. | 1981 // Set up the chrome://net-internals/ source. |
| 1920 Profile* profile = Profile::FromWebUI(web_ui); | 1982 Profile* profile = Profile::FromWebUI(web_ui); |
| 1921 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); | 1983 ChromeURLDataManager::AddDataSource(profile, CreateNetInternalsHTMLSource()); |
| 1922 } | 1984 } |
| OLD | NEW |