Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: chrome/browser/ui/webui/net_internals/net_internals_ui.cc

Issue 419013003: Replace c/b/nss_context by a KeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "net/proxy/proxy_service.h" 69 #include "net/proxy/proxy_service.h"
70 #include "net/url_request/url_request_context.h" 70 #include "net/url_request/url_request_context.h"
71 #include "net/url_request/url_request_context_getter.h" 71 #include "net/url_request/url_request_context_getter.h"
72 72
73 #if defined(OS_CHROMEOS) 73 #if defined(OS_CHROMEOS)
74 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" 74 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
75 #include "chrome/browser/chromeos/net/onc_utils.h" 75 #include "chrome/browser/chromeos/net/onc_utils.h"
76 #include "chrome/browser/chromeos/profiles/profile_helper.h" 76 #include "chrome/browser/chromeos/profiles/profile_helper.h"
77 #include "chrome/browser/chromeos/system/syslogs_provider.h" 77 #include "chrome/browser/chromeos/system/syslogs_provider.h"
78 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h" 78 #include "chrome/browser/chromeos/system_logs/debug_log_writer.h"
79 #include "chrome/browser/net/nss_context.h" 79 #include "chrome/browser/net/cert_database_service_factory.h"
80 #include "chromeos/dbus/dbus_thread_manager.h" 80 #include "chromeos/dbus/dbus_thread_manager.h"
81 #include "chromeos/dbus/debug_daemon_client.h" 81 #include "chromeos/dbus/debug_daemon_client.h"
82 #include "chromeos/network/onc/onc_certificate_importer_impl.h" 82 #include "chromeos/network/onc/onc_certificate_importer_impl.h"
83 #include "chromeos/network/onc/onc_utils.h" 83 #include "chromeos/network/onc/onc_utils.h"
84 #include "components/cert_database/public/cert_database_service.h"
84 #include "components/user_manager/user.h" 85 #include "components/user_manager/user.h"
85 #endif 86 #endif
86 87
87 #if defined(OS_WIN) 88 #if defined(OS_WIN)
88 #include "chrome/browser/net/service_providers_win.h" 89 #include "chrome/browser/net/service_providers_win.h"
89 #endif 90 #endif
90 91
91 #if defined(ENABLE_EXTENSIONS) 92 #if defined(ENABLE_EXTENSIONS)
92 #include "chrome/browser/extensions/extension_service.h" 93 #include "chrome/browser/extensions/extension_service.h"
93 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h" 94 #include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 void OnRefreshSystemLogs(const base::ListValue* list); 232 void OnRefreshSystemLogs(const base::ListValue* list);
232 void OnGetSystemLog(const base::ListValue* list); 233 void OnGetSystemLog(const base::ListValue* list);
233 void OnImportONCFile(const base::ListValue* list); 234 void OnImportONCFile(const base::ListValue* list);
234 void OnStoreDebugLogs(const base::ListValue* list); 235 void OnStoreDebugLogs(const base::ListValue* list);
235 void OnStoreDebugLogsCompleted(const base::FilePath& log_path, 236 void OnStoreDebugLogsCompleted(const base::FilePath& log_path,
236 bool succeeded); 237 bool succeeded);
237 void OnSetNetworkDebugMode(const base::ListValue* list); 238 void OnSetNetworkDebugMode(const base::ListValue* list);
238 void OnSetNetworkDebugModeCompleted(const std::string& subsystem, 239 void OnSetNetworkDebugModeCompleted(const std::string& subsystem,
239 bool succeeded); 240 bool succeeded);
240 241
241 // Callback to |GetNSSCertDatabaseForProfile| used to retrieve the database
242 // to which user's ONC defined certificates should be imported.
243 // It parses and imports |onc_blob|.
244 void ImportONCFileToNSSDB(const std::string& onc_blob,
245 const std::string& passcode,
246 net::NSSCertDatabase* nssdb);
247
248 // Called back by the CertificateImporter when a certificate import finished. 242 // Called back by the CertificateImporter when a certificate import finished.
249 // |previous_error| contains earlier errors during this import. 243 // |previous_error| contains earlier errors during this import.
250 void OnCertificatesImported( 244 void OnCertificatesImported(
251 const std::string& previous_error, 245 const std::string& previous_error,
252 bool success, 246 bool success,
253 const net::CertificateList& onc_trusted_certificates); 247 const net::CertificateList& onc_trusted_certificates);
254 #endif 248 #endif
255 249
256 private: 250 private:
257 class IOThreadImpl; 251 class IOThreadImpl;
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 syslogs_getter_->DeleteSystemLogs(); 1150 syslogs_getter_->DeleteSystemLogs();
1157 syslogs_getter_->LoadSystemLogs(); 1151 syslogs_getter_->LoadSystemLogs();
1158 } 1152 }
1159 1153
1160 void NetInternalsMessageHandler::OnGetSystemLog( 1154 void NetInternalsMessageHandler::OnGetSystemLog(
1161 const base::ListValue* list) { 1155 const base::ListValue* list) {
1162 DCHECK(syslogs_getter_.get()); 1156 DCHECK(syslogs_getter_.get());
1163 syslogs_getter_->RequestSystemLog(list); 1157 syslogs_getter_->RequestSystemLog(list);
1164 } 1158 }
1165 1159
1166 void NetInternalsMessageHandler::ImportONCFileToNSSDB( 1160 void NetInternalsMessageHandler::OnImportONCFile(const base::ListValue* list) {
1167 const std::string& onc_blob, 1161 std::string onc_blob;
1168 const std::string& passcode, 1162 std::string passcode;
1169 net::NSSCertDatabase* nssdb) { 1163 if (list->GetSize() != 2 || !list->GetString(0, &onc_blob) ||
1164 !list->GetString(1, &passcode)) {
1165 NOTREACHED();
1166 }
1167
1170 user_manager::User* user = chromeos::ProfileHelper::Get()->GetUserByProfile( 1168 user_manager::User* user = chromeos::ProfileHelper::Get()->GetUserByProfile(
1171 Profile::FromWebUI(web_ui())); 1169 Profile::FromWebUI(web_ui()));
1172 1170
1173 if (!user) { 1171 if (!user) {
1174 std::string error = "User not found."; 1172 std::string error = "User not found.";
1175 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error)); 1173 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error));
1176 return; 1174 return;
1177 } 1175 }
1178 1176
1179 std::string error; 1177 std::string error;
1180 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT; 1178 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT;
1181 base::ListValue network_configs; 1179 base::ListValue network_configs;
1182 base::DictionaryValue global_network_config; 1180 base::DictionaryValue global_network_config;
1183 base::ListValue certificates; 1181 base::ListValue certificates;
1184 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob, 1182 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob,
1185 onc_source, 1183 onc_source,
1186 passcode, 1184 passcode,
1187 &network_configs, 1185 &network_configs,
1188 &global_network_config, 1186 &global_network_config,
1189 &certificates)) { 1187 &certificates)) {
1190 error = "Errors occurred during the ONC parsing. "; 1188 error = "Errors occurred during the ONC parsing. ";
1191 } 1189 }
1192 1190
1193 std::string network_error; 1191 std::string network_error;
1194 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error); 1192 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error);
1195 if (!network_error.empty()) 1193 if (!network_error.empty())
1196 error += network_error; 1194 error += network_error;
1197 1195
1196 cert_database::CertDatabaseService* cert_service =
1197 cert_database::CertDatabaseServiceFactory::GetForBrowserContext(
1198 web_ui()->GetWebContents()->GetBrowserContext());
1198 chromeos::onc::CertificateImporterImpl cert_importer( 1199 chromeos::onc::CertificateImporterImpl cert_importer(
1199 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), nssdb); 1200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
1201 cert_service->GetIOPart());
1200 cert_importer.ImportCertificates( 1202 cert_importer.ImportCertificates(
1201 certificates, 1203 certificates,
1202 onc_source, 1204 onc_source,
1203 base::Bind(&NetInternalsMessageHandler::OnCertificatesImported, 1205 base::Bind(&NetInternalsMessageHandler::OnCertificatesImported,
1204 AsWeakPtr(), 1206 AsWeakPtr(),
1205 error)); 1207 error));
1206 } 1208 }
1207 1209
1208 void NetInternalsMessageHandler::OnCertificatesImported( 1210 void NetInternalsMessageHandler::OnCertificatesImported(
1209 const std::string& previous_error, 1211 const std::string& previous_error,
1210 bool success, 1212 bool success,
1211 const net::CertificateList& /* unused onc_trusted_certificates */) { 1213 const net::CertificateList& /* unused onc_trusted_certificates */) {
1212 std::string error = previous_error; 1214 std::string error = previous_error;
1213 if (!success) 1215 if (!success)
1214 error += "Some certificates couldn't be imported. "; 1216 error += "Some certificates couldn't be imported. ";
1215 1217
1216 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error)); 1218 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error));
1217 } 1219 }
1218 1220
1219 void NetInternalsMessageHandler::OnImportONCFile(
1220 const base::ListValue* list) {
1221 std::string onc_blob;
1222 std::string passcode;
1223 if (list->GetSize() != 2 ||
1224 !list->GetString(0, &onc_blob) ||
1225 !list->GetString(1, &passcode)) {
1226 NOTREACHED();
1227 }
1228
1229 GetNSSCertDatabaseForProfile(
1230 Profile::FromWebUI(web_ui()),
1231 base::Bind(&NetInternalsMessageHandler::ImportONCFileToNSSDB, AsWeakPtr(),
1232 onc_blob, passcode));
1233 }
1234
1235 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) { 1221 void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) {
1236 DCHECK(list); 1222 DCHECK(list);
1237 1223
1238 SendJavascriptCommand("receivedStoreDebugLogs", 1224 SendJavascriptCommand("receivedStoreDebugLogs",
1239 new base::StringValue("Creating log file...")); 1225 new base::StringValue("Creating log file..."));
1240 Profile* profile = Profile::FromWebUI(web_ui()); 1226 Profile* profile = Profile::FromWebUI(web_ui());
1241 const DownloadPrefs* const prefs = DownloadPrefs::FromBrowserContext(profile); 1227 const DownloadPrefs* const prefs = DownloadPrefs::FromBrowserContext(profile);
1242 base::FilePath path = prefs->DownloadPath(); 1228 base::FilePath path = prefs->DownloadPath();
1243 if (file_manager::util::IsUnderNonNativeLocalPath(profile, path)) 1229 if (file_manager::util::IsUnderNonNativeLocalPath(profile, path))
1244 path = prefs->GetDefaultDownloadDirectoryForProfile(); 1230 path = prefs->GetDefaultDownloadDirectoryForProfile();
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 } 1471 }
1486 1472
1487 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1473 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1488 : WebUIController(web_ui) { 1474 : WebUIController(web_ui) {
1489 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1475 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1490 1476
1491 // Set up the chrome://net-internals/ source. 1477 // Set up the chrome://net-internals/ source.
1492 Profile* profile = Profile::FromWebUI(web_ui); 1478 Profile* profile = Profile::FromWebUI(web_ui);
1493 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); 1479 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource());
1494 } 1480 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698