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

Unified Diff: chromeos/network/onc/onc_certificate_importer_impl.cc

Issue 419013003: Replace c/b/nss_context by a KeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Flattened components/cert_database folders. 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/network/onc/onc_certificate_importer_impl.cc
diff --git a/chromeos/network/onc/onc_certificate_importer_impl.cc b/chromeos/network/onc/onc_certificate_importer_impl.cc
index 6403fb41014b4be7283a5cba6deefc79d390f524..8e1fb4b7016370764ac9084c17d1cc2077cc74b8 100644
--- a/chromeos/network/onc/onc_certificate_importer_impl.cc
+++ b/chromeos/network/onc/onc_certificate_importer_impl.cc
@@ -20,6 +20,7 @@
#include "base/values.h"
#include "chromeos/network/network_event_log.h"
#include "chromeos/network/onc/onc_utils.h"
+#include "components/cert_database/cert_database_service_io_part.h"
#include "components/onc/onc_constants.h"
#include "crypto/scoped_nss_types.h"
#include "net/base/crypto_module.h"
@@ -41,15 +42,28 @@ void CallBackOnOriginLoop(
FROM_HERE, base::Bind(callback, success, onc_trusted_certificates));
}
+// Gets the NSSCertDatabase from |cert_db_io| and passes it to |callback|.
+void GetNSSCertDatabase(
+ const base::WeakPtr<cert_database::CertDatabaseServiceIOPart>& cert_db_io,
+ const cert_database::CertDatabaseServiceIOPart::GetCertDBCallback&
+ callback) {
+ if (!cert_db_io) {
+ callback.Run(NULL /* no NSSCertDatabase */);
+ return;
+ }
+ net::NSSCertDatabase* nss_db = cert_db_io->GetNSSCertDatabase(callback);
+ if (nss_db)
+ callback.Run(nss_db);
+}
+
} // namespace
CertificateImporterImpl::CertificateImporterImpl(
const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
- net::NSSCertDatabase* target_nssdb)
+ const base::WeakPtr<cert_database::CertDatabaseServiceIOPart>& cert_db_io)
: io_task_runner_(io_task_runner),
- target_nssdb_(target_nssdb),
+ cert_db_io_(cert_db_io),
weak_factory_(this) {
- CHECK(target_nssdb);
}
CertificateImporterImpl::~CertificateImporterImpl() {
@@ -74,16 +88,19 @@ void CertificateImporterImpl::ImportCertificates(
base::ThreadTaskRunnerHandle::Get(),
callback_to_this);
- // This is the actual function that imports the certificates.
- base::Closure import_certs_callback =
- base::Bind(&ParseAndStoreCertificates,
- source,
- callback_on_origin_loop,
- base::Owned(certificates.DeepCopy()),
- target_nssdb_);
-
- // The NSSCertDatabase must be accessed on |io_task_runner_|
- io_task_runner_->PostTask(FROM_HERE, import_certs_callback);
+ // This is the actual function that imports the certificates. This must be
+ // executed when the NSSCertDatabase is available.
+ cert_database::CertDatabaseServiceIOPart::GetCertDBCallback
+ import_certs_callback = base::Bind(&ParseAndStoreCertificates,
+ source,
+ callback_on_origin_loop,
+ base::Owned(certificates.DeepCopy()));
+
+ // The NSSCertDatabase is obtained from |cert_db_io_|, which must be accessed
+ // on |io_task_runner_|
+ io_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&GetNSSCertDatabase, cert_db_io_, import_certs_callback));
}
// static
@@ -92,9 +109,13 @@ void CertificateImporterImpl::ParseAndStoreCertificates(
const DoneCallback& done_callback,
base::ListValue* certificates,
net::NSSCertDatabase* nssdb) {
+ net::CertificateList onc_trusted_certificates;
+ if (!nssdb) {
+ done_callback.Run(false, onc_trusted_certificates);
+ return;
+ }
// Web trust is only granted to certificates imported by the user.
bool allow_trust_imports = source == ::onc::ONC_SOURCE_USER_IMPORT;
- net::CertificateList onc_trusted_certificates;
bool success = true;
for (size_t i = 0; i < certificates->GetSize(); ++i) {
const base::DictionaryValue* certificate = NULL;
« no previous file with comments | « chromeos/network/onc/onc_certificate_importer_impl.h ('k') | chromeos/network/onc/onc_certificate_importer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698