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

Unified Diff: chrome/browser/chromeos/policy/user_network_configuration_updater.cc

Issue 148183013: Use per-user nssdb in onc certificate importer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/user_network_configuration_updater.cc
diff --git a/chrome/browser/chromeos/policy/user_network_configuration_updater.cc b/chrome/browser/chromeos/policy/user_network_configuration_updater.cc
index 1c7ac35da91e1e0daf2c53103eb33553fc96de91..29ae14ec492701ec22ece476abb8f4af5aa4e8d7 100644
--- a/chrome/browser/chromeos/policy/user_network_configuration_updater.cc
+++ b/chrome/browser/chromeos/policy/user_network_configuration_updater.cc
@@ -7,14 +7,25 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/logging.h"
+#include "base/values.h"
+#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/user.h"
#include "chrome/browser/chromeos/net/onc_utils.h"
+#include "chrome/browser/net/nss_context.h"
+#include "chrome/browser/profiles/profile.h"
#include "chromeos/network/managed_network_configuration_handler.h"
-#include "chromeos/network/onc/onc_certificate_importer.h"
+#include "chromeos/network/onc/onc_certificate_importer_impl.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_source.h"
#include "net/cert/x509_certificate.h"
#include "policy/policy_constants.h"
+namespace {
+
+bool skip_certificate_importer_creation_for_test = false;
+
+} // namespace
+
namespace policy {
UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {}
@@ -22,15 +33,15 @@ UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {}
// static
scoped_ptr<UserNetworkConfigurationUpdater>
UserNetworkConfigurationUpdater::CreateForUserPolicy(
+ Profile* profile,
bool allow_trusted_certs_from_policy,
const chromeos::User& user,
- scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer,
PolicyService* policy_service,
chromeos::ManagedNetworkConfigurationHandler* network_config_handler) {
scoped_ptr<UserNetworkConfigurationUpdater> updater(
- new UserNetworkConfigurationUpdater(allow_trusted_certs_from_policy,
+ new UserNetworkConfigurationUpdater(profile,
+ allow_trusted_certs_from_policy,
user,
- certificate_importer.Pass(),
policy_service,
network_config_handler));
updater->Init();
@@ -48,18 +59,41 @@ void UserNetworkConfigurationUpdater::RemoveTrustedCertsObserver(
}
UserNetworkConfigurationUpdater::UserNetworkConfigurationUpdater(
+ Profile* profile,
bool allow_trusted_certs_from_policy,
const chromeos::User& user,
- scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer,
PolicyService* policy_service,
chromeos::ManagedNetworkConfigurationHandler* network_config_handler)
: NetworkConfigurationUpdater(onc::ONC_SOURCE_USER_POLICY,
key::kOpenNetworkConfiguration,
- certificate_importer.Pass(),
policy_service,
network_config_handler),
allow_trusted_certificates_from_policy_(allow_trusted_certs_from_policy),
- user_(&user) {}
+ user_(&user),
+ profile_(profile),
pneubeck (no reviews) 2014/02/07 08:56:35 please don't store Profile*. They tend to be misus
+ weak_factory_(this) {
+ // The updater is created with |certificate_importer_| unset and is
+ // responsible for creating it. This requires |GetNSSCertDatabaseForProfile|
+ // call, which is not safe before the profile initialization is finalized.
+ // Thus, listen for PROFILE_ADDED notification, on which |cert_importer_|
+ // creation should start. This behaviour can be disabled in tests.
+ if (!skip_certificate_importer_creation_for_test) {
+ registrar_.Add(this,
+ chrome::NOTIFICATION_PROFILE_ADDED,
+ content::Source<Profile>(profile));
+ }
+}
+
+void UserNetworkConfigurationUpdater::SetCertificateImporterForTest(
+ scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) {
+ SetCertificateImporter(certificate_importer.Pass());
+}
+
+// static
+void UserNetworkConfigurationUpdater::
+SetSkipCertificateImporterCreationForTest(bool skip) {
+ skip_certificate_importer_creation_for_test = skip;
+}
void UserNetworkConfigurationUpdater::GetWebTrustedCertificates(
net::CertificateList* certs) const {
@@ -68,6 +102,13 @@ void UserNetworkConfigurationUpdater::GetWebTrustedCertificates(
void UserNetworkConfigurationUpdater::ImportCertificates(
const base::ListValue& certificates_onc) {
+ // If certificate importer is not yet set, cache the certificate onc. It will
+ // be imported when the certificate importer gets set.
+ if (!certificate_importer_) {
+ pending_certificates_onc_.reset(certificates_onc.DeepCopy());
+ return;
+ }
+
web_trust_certs_.clear();
certificate_importer_->ImportCertificates(
certificates_onc,
@@ -89,6 +130,40 @@ void UserNetworkConfigurationUpdater::ApplyNetworkPolicy(
*global_network_config);
}
+void UserNetworkConfigurationUpdater::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED);
+ Profile* profile = content::Source<Profile>(source).ptr();
+ DCHECK_EQ(profile_, profile);
+
+ if (skip_certificate_importer_creation_for_test)
+ return;
+
+ GetNSSCertDatabaseForProfile(
+ profile,
+ base::Bind(
+ &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter,
+ weak_factory_.GetWeakPtr()));
+}
+
+void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter(
+ net::NSSCertDatabase* database) {
+ DCHECK(database);
+ SetCertificateImporter(scoped_ptr<chromeos::onc::CertificateImporter>(
+ new chromeos::onc::CertificateImporterImpl(database)));
+}
+
+void UserNetworkConfigurationUpdater::SetCertificateImporter(
+ scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) {
+ certificate_importer_ = certificate_importer.Pass();
+
+ if (pending_certificates_onc_)
+ ImportCertificates(*pending_certificates_onc_);
+ pending_certificates_onc_.reset();
+}
+
void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() {
FOR_EACH_OBSERVER(WebTrustedCertsObserver,
observer_list_,

Powered by Google App Engine
This is Rietveld 408576698