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