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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 void OnRunIPv6Probe(const ListValue* list); | 503 void OnRunIPv6Probe(const ListValue* list); |
503 void OnClearHostResolverCache(const ListValue* list); | 504 void OnClearHostResolverCache(const ListValue* list); |
504 void OnEnableIPv6(const ListValue* list); | 505 void OnEnableIPv6(const ListValue* list); |
505 void OnStartConnectionTests(const ListValue* list); | 506 void OnStartConnectionTests(const ListValue* list); |
506 void OnHSTSQuery(const ListValue* list); | 507 void OnHSTSQuery(const ListValue* list); |
507 void OnHSTSAdd(const ListValue* list); | 508 void OnHSTSAdd(const ListValue* list); |
508 void OnHSTSDelete(const ListValue* list); | 509 void OnHSTSDelete(const ListValue* list); |
509 void OnGetHttpCacheInfo(const ListValue* list); | 510 void OnGetHttpCacheInfo(const ListValue* list); |
510 void OnGetSocketPoolInfo(const ListValue* list); | 511 void OnGetSocketPoolInfo(const ListValue* list); |
511 void OnGetSessionNetworkStats(const ListValue* list); | 512 void OnGetSessionNetworkStats(const ListValue* list); |
513 void OnGetMobileNetLogInfo(const ListValue* list); | |
514 void OnStartNetLog(const ListValue* list); | |
515 void OnStopNetLog(const ListValue* list); | |
516 void OnSendNetLog(const ListValue* list); | |
512 void OnCloseIdleSockets(const ListValue* list); | 517 void OnCloseIdleSockets(const ListValue* list); |
513 void OnFlushSocketPools(const ListValue* list); | 518 void OnFlushSocketPools(const ListValue* list); |
514 void OnGetSpdySessionInfo(const ListValue* list); | 519 void OnGetSpdySessionInfo(const ListValue* list); |
515 void OnGetSpdyStatus(const ListValue* list); | 520 void OnGetSpdyStatus(const ListValue* list); |
516 void OnGetSpdyAlternateProtocolMappings(const ListValue* list); | 521 void OnGetSpdyAlternateProtocolMappings(const ListValue* list); |
517 #if defined(OS_WIN) | 522 #if defined(OS_WIN) |
518 void OnGetServiceProviders(const ListValue* list); | 523 void OnGetServiceProviders(const ListValue* list); |
519 #endif | 524 #endif |
520 void OnGetHttpPipeliningStatus(const ListValue* list); | 525 void OnGetHttpPipeliningStatus(const ListValue* list); |
521 void OnSetLogLevel(const ListValue* list); | 526 void OnSetLogLevel(const ListValue* list); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 | 559 |
555 // Sends all pending entries to the page via Javascript, and clears the list | 560 // 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 | 561 // of pending entries. Sending multiple entries at once results in a |
557 // significant reduction of CPU usage when a lot of events are happening. | 562 // significant reduction of CPU usage when a lot of events are happening. |
558 // Must be called on the IO Thread. | 563 // Must be called on the IO Thread. |
559 void PostPendingEntries(); | 564 void PostPendingEntries(); |
560 | 565 |
561 // Adds entries with the states of ongoing URL requests. | 566 // Adds entries with the states of ongoing URL requests. |
562 void PrePopulateEventList(); | 567 void PrePopulateEventList(); |
563 | 568 |
569 // Calls NetLogTempFile's ProcessCommand and updates the MobileNetLogInfo. | |
570 void ProcessNetLogCommand(NetLogTempFile::Command command); | |
571 | |
564 net::URLRequestContext* GetMainContext() { | 572 net::URLRequestContext* GetMainContext() { |
565 return main_context_getter_->GetURLRequestContext(); | 573 return main_context_getter_->GetURLRequestContext(); |
566 } | 574 } |
567 | 575 |
568 // Pointer to the UI-thread message handler. Only access this from | 576 // Pointer to the UI-thread message handler. Only access this from |
569 // the UI thread. | 577 // the UI thread. |
570 base::WeakPtr<NetInternalsMessageHandler> handler_; | 578 base::WeakPtr<NetInternalsMessageHandler> handler_; |
571 | 579 |
572 // The global IOThread, which contains the global NetLog to observer. | 580 // The global IOThread, which contains the global NetLog to observer. |
573 IOThread* io_thread_; | 581 IOThread* io_thread_; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 &IOThreadImpl::OnGetHttpCacheInfo, proxy_)); | 704 &IOThreadImpl::OnGetHttpCacheInfo, proxy_)); |
697 web_ui()->RegisterMessageCallback( | 705 web_ui()->RegisterMessageCallback( |
698 "getSocketPoolInfo", | 706 "getSocketPoolInfo", |
699 base::Bind(&IOThreadImpl::CallbackHelper, | 707 base::Bind(&IOThreadImpl::CallbackHelper, |
700 &IOThreadImpl::OnGetSocketPoolInfo, proxy_)); | 708 &IOThreadImpl::OnGetSocketPoolInfo, proxy_)); |
701 web_ui()->RegisterMessageCallback( | 709 web_ui()->RegisterMessageCallback( |
702 "getSessionNetworkStats", | 710 "getSessionNetworkStats", |
703 base::Bind(&IOThreadImpl::CallbackHelper, | 711 base::Bind(&IOThreadImpl::CallbackHelper, |
704 &IOThreadImpl::OnGetSessionNetworkStats, proxy_)); | 712 &IOThreadImpl::OnGetSessionNetworkStats, proxy_)); |
705 web_ui()->RegisterMessageCallback( | 713 web_ui()->RegisterMessageCallback( |
714 "getMobileNetLogInfo", | |
715 base::Bind(&IOThreadImpl::CallbackHelper, | |
716 &IOThreadImpl::OnGetMobileNetLogInfo, proxy_)); | |
717 web_ui()->RegisterMessageCallback( | |
718 "startNetLog", | |
719 base::Bind(&IOThreadImpl::CallbackHelper, | |
720 &IOThreadImpl::OnStartNetLog, proxy_)); | |
721 web_ui()->RegisterMessageCallback( | |
722 "stopNetLog", | |
723 base::Bind(&IOThreadImpl::CallbackHelper, | |
724 &IOThreadImpl::OnStopNetLog, proxy_)); | |
725 web_ui()->RegisterMessageCallback( | |
726 "sendNetLog", | |
727 base::Bind(&IOThreadImpl::CallbackHelper, | |
728 &IOThreadImpl::OnSendNetLog, proxy_)); | |
729 web_ui()->RegisterMessageCallback( | |
706 "closeIdleSockets", | 730 "closeIdleSockets", |
707 base::Bind(&IOThreadImpl::CallbackHelper, | 731 base::Bind(&IOThreadImpl::CallbackHelper, |
708 &IOThreadImpl::OnCloseIdleSockets, proxy_)); | 732 &IOThreadImpl::OnCloseIdleSockets, proxy_)); |
709 web_ui()->RegisterMessageCallback( | 733 web_ui()->RegisterMessageCallback( |
710 "flushSocketPools", | 734 "flushSocketPools", |
711 base::Bind(&IOThreadImpl::CallbackHelper, | 735 base::Bind(&IOThreadImpl::CallbackHelper, |
712 &IOThreadImpl::OnFlushSocketPools, proxy_)); | 736 &IOThreadImpl::OnFlushSocketPools, proxy_)); |
713 web_ui()->RegisterMessageCallback( | 737 web_ui()->RegisterMessageCallback( |
714 "getSpdySessionInfo", | 738 "getSpdySessionInfo", |
715 base::Bind(&IOThreadImpl::CallbackHelper, | 739 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|. | 983 // |method| cannot take ownership of |list_copy|. |
960 ListValue* list_copy = (list && list->GetSize()) ? list->DeepCopy() : NULL; | 984 ListValue* list_copy = (list && list->GetSize()) ? list->DeepCopy() : NULL; |
961 | 985 |
962 BrowserThread::PostTask( | 986 BrowserThread::PostTask( |
963 BrowserThread::IO, FROM_HERE, | 987 BrowserThread::IO, FROM_HERE, |
964 base::Bind(method, io_thread, base::Owned(list_copy))); | 988 base::Bind(method, io_thread, base::Owned(list_copy))); |
965 } | 989 } |
966 | 990 |
967 void NetInternalsMessageHandler::IOThreadImpl::Detach() { | 991 void NetInternalsMessageHandler::IOThreadImpl::Detach() { |
968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 992 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
993 | |
994 // Cancel any in-progress requests to collect net_log into temporary file. | |
995 NetLogTempFile::GetInstance()->ProcessCommand(NetLogTempFile::DO_STOP); | |
996 | |
969 // Unregister with network stack to observe events. | 997 // Unregister with network stack to observe events. |
970 if (net_log()) | 998 if (net_log()) |
971 net_log()->RemoveThreadSafeObserver(this); | 999 net_log()->RemoveThreadSafeObserver(this); |
972 | 1000 |
973 // Cancel any in-progress connection tests. | 1001 // Cancel any in-progress connection tests. |
974 connection_tester_.reset(); | 1002 connection_tester_.reset(); |
975 } | 1003 } |
976 | 1004 |
977 void NetInternalsMessageHandler::IOThreadImpl::OnWebUIDeleted() { | 1005 void NetInternalsMessageHandler::IOThreadImpl::OnWebUIDeleted() { |
978 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1006 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1343 void NetInternalsMessageHandler::IOThreadImpl::OnFlushSocketPools( | 1371 void NetInternalsMessageHandler::IOThreadImpl::OnFlushSocketPools( |
1344 const ListValue* list) { | 1372 const ListValue* list) { |
1345 DCHECK(!list); | 1373 DCHECK(!list); |
1346 net::HttpNetworkSession* http_network_session = | 1374 net::HttpNetworkSession* http_network_session = |
1347 GetHttpNetworkSession(GetMainContext()); | 1375 GetHttpNetworkSession(GetMainContext()); |
1348 | 1376 |
1349 if (http_network_session) | 1377 if (http_network_session) |
1350 http_network_session->CloseAllConnections(); | 1378 http_network_session->CloseAllConnections(); |
1351 } | 1379 } |
1352 | 1380 |
1381 void NetInternalsMessageHandler::IOThreadImpl::OnGetMobileNetLogInfo( | |
1382 const ListValue* list) { | |
1383 DCHECK(!list); | |
1384 SendJavascriptCommand("receivedMobileNetLogInfo", | |
1385 NetLogTempFile::GetInstance()->NetLogTempFileToValue()); | |
1386 } | |
1387 | |
1388 void NetInternalsMessageHandler::IOThreadImpl::OnStartNetLog( | |
1389 const ListValue* list) { | |
1390 DCHECK(!list); | |
1391 ProcessNetLogCommand(NetLogTempFile::DO_START); | |
1392 } | |
1393 | |
1394 void NetInternalsMessageHandler::IOThreadImpl::OnStopNetLog( | |
1395 const ListValue* list) { | |
1396 DCHECK(!list); | |
1397 ProcessNetLogCommand(NetLogTempFile::DO_STOP); | |
1398 } | |
1399 | |
1400 void NetInternalsMessageHandler::IOThreadImpl::OnSendNetLog( | |
1401 const ListValue* list) { | |
1402 DCHECK(!list); | |
1403 ProcessNetLogCommand(NetLogTempFile::DO_SEND); | |
1404 } | |
1405 | |
1353 void NetInternalsMessageHandler::IOThreadImpl::OnCloseIdleSockets( | 1406 void NetInternalsMessageHandler::IOThreadImpl::OnCloseIdleSockets( |
1354 const ListValue* list) { | 1407 const ListValue* list) { |
1355 DCHECK(!list); | 1408 DCHECK(!list); |
1356 net::HttpNetworkSession* http_network_session = | 1409 net::HttpNetworkSession* http_network_session = |
1357 GetHttpNetworkSession(GetMainContext()); | 1410 GetHttpNetworkSession(GetMainContext()); |
1358 | 1411 |
1359 if (http_network_session) | 1412 if (http_network_session) |
1360 http_network_session->CloseIdleConnections(); | 1413 http_network_session->CloseIdleConnections(); |
1361 } | 1414 } |
1362 | 1415 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1682 if (!BrowserThread::PostTask( | 1735 if (!BrowserThread::PostTask( |
1683 BrowserThread::UI, FROM_HERE, | 1736 BrowserThread::UI, FROM_HERE, |
1684 base::Bind(&IOThreadImpl::SendJavascriptCommand, this, command, arg))) { | 1737 base::Bind(&IOThreadImpl::SendJavascriptCommand, this, command, arg))) { |
1685 // Failed posting the task, avoid leaking. | 1738 // Failed posting the task, avoid leaking. |
1686 delete arg; | 1739 delete arg; |
1687 } | 1740 } |
1688 } | 1741 } |
1689 | 1742 |
1690 void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue(Value* entry) { | 1743 void NetInternalsMessageHandler::IOThreadImpl::AddEntryToQueue(Value* entry) { |
1691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1745 #if !defined(OS_IOS) | |
mmenke
2012/12/27 20:43:05
This seems a somewhat random thing to exclude on i
ramant (doing other things)
2013/01/04 01:47:28
Added code in JavaScript not to store pending_entr
| |
1692 if (!pending_entries_.get()) { | 1746 if (!pending_entries_.get()) { |
1693 pending_entries_.reset(new ListValue()); | 1747 pending_entries_.reset(new ListValue()); |
1694 BrowserThread::PostDelayedTask( | 1748 BrowserThread::PostDelayedTask( |
1695 BrowserThread::IO, FROM_HERE, | 1749 BrowserThread::IO, FROM_HERE, |
1696 base::Bind(&IOThreadImpl::PostPendingEntries, this), | 1750 base::Bind(&IOThreadImpl::PostPendingEntries, this), |
1697 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); | 1751 base::TimeDelta::FromMilliseconds(kNetLogEventDelayMilliseconds)); |
1698 } | 1752 } |
1699 pending_entries_->Append(entry); | 1753 pending_entries_->Append(entry); |
1754 #endif | |
1700 } | 1755 } |
1701 | 1756 |
1702 void NetInternalsMessageHandler::IOThreadImpl::PostPendingEntries() { | 1757 void NetInternalsMessageHandler::IOThreadImpl::PostPendingEntries() { |
1703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1704 if (pending_entries_.get()) | 1759 if (pending_entries_.get()) |
1705 SendJavascriptCommand("receivedLogEntries", pending_entries_.release()); | 1760 SendJavascriptCommand("receivedLogEntries", pending_entries_.release()); |
1706 } | 1761 } |
1707 | 1762 |
1708 void NetInternalsMessageHandler::IOThreadImpl::PrePopulateEventList() { | 1763 void NetInternalsMessageHandler::IOThreadImpl::PrePopulateEventList() { |
1709 // Use a set to prevent duplicates. | 1764 // Use a set to prevent duplicates. |
(...skipping 40 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 |