| 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 26 matching lines...) Expand all Loading... |
| 37 #include "chrome/browser/io_thread.h" | 37 #include "chrome/browser/io_thread.h" |
| 38 #include "chrome/browser/net/chrome_net_log.h" | 38 #include "chrome/browser/net/chrome_net_log.h" |
| 39 #include "chrome/browser/net/chrome_network_delegate.h" | 39 #include "chrome/browser/net/chrome_network_delegate.h" |
| 40 #include "chrome/browser/net/connection_tester.h" | 40 #include "chrome/browser/net/connection_tester.h" |
| 41 #include "chrome/browser/prerender/prerender_manager.h" | 41 #include "chrome/browser/prerender/prerender_manager.h" |
| 42 #include "chrome/browser/prerender/prerender_manager_factory.h" | 42 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 43 #include "chrome/browser/profiles/profile.h" | 43 #include "chrome/browser/profiles/profile.h" |
| 44 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" | 44 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" |
| 45 #include "chrome/common/chrome_paths.h" | 45 #include "chrome/common/chrome_paths.h" |
| 46 #include "chrome/common/chrome_version_info.h" | 46 #include "chrome/common/chrome_version_info.h" |
| 47 #include "chrome/common/logging_chrome.h" | |
| 48 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
| 49 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
| 50 #include "components/onc/onc_constants.h" | 49 #include "components/onc/onc_constants.h" |
| 51 #include "components/url_fixer/url_fixer.h" | 50 #include "components/url_fixer/url_fixer.h" |
| 52 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
| 53 #include "content/public/browser/notification_details.h" | 52 #include "content/public/browser/notification_details.h" |
| 54 #include "content/public/browser/resource_dispatcher_host.h" | 53 #include "content/public/browser/resource_dispatcher_host.h" |
| 55 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
| 56 #include "content/public/browser/web_ui.h" | 55 #include "content/public/browser/web_ui.h" |
| 57 #include "content/public/browser/web_ui_data_source.h" | 56 #include "content/public/browser/web_ui_data_source.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 #include "net/proxy/proxy_service.h" | 75 #include "net/proxy/proxy_service.h" |
| 77 #include "net/url_request/url_request_context.h" | 76 #include "net/url_request/url_request_context.h" |
| 78 #include "net/url_request/url_request_context_getter.h" | 77 #include "net/url_request/url_request_context_getter.h" |
| 79 #include "ui/base/resource/resource_bundle.h" | 78 #include "ui/base/resource/resource_bundle.h" |
| 80 | 79 |
| 81 #if defined(OS_CHROMEOS) | 80 #if defined(OS_CHROMEOS) |
| 82 #include "chrome/browser/chromeos/login/users/user.h" | 81 #include "chrome/browser/chromeos/login/users/user.h" |
| 83 #include "chrome/browser/chromeos/login/users/user_manager.h" | 82 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 84 #include "chrome/browser/chromeos/net/onc_utils.h" | 83 #include "chrome/browser/chromeos/net/onc_utils.h" |
| 85 #include "chrome/browser/chromeos/system/syslogs_provider.h" | 84 #include "chrome/browser/chromeos/system/syslogs_provider.h" |
| 85 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h" |
| 86 #include "chrome/browser/net/nss_context.h" | 86 #include "chrome/browser/net/nss_context.h" |
| 87 #include "chromeos/dbus/dbus_thread_manager.h" | 87 #include "chromeos/dbus/dbus_thread_manager.h" |
| 88 #include "chromeos/dbus/debug_daemon_client.h" | 88 #include "chromeos/dbus/debug_daemon_client.h" |
| 89 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 89 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
| 90 #include "chromeos/network/onc/onc_utils.h" | 90 #include "chromeos/network/onc/onc_utils.h" |
| 91 #endif | 91 #endif |
| 92 #if defined(OS_WIN) | 92 #if defined(OS_WIN) |
| 93 #include "chrome/browser/net/service_providers_win.h" | 93 #include "chrome/browser/net/service_providers_win.h" |
| 94 #endif | 94 #endif |
| 95 | 95 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 content::WebUIDataSource* source = | 200 content::WebUIDataSource* source = |
| 201 content::WebUIDataSource::Create(chrome::kChromeUINetInternalsHost); | 201 content::WebUIDataSource::Create(chrome::kChromeUINetInternalsHost); |
| 202 | 202 |
| 203 source->SetUseJsonJSFormatV2(); | 203 source->SetUseJsonJSFormatV2(); |
| 204 source->SetDefaultResource(IDR_NET_INTERNALS_INDEX_HTML); | 204 source->SetDefaultResource(IDR_NET_INTERNALS_INDEX_HTML); |
| 205 source->AddResourcePath("index.js", IDR_NET_INTERNALS_INDEX_JS); | 205 source->AddResourcePath("index.js", IDR_NET_INTERNALS_INDEX_JS); |
| 206 source->SetJsonPath("strings.js"); | 206 source->SetJsonPath("strings.js"); |
| 207 return source; | 207 return source; |
| 208 } | 208 } |
| 209 | 209 |
| 210 #if defined(OS_CHROMEOS) | |
| 211 // Following functions are used for getting debug logs. Logs are | |
| 212 // fetched from /var/log/* and put on the fileshelf. | |
| 213 | |
| 214 // Called once StoreDebugLogs is complete. Takes two parameters: | |
| 215 // - log_path: where the log file was saved in the case of success; | |
| 216 // - succeeded: was the log file saved successfully. | |
| 217 typedef base::Callback<void(const base::FilePath& log_path, | |
| 218 bool succeded)> StoreDebugLogsCallback; | |
| 219 | |
| 220 // Called upon completion of |WriteDebugLogToFile|. Closes file | |
| 221 // descriptor, deletes log file in the case of failure and calls | |
| 222 // |callback|. | |
| 223 void WriteDebugLogToFileCompleted(const StoreDebugLogsCallback& callback, | |
| 224 const base::FilePath& file_path, | |
| 225 bool succeeded) { | |
| 226 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 227 if (!succeeded) { | |
| 228 bool posted = BrowserThread::PostBlockingPoolTaskAndReply( | |
| 229 FROM_HERE, | |
| 230 base::Bind(base::IgnoreResult(&base::DeleteFile), file_path, false), | |
| 231 base::Bind(callback, file_path, false)); | |
| 232 DCHECK(posted); | |
| 233 return; | |
| 234 } | |
| 235 callback.Run(file_path, true); | |
| 236 } | |
| 237 | |
| 238 // Stores into |file_path| debug logs in the .tgz format. Calls | |
| 239 // |callback| upon completion. | |
| 240 void WriteDebugLogToFile(const StoreDebugLogsCallback& callback, | |
| 241 base::File* file, | |
| 242 const base::FilePath& file_path) { | |
| 243 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 244 if (!file->IsValid()) { | |
| 245 LOG(ERROR) << | |
| 246 "Can't create debug log file: " << file_path.AsUTF8Unsafe() << ", " << | |
| 247 "error: " << file->error_details(); | |
| 248 return; | |
| 249 } | |
| 250 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->GetDebugLogs( | |
| 251 file->Pass(), | |
| 252 base::Bind(&WriteDebugLogToFileCompleted, callback, file_path)); | |
| 253 } | |
| 254 | |
| 255 // Stores debug logs in the .tgz archive on the |fileshelf|. The file | |
| 256 // is created on the worker pool, then writing to it is triggered from | |
| 257 // the UI thread, and finally it is closed (on success) or deleted (on | |
| 258 // failure) on the worker pool, prior to calling |callback|. | |
| 259 void StoreDebugLogs(const base::FilePath& fileshelf, | |
| 260 const StoreDebugLogsCallback& callback) { | |
| 261 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 262 DCHECK(!callback.is_null()); | |
| 263 | |
| 264 const base::FilePath::CharType kLogFileName[] = | |
| 265 FILE_PATH_LITERAL("debug-log.tgz"); | |
| 266 | |
| 267 base::FilePath file_path = fileshelf.Append(kLogFileName); | |
| 268 file_path = logging::GenerateTimestampedName(file_path, base::Time::Now()); | |
| 269 | |
| 270 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE; | |
| 271 base::File* file = new base::File; | |
| 272 bool posted = BrowserThread::PostBlockingPoolTaskAndReply( | |
| 273 FROM_HERE, | |
| 274 base::Bind(&base::File::Initialize, | |
| 275 base::Unretained(file), file_path, flags), | |
| 276 base::Bind(&WriteDebugLogToFile, callback, base::Owned(file), file_path)); | |
| 277 DCHECK(posted); | |
| 278 } | |
| 279 #endif // defined(OS_CHROMEOS) | |
| 280 | |
| 281 // This class receives javascript messages from the renderer. | 210 // This class receives javascript messages from the renderer. |
| 282 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 211 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
| 283 // this class's methods are expected to run on the UI thread. | 212 // this class's methods are expected to run on the UI thread. |
| 284 // | 213 // |
| 285 // Since the network code we want to run lives on the IO thread, we proxy | 214 // Since the network code we want to run lives on the IO thread, we proxy |
| 286 // almost everything over to NetInternalsMessageHandler::IOThreadImpl, which | 215 // almost everything over to NetInternalsMessageHandler::IOThreadImpl, which |
| 287 // runs on the IO thread. | 216 // runs on the IO thread. |
| 288 // | 217 // |
| 289 // TODO(eroman): Can we start on the IO thread to begin with? | 218 // TODO(eroman): Can we start on the IO thread to begin with? |
| 290 class NetInternalsMessageHandler | 219 class NetInternalsMessageHandler |
| (...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 onc_blob, passcode)); | 1456 onc_blob, passcode)); |
| 1528 } | 1457 } |
| 1529 | 1458 |
| 1530 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) { | 1459 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) { |
| 1531 DCHECK(list); | 1460 DCHECK(list); |
| 1532 | 1461 |
| 1533 SendJavascriptCommand("receivedStoreDebugLogs", | 1462 SendJavascriptCommand("receivedStoreDebugLogs", |
| 1534 new base::StringValue("Creating log file...")); | 1463 new base::StringValue("Creating log file...")); |
| 1535 const DownloadPrefs* const prefs = | 1464 const DownloadPrefs* const prefs = |
| 1536 DownloadPrefs::FromBrowserContext(Profile::FromWebUI(web_ui())); | 1465 DownloadPrefs::FromBrowserContext(Profile::FromWebUI(web_ui())); |
| 1537 StoreDebugLogs(prefs->DownloadPath(), | 1466 chromeos::DebugLogWriter::StoreLogs(prefs->DownloadPath(), |
| 1538 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted, | 1467 base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted, |
| 1539 AsWeakPtr())); | 1468 AsWeakPtr())); |
| 1540 } | 1469 } |
| 1541 | 1470 |
| 1542 void NetInternalsMessageHandler::OnStoreDebugLogsCompleted( | 1471 void NetInternalsMessageHandler::OnStoreDebugLogsCompleted( |
| 1543 const base::FilePath& log_path, bool succeeded) { | 1472 const base::FilePath& log_path, bool succeeded) { |
| 1544 std::string status; | 1473 std::string status; |
| 1545 if (succeeded) | 1474 if (succeeded) |
| 1546 status = "Created log file: " + log_path.BaseName().AsUTF8Unsafe(); | 1475 status = "Created log file: " + log_path.BaseName().AsUTF8Unsafe(); |
| 1547 else | 1476 else |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 } | 1702 } |
| 1774 | 1703 |
| 1775 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) | 1704 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) |
| 1776 : WebUIController(web_ui) { | 1705 : WebUIController(web_ui) { |
| 1777 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); | 1706 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); |
| 1778 | 1707 |
| 1779 // Set up the chrome://net-internals/ source. | 1708 // Set up the chrome://net-internals/ source. |
| 1780 Profile* profile = Profile::FromWebUI(web_ui); | 1709 Profile* profile = Profile::FromWebUI(web_ui); |
| 1781 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); | 1710 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); |
| 1782 } | 1711 } |
| OLD | NEW |