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

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

Issue 547553005: Make ONCCertificateImporter async. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nss_util_deadcode
Patch Set: Simplified NSSCertDatabase creation in unit test. Created 6 years, 3 months 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
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 void OnSetNetworkDebugMode(const base::ListValue* list); 250 void OnSetNetworkDebugMode(const base::ListValue* list);
251 void OnSetNetworkDebugModeCompleted(const std::string& subsystem, 251 void OnSetNetworkDebugModeCompleted(const std::string& subsystem,
252 bool succeeded); 252 bool succeeded);
253 253
254 // Callback to |GetNSSCertDatabaseForProfile| used to retrieve the database 254 // Callback to |GetNSSCertDatabaseForProfile| used to retrieve the database
255 // to which user's ONC defined certificates should be imported. 255 // to which user's ONC defined certificates should be imported.
256 // It parses and imports |onc_blob|. 256 // It parses and imports |onc_blob|.
257 void ImportONCFileToNSSDB(const std::string& onc_blob, 257 void ImportONCFileToNSSDB(const std::string& onc_blob,
258 const std::string& passcode, 258 const std::string& passcode,
259 net::NSSCertDatabase* nssdb); 259 net::NSSCertDatabase* nssdb);
260
261 // Called back by the CertificateImporter when a certificate import finished.
262 // |error| contains earlier errors during this import.
263 void OnCertificatesImported(
264 const std::string& previous_error,
265 bool success,
266 const net::CertificateList& onc_trusted_certificates);
260 #endif 267 #endif
261 268
262 private: 269 private:
263 class IOThreadImpl; 270 class IOThreadImpl;
264 271
265 #if defined(OS_CHROMEOS) 272 #if defined(OS_CHROMEOS)
266 // Class that is used for getting network related ChromeOS logs. 273 // Class that is used for getting network related ChromeOS logs.
267 // Logs are fetched from ChromeOS libcros on user request, and only when we 274 // Logs are fetched from ChromeOS libcros on user request, and only when we
268 // don't yet have a copy of logs. If a copy is present, we send back data from 275 // don't yet have a copy of logs. If a copy is present, we send back data from
269 // it, else we save request and answer to it when we get logs from libcros. 276 // it, else we save request and answer to it when we get logs from libcros.
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 void NetInternalsMessageHandler::OnGetSystemLog( 1407 void NetInternalsMessageHandler::OnGetSystemLog(
1401 const base::ListValue* list) { 1408 const base::ListValue* list) {
1402 DCHECK(syslogs_getter_.get()); 1409 DCHECK(syslogs_getter_.get());
1403 syslogs_getter_->RequestSystemLog(list); 1410 syslogs_getter_->RequestSystemLog(list);
1404 } 1411 }
1405 1412
1406 void NetInternalsMessageHandler::ImportONCFileToNSSDB( 1413 void NetInternalsMessageHandler::ImportONCFileToNSSDB(
1407 const std::string& onc_blob, 1414 const std::string& onc_blob,
1408 const std::string& passcode, 1415 const std::string& passcode,
1409 net::NSSCertDatabase* nssdb) { 1416 net::NSSCertDatabase* nssdb) {
1410 std::string error;
1411 user_manager::User* user = chromeos::ProfileHelper::Get()->GetUserByProfile( 1417 user_manager::User* user = chromeos::ProfileHelper::Get()->GetUserByProfile(
1412 Profile::FromWebUI(web_ui())); 1418 Profile::FromWebUI(web_ui()));
1413 1419
1414 if (user) { 1420 if (!user) {
1415 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT; 1421 std::string error = "User not found.";
1416 1422 LOG(ERROR) << error;
1417 base::ListValue network_configs; 1423 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error));
1418 base::DictionaryValue global_network_config; 1424 return;
1419 base::ListValue certificates;
1420 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob,
1421 onc_source,
1422 passcode,
1423 &network_configs,
1424 &global_network_config,
1425 &certificates)) {
1426 error = "Errors occurred during the ONC parsing. ";
1427 }
1428
1429 chromeos::onc::CertificateImporterImpl cert_importer(nssdb);
1430 if (!cert_importer.ImportCertificates(certificates, onc_source, NULL))
1431 error += "Some certificates couldn't be imported. ";
1432
1433 std::string network_error;
1434 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error);
1435 if (!network_error.empty())
1436 error += network_error;
1437 } else {
1438 error = "User not found.";
1439 } 1425 }
1440 1426
1441 LOG_IF(ERROR, !error.empty()) << error; 1427 std::string error;
1428 onc::ONCSource onc_source = onc::ONC_SOURCE_USER_IMPORT;
1429 base::ListValue network_configs;
1430 base::DictionaryValue global_network_config;
1431 base::ListValue certificates;
1432 if (!chromeos::onc::ParseAndValidateOncForImport(onc_blob,
1433 onc_source,
1434 passcode,
1435 &network_configs,
1436 &global_network_config,
1437 &certificates)) {
1438 error = "Errors occurred during the ONC parsing. ";
1439 }
1440
1441 std::string network_error;
1442 chromeos::onc::ImportNetworksForUser(user, network_configs, &network_error);
1443 if (!network_error.empty())
1444 error += network_error;
1445
1446 chromeos::onc::CertificateImporterImpl cert_importer(
1447 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), nssdb);
1448 cert_importer.ImportCertificates(
1449 certificates,
1450 onc_source,
1451 base::Bind(&NetInternalsMessageHandler::OnCertificatesImported,
1452 AsWeakPtr(),
1453 error));
1454 }
1455
1456 void NetInternalsMessageHandler::OnCertificatesImported(
1457 const std::string& previous_error,
1458 bool success,
1459 const net::CertificateList& /* unused onc_trusted_certificates */) {
1460 std::string error = previous_error;
1461 if (!success)
1462 error += "Some certificates couldn't be imported. ";
1463
1464 LOG(ERROR) << error;
1442 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error)); 1465 SendJavascriptCommand("receivedONCFileParse", new base::StringValue(error));
1443 } 1466 }
1444 1467
1445 void NetInternalsMessageHandler::OnImportONCFile( 1468 void NetInternalsMessageHandler::OnImportONCFile(
1446 const base::ListValue* list) { 1469 const base::ListValue* list) {
1447 std::string onc_blob; 1470 std::string onc_blob;
1448 std::string passcode; 1471 std::string passcode;
1449 if (list->GetSize() != 2 || 1472 if (list->GetSize() != 2 ||
1450 !list->GetString(0, &onc_blob) || 1473 !list->GetString(0, &onc_blob) ||
1451 !list->GetString(1, &passcode)) { 1474 !list->GetString(1, &passcode)) {
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 } 1732 }
1710 1733
1711 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui) 1734 NetInternalsUI::NetInternalsUI(content::WebUI* web_ui)
1712 : WebUIController(web_ui) { 1735 : WebUIController(web_ui) {
1713 web_ui->AddMessageHandler(new NetInternalsMessageHandler()); 1736 web_ui->AddMessageHandler(new NetInternalsMessageHandler());
1714 1737
1715 // Set up the chrome://net-internals/ source. 1738 // Set up the chrome://net-internals/ source.
1716 Profile* profile = Profile::FromWebUI(web_ui); 1739 Profile* profile = Profile::FromWebUI(web_ui);
1717 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource()); 1740 content::WebUIDataSource::Add(profile, CreateNetInternalsHTMLSource());
1718 } 1741 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698