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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 88 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
89 #include "chromeos/network/onc/onc_utils.h" | 89 #include "chromeos/network/onc/onc_utils.h" |
90 #endif | 90 #endif |
91 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
92 #include "chrome/browser/net/service_providers_win.h" | 92 #include "chrome/browser/net/service_providers_win.h" |
93 #endif | 93 #endif |
94 | 94 |
95 using base::PassPlatformFile; | 95 using base::PassPlatformFile; |
96 using base::PlatformFile; | 96 using base::PlatformFile; |
97 using base::PlatformFileError; | 97 using base::PlatformFileError; |
98 using base::StringValue; | |
98 using content::BrowserThread; | 99 using content::BrowserThread; |
99 using content::WebContents; | 100 using content::WebContents; |
100 using content::WebUIMessageHandler; | 101 using content::WebUIMessageHandler; |
101 | 102 |
102 namespace { | 103 namespace { |
103 | 104 |
104 // Delay between when an event occurs and when it is passed to the Javascript | 105 // Delay between when an event occurs and when it is passed to the Javascript |
105 // page. All events that occur during this period are grouped together and | 106 // page. All events that occur during this period are grouped together and |
106 // sent to the page at once, which reduces context switching and CPU usage. | 107 // sent to the page at once, which reduces context switching and CPU usage. |
107 const int kNetLogEventDelayMilliseconds = 100; | 108 const int kNetLogEventDelayMilliseconds = 100; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 DCHECK(posted); | 367 DCHECK(posted); |
367 return; | 368 return; |
368 } | 369 } |
369 PlatformFile platform_file = pass_platform_file.ReleaseValue(); | 370 PlatformFile platform_file = pass_platform_file.ReleaseValue(); |
370 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->GetDebugLogs( | 371 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->GetDebugLogs( |
371 platform_file, | 372 platform_file, |
372 base::Bind(&WriteDebugLogToFileCompleted, | 373 base::Bind(&WriteDebugLogToFileCompleted, |
373 callback, PassPlatformFile(&platform_file), file_path)); | 374 callback, PassPlatformFile(&platform_file), file_path)); |
374 } | 375 } |
375 | 376 |
376 // Stores debug logs in the .tgz archive on the fileshelf. The file is | 377 // Stores debug logs in the .tgz archive on the |fileshelf|. The file |
377 // created on the worker pool, then writing to it is triggered from | 378 // is created on the worker pool, then writing to it is triggered from |
378 // the UI thread, and finally it is closed (on success) or deleted (on | 379 // the UI thread, and finally it is closed (on success) or deleted (on |
379 // failure) on the worker pool, prior to calling |callback|. | 380 // failure) on the worker pool, prior to calling |callback|. |
380 void StoreDebugLogs(const StoreDebugLogsCallback& callback) { | 381 void StoreDebugLogs(const base::FilePath& fileshelf, |
382 const StoreDebugLogsCallback& callback) { | |
381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
382 DCHECK(!callback.is_null()); | 384 DCHECK(!callback.is_null()); |
383 const base::FilePath fileshelf = DownloadPrefs::GetDefaultDownloadDirectory(); | |
384 DebugLogFileHelper* helper = new DebugLogFileHelper(); | 385 DebugLogFileHelper* helper = new DebugLogFileHelper(); |
385 bool posted = base::WorkerPool::PostTaskAndReply(FROM_HERE, | 386 bool posted = base::WorkerPool::PostTaskAndReply(FROM_HERE, |
386 base::Bind(&DebugLogFileHelper::DoWork, | 387 base::Bind(&DebugLogFileHelper::DoWork, |
387 base::Unretained(helper), fileshelf), | 388 base::Unretained(helper), fileshelf), |
388 base::Bind(&DebugLogFileHelper::Reply, base::Owned(helper), | 389 base::Bind(&DebugLogFileHelper::Reply, base::Owned(helper), |
389 base::Bind(&WriteDebugLogToFile, callback)), false); | 390 base::Bind(&WriteDebugLogToFile, callback)), false); |
390 DCHECK(posted); | 391 DCHECK(posted); |
391 } | 392 } |
392 #endif // defined(OS_CHROMEOS) | 393 #endif // defined(OS_CHROMEOS) |
393 | 394 |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 web_ui()->RegisterMessageCallback( | 832 web_ui()->RegisterMessageCallback( |
832 "setNetworkDebugMode", | 833 "setNetworkDebugMode", |
833 base::Bind(&NetInternalsMessageHandler::OnSetNetworkDebugMode, | 834 base::Bind(&NetInternalsMessageHandler::OnSetNetworkDebugMode, |
834 base::Unretained(this))); | 835 base::Unretained(this))); |
835 #endif | 836 #endif |
836 } | 837 } |
837 | 838 |
838 void NetInternalsMessageHandler::SendJavascriptCommand( | 839 void NetInternalsMessageHandler::SendJavascriptCommand( |
839 const std::string& command, | 840 const std::string& command, |
840 Value* arg) { | 841 Value* arg) { |
841 scoped_ptr<Value> command_value(Value::CreateStringValue(command)); | 842 scoped_ptr<Value> command_value(new StringValue(command)); |
842 scoped_ptr<Value> value(arg); | 843 scoped_ptr<Value> value(arg); |
843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
844 if (value.get()) { | 845 if (value.get()) { |
845 web_ui()->CallJavascriptFunction("g_browser.receive", | 846 web_ui()->CallJavascriptFunction("g_browser.receive", |
846 *command_value.get(), | 847 *command_value.get(), |
847 *value.get()); | 848 *value.get()); |
848 } else { | 849 } else { |
849 web_ui()->CallJavascriptFunction("g_browser.receive", | 850 web_ui()->CallJavascriptFunction("g_browser.receive", |
850 *command_value.get()); | 851 *command_value.get()); |
851 } | 852 } |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1569 | 1570 |
1570 std::string network_error; | 1571 std::string network_error; |
1571 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error); | 1572 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error); |
1572 if (!network_error.empty()) | 1573 if (!network_error.empty()) |
1573 error += network_error; | 1574 error += network_error; |
1574 } else { | 1575 } else { |
1575 error = "No active user."; | 1576 error = "No active user."; |
1576 } | 1577 } |
1577 | 1578 |
1578 LOG_IF(ERROR, !error.empty()) << error; | 1579 LOG_IF(ERROR, !error.empty()) << error; |
1579 SendJavascriptCommand("receivedONCFileParse", | 1580 SendJavascriptCommand("receivedONCFileParse", new StringValue(error)); |
1580 Value::CreateStringValue(error)); | |
1581 } | 1581 } |
1582 | 1582 |
1583 void NetInternalsMessageHandler::OnStoreDebugLogs(const ListValue* list) { | 1583 void NetInternalsMessageHandler::OnStoreDebugLogs(const ListValue* list) { |
1584 DCHECK(list); | 1584 DCHECK(list); |
1585 StoreDebugLogs( | 1585 |
1586 SendJavascriptCommand("receivedStoreDebugLogs", | |
1587 new StringValue("Creating log file...")); | |
1588 StoreDebugLogs(DownloadPrefs(Profile::FromWebUI(web_ui())).DownloadPath(), | |
mmenke
2013/11/13 22:27:16
Should we be using DownloadPrefs:::FromBrowserCont
ygorshenin1
2013/11/13 23:55:36
Done.
| |
1586 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted, | 1589 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted, |
1587 AsWeakPtr())); | 1590 AsWeakPtr())); |
1588 } | 1591 } |
1589 | 1592 |
1590 void NetInternalsMessageHandler::OnStoreDebugLogsCompleted( | 1593 void NetInternalsMessageHandler::OnStoreDebugLogsCompleted( |
1591 const base::FilePath& log_path, bool succeeded) { | 1594 const base::FilePath& log_path, bool succeeded) { |
1592 std::string status; | 1595 std::string status; |
1593 if (succeeded) | 1596 if (succeeded) |
1594 status = "Created log file: " + log_path.BaseName().AsUTF8Unsafe(); | 1597 status = "Created log file: " + log_path.BaseName().AsUTF8Unsafe(); |
1595 else | 1598 else |
1596 status = "Failed to create log file"; | 1599 status = "Failed to create log file"; |
1597 SendJavascriptCommand("receivedStoreDebugLogs", | 1600 SendJavascriptCommand("receivedStoreDebugLogs", new StringValue(status)); |
1598 Value::CreateStringValue(status)); | |
1599 } | 1601 } |
1600 | 1602 |
1601 void NetInternalsMessageHandler::OnSetNetworkDebugMode(const ListValue* list) { | 1603 void NetInternalsMessageHandler::OnSetNetworkDebugMode(const ListValue* list) { |
1602 std::string subsystem; | 1604 std::string subsystem; |
1603 if (list->GetSize() != 1 || !list->GetString(0, &subsystem)) | 1605 if (list->GetSize() != 1 || !list->GetString(0, &subsystem)) |
1604 NOTREACHED(); | 1606 NOTREACHED(); |
1605 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | 1607 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> |
1606 SetDebugMode( | 1608 SetDebugMode( |
1607 subsystem, | 1609 subsystem, |
1608 base::Bind( | 1610 base::Bind( |
1609 &NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted, | 1611 &NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted, |
1610 AsWeakPtr(), | 1612 AsWeakPtr(), |
1611 subsystem)); | 1613 subsystem)); |
1612 } | 1614 } |
1613 | 1615 |
1614 void NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted( | 1616 void NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted( |
1615 const std::string& subsystem, | 1617 const std::string& subsystem, |
1616 bool succeeded) { | 1618 bool succeeded) { |
1617 std::string status; | 1619 std::string status; |
1618 if (succeeded) | 1620 if (succeeded) |
1619 status = "Debug mode is changed to " + subsystem; | 1621 status = "Debug mode is changed to " + subsystem; |
1620 else | 1622 else |
1621 status = "Failed to change debug mode to " + subsystem; | 1623 status = "Failed to change debug mode to " + subsystem; |
1622 SendJavascriptCommand("receivedSetNetworkDebugMode", | 1624 SendJavascriptCommand("receivedSetNetworkDebugMode", new StringValue(status)); |
1623 Value::CreateStringValue(status)); | |
1624 } | 1625 } |
1625 #endif // defined(OS_CHROMEOS) | 1626 #endif // defined(OS_CHROMEOS) |
1626 | 1627 |
1627 void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpPipeliningStatus( | 1628 void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpPipeliningStatus( |
1628 const ListValue* list) { | 1629 const ListValue* list) { |
1629 DCHECK(!list); | 1630 DCHECK(!list); |
1630 DictionaryValue* status_dict = new DictionaryValue(); | 1631 DictionaryValue* status_dict = new DictionaryValue(); |
1631 | 1632 |
1632 Value* pipelined_connection_info = NULL; | 1633 Value* pipelined_connection_info = NULL; |
1633 net::HttpNetworkSession* http_network_session = | 1634 net::HttpNetworkSession* http_network_session = |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1876 } | 1877 } |
1877 | 1878 |
1878 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1879 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
1879 : WebUIController(web_ui) { | 1880 : WebUIController(web_ui) { |
1880 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1881 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
1881 | 1882 |
1882 // Set up the chrome://net-internals/ source. | 1883 // Set up the chrome://net-internals/ source. |
1883 Profile* profile = Profile::FromWebUI(web_ui); | 1884 Profile* profile = Profile::FromWebUI(web_ui); |
1884 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); | 1885 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); |
1885 } | 1886 } |
OLD | NEW |