| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/policy/user_network_configuration_updater.h" | 5 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | |
| 12 #include "chrome/browser/chromeos/net/onc_utils.h" | 11 #include "chrome/browser/chromeos/net/onc_utils.h" |
| 13 #include "chrome/browser/net/nss_context.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chromeos/network/managed_network_configuration_handler.h" | 13 #include "chromeos/network/managed_network_configuration_handler.h" |
| 16 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 14 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
| 17 #include "components/user_manager/user.h" | 15 #include "components/user_manager/user.h" |
| 18 #include "content/public/browser/notification_source.h" | |
| 19 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
| 20 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
| 21 | 18 |
| 22 namespace policy { | 19 namespace policy { |
| 23 | 20 |
| 24 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {} | 21 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {} |
| 25 | 22 |
| 26 // static | 23 // static |
| 27 scoped_ptr<UserNetworkConfigurationUpdater> | 24 scoped_ptr<UserNetworkConfigurationUpdater> |
| 28 UserNetworkConfigurationUpdater::CreateForUserPolicy( | 25 UserNetworkConfigurationUpdater::CreateForUserPolicy( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 57 const user_manager::User& user, | 54 const user_manager::User& user, |
| 58 PolicyService* policy_service, | 55 PolicyService* policy_service, |
| 59 chromeos::ManagedNetworkConfigurationHandler* network_config_handler) | 56 chromeos::ManagedNetworkConfigurationHandler* network_config_handler) |
| 60 : NetworkConfigurationUpdater(onc::ONC_SOURCE_USER_POLICY, | 57 : NetworkConfigurationUpdater(onc::ONC_SOURCE_USER_POLICY, |
| 61 key::kOpenNetworkConfiguration, | 58 key::kOpenNetworkConfiguration, |
| 62 policy_service, | 59 policy_service, |
| 63 network_config_handler), | 60 network_config_handler), |
| 64 allow_trusted_certificates_from_policy_(allow_trusted_certs_from_policy), | 61 allow_trusted_certificates_from_policy_(allow_trusted_certs_from_policy), |
| 65 user_(&user), | 62 user_(&user), |
| 66 weak_factory_(this) { | 63 weak_factory_(this) { |
| 67 // The updater is created with |certificate_importer_| unset and is | |
| 68 // responsible for creating it. This requires |GetNSSCertDatabaseForProfile| | |
| 69 // call, which is not safe before the profile initialization is finalized. | |
| 70 // Thus, listen for PROFILE_ADDED notification, on which |cert_importer_| | |
| 71 // creation should start. | |
| 72 registrar_.Add(this, | |
| 73 chrome::NOTIFICATION_PROFILE_ADDED, | |
| 74 content::Source<Profile>(profile)); | |
| 75 } | 64 } |
| 76 | 65 |
| 77 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest( | 66 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest( |
| 78 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { | 67 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { |
| 79 SetCertificateImporter(certificate_importer.Pass()); | 68 SetCertificateImporter(certificate_importer.Pass()); |
| 80 } | 69 } |
| 81 | 70 |
| 82 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates( | 71 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates( |
| 83 net::CertificateList* certs) const { | 72 net::CertificateList* certs) const { |
| 84 *certs = web_trust_certs_; | 73 *certs = web_trust_certs_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 107 base::DictionaryValue* global_network_config) { | 96 base::DictionaryValue* global_network_config) { |
| 108 DCHECK(user_); | 97 DCHECK(user_); |
| 109 chromeos::onc::ExpandStringPlaceholdersInNetworksForUser(user_, | 98 chromeos::onc::ExpandStringPlaceholdersInNetworksForUser(user_, |
| 110 network_configs_onc); | 99 network_configs_onc); |
| 111 network_config_handler_->SetPolicy(onc_source_, | 100 network_config_handler_->SetPolicy(onc_source_, |
| 112 user_->username_hash(), | 101 user_->username_hash(), |
| 113 *network_configs_onc, | 102 *network_configs_onc, |
| 114 *global_network_config); | 103 *global_network_config); |
| 115 } | 104 } |
| 116 | 105 |
| 117 void UserNetworkConfigurationUpdater::Observe( | |
| 118 int type, | |
| 119 const content::NotificationSource& source, | |
| 120 const content::NotificationDetails& details) { | |
| 121 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); | |
| 122 Profile* profile = content::Source<Profile>(source).ptr(); | |
| 123 | |
| 124 GetNSSCertDatabaseForProfile( | |
| 125 profile, | |
| 126 base::Bind( | |
| 127 &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter, | |
| 128 weak_factory_.GetWeakPtr())); | |
| 129 } | |
| 130 | |
| 131 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter( | 106 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter( |
| 132 net::NSSCertDatabase* database) { | 107 net::NSSCertDatabase* database) { |
| 133 DCHECK(database); | 108 DCHECK(database); |
| 134 SetCertificateImporter(scoped_ptr<chromeos::onc::CertificateImporter>( | 109 SetCertificateImporter(scoped_ptr<chromeos::onc::CertificateImporter>( |
| 135 new chromeos::onc::CertificateImporterImpl(database))); | 110 new chromeos::onc::CertificateImporterImpl(database))); |
| 136 } | 111 } |
| 137 | 112 |
| 138 void UserNetworkConfigurationUpdater::SetCertificateImporter( | 113 void UserNetworkConfigurationUpdater::SetCertificateImporter( |
| 139 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { | 114 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { |
| 115 DCHECK(!certificate_importer_); |
| 140 certificate_importer_ = certificate_importer.Pass(); | 116 certificate_importer_ = certificate_importer.Pass(); |
| 141 | 117 |
| 142 if (pending_certificates_onc_) | 118 if (pending_certificates_onc_) |
| 143 ImportCertificates(*pending_certificates_onc_); | 119 ImportCertificates(*pending_certificates_onc_); |
| 144 pending_certificates_onc_.reset(); | 120 pending_certificates_onc_.reset(); |
| 145 } | 121 } |
| 146 | 122 |
| 147 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() { | 123 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() { |
| 148 FOR_EACH_OBSERVER(WebTrustedCertsObserver, | 124 FOR_EACH_OBSERVER(WebTrustedCertsObserver, |
| 149 observer_list_, | 125 observer_list_, |
| 150 OnTrustAnchorsChanged(web_trust_certs_)); | 126 OnTrustAnchorsChanged(web_trust_certs_)); |
| 151 } | 127 } |
| 152 | 128 |
| 153 } // namespace policy | 129 } // namespace policy |
| OLD | NEW |