| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/chromeos/net/onc_utils.h" | 14 #include "chrome/browser/chromeos/net/onc_utils.h" |
| 15 #include "chrome/browser/net/nss_context.h" | 15 #include "chrome/browser/net/nss_context.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chromeos/network/managed_network_configuration_handler.h" | 17 #include "chromeos/network/managed_network_configuration_handler.h" |
| 18 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 18 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
| 19 #include "components/user_manager/user.h" | 19 #include "components/user_manager/user.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 22 #include "net/cert/x509_certificate.h" | 22 #include "net/cert/x509_certificate.h" |
| 23 #include "policy/policy_constants.h" | 23 #include "policy/policy_constants.h" |
| 24 | 24 |
| 25 namespace policy { | 25 namespace policy { |
| 26 | 26 |
| 27 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {} | 27 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {} |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 scoped_ptr<UserNetworkConfigurationUpdater> | 30 std::unique_ptr<UserNetworkConfigurationUpdater> |
| 31 UserNetworkConfigurationUpdater::CreateForUserPolicy( | 31 UserNetworkConfigurationUpdater::CreateForUserPolicy( |
| 32 Profile* profile, | 32 Profile* profile, |
| 33 bool allow_trusted_certs_from_policy, | 33 bool allow_trusted_certs_from_policy, |
| 34 const user_manager::User& user, | 34 const user_manager::User& user, |
| 35 PolicyService* policy_service, | 35 PolicyService* policy_service, |
| 36 chromeos::ManagedNetworkConfigurationHandler* network_config_handler) { | 36 chromeos::ManagedNetworkConfigurationHandler* network_config_handler) { |
| 37 scoped_ptr<UserNetworkConfigurationUpdater> updater( | 37 std::unique_ptr<UserNetworkConfigurationUpdater> updater( |
| 38 new UserNetworkConfigurationUpdater(profile, | 38 new UserNetworkConfigurationUpdater( |
| 39 allow_trusted_certs_from_policy, | 39 profile, allow_trusted_certs_from_policy, user, policy_service, |
| 40 user, | 40 network_config_handler)); |
| 41 policy_service, | |
| 42 network_config_handler)); | |
| 43 updater->Init(); | 41 updater->Init(); |
| 44 return updater; | 42 return updater; |
| 45 } | 43 } |
| 46 | 44 |
| 47 void UserNetworkConfigurationUpdater::AddTrustedCertsObserver( | 45 void UserNetworkConfigurationUpdater::AddTrustedCertsObserver( |
| 48 WebTrustedCertsObserver* observer) { | 46 WebTrustedCertsObserver* observer) { |
| 49 observer_list_.AddObserver(observer); | 47 observer_list_.AddObserver(observer); |
| 50 } | 48 } |
| 51 | 49 |
| 52 void UserNetworkConfigurationUpdater::RemoveTrustedCertsObserver( | 50 void UserNetworkConfigurationUpdater::RemoveTrustedCertsObserver( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 71 // responsible for creating it. This requires |GetNSSCertDatabaseForProfile| | 69 // responsible for creating it. This requires |GetNSSCertDatabaseForProfile| |
| 72 // call, which is not safe before the profile initialization is finalized. | 70 // call, which is not safe before the profile initialization is finalized. |
| 73 // Thus, listen for PROFILE_ADDED notification, on which |cert_importer_| | 71 // Thus, listen for PROFILE_ADDED notification, on which |cert_importer_| |
| 74 // creation should start. | 72 // creation should start. |
| 75 registrar_.Add(this, | 73 registrar_.Add(this, |
| 76 chrome::NOTIFICATION_PROFILE_ADDED, | 74 chrome::NOTIFICATION_PROFILE_ADDED, |
| 77 content::Source<Profile>(profile)); | 75 content::Source<Profile>(profile)); |
| 78 } | 76 } |
| 79 | 77 |
| 80 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest( | 78 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest( |
| 81 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { | 79 std::unique_ptr<chromeos::onc::CertificateImporter> certificate_importer) { |
| 82 SetCertificateImporter(std::move(certificate_importer)); | 80 SetCertificateImporter(std::move(certificate_importer)); |
| 83 } | 81 } |
| 84 | 82 |
| 85 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates( | 83 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates( |
| 86 net::CertificateList* certs) const { | 84 net::CertificateList* certs) const { |
| 87 *certs = web_trust_certs_; | 85 *certs = web_trust_certs_; |
| 88 } | 86 } |
| 89 | 87 |
| 90 void UserNetworkConfigurationUpdater::OnCertificatesImported( | 88 void UserNetworkConfigurationUpdater::OnCertificatesImported( |
| 91 bool /* unused success */, | 89 bool /* unused success */, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 GetNSSCertDatabaseForProfile( | 132 GetNSSCertDatabaseForProfile( |
| 135 profile, | 133 profile, |
| 136 base::Bind( | 134 base::Bind( |
| 137 &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter, | 135 &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter, |
| 138 weak_factory_.GetWeakPtr())); | 136 weak_factory_.GetWeakPtr())); |
| 139 } | 137 } |
| 140 | 138 |
| 141 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter( | 139 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter( |
| 142 net::NSSCertDatabase* database) { | 140 net::NSSCertDatabase* database) { |
| 143 DCHECK(database); | 141 DCHECK(database); |
| 144 SetCertificateImporter(scoped_ptr<chromeos::onc::CertificateImporter>( | 142 SetCertificateImporter(std::unique_ptr<chromeos::onc::CertificateImporter>( |
| 145 new chromeos::onc::CertificateImporterImpl( | 143 new chromeos::onc::CertificateImporterImpl( |
| 146 content::BrowserThread::GetMessageLoopProxyForThread( | 144 content::BrowserThread::GetMessageLoopProxyForThread( |
| 147 content::BrowserThread::IO), | 145 content::BrowserThread::IO), |
| 148 database))); | 146 database))); |
| 149 } | 147 } |
| 150 | 148 |
| 151 void UserNetworkConfigurationUpdater::SetCertificateImporter( | 149 void UserNetworkConfigurationUpdater::SetCertificateImporter( |
| 152 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { | 150 std::unique_ptr<chromeos::onc::CertificateImporter> certificate_importer) { |
| 153 certificate_importer_ = std::move(certificate_importer); | 151 certificate_importer_ = std::move(certificate_importer); |
| 154 | 152 |
| 155 if (pending_certificates_onc_) | 153 if (pending_certificates_onc_) |
| 156 ImportCertificates(*pending_certificates_onc_); | 154 ImportCertificates(*pending_certificates_onc_); |
| 157 pending_certificates_onc_.reset(); | 155 pending_certificates_onc_.reset(); |
| 158 } | 156 } |
| 159 | 157 |
| 160 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() { | 158 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() { |
| 161 FOR_EACH_OBSERVER(WebTrustedCertsObserver, | 159 FOR_EACH_OBSERVER(WebTrustedCertsObserver, |
| 162 observer_list_, | 160 observer_list_, |
| 163 OnTrustAnchorsChanged(web_trust_certs_)); | 161 OnTrustAnchorsChanged(web_trust_certs_)); |
| 164 } | 162 } |
| 165 | 163 |
| 166 } // namespace policy | 164 } // namespace policy |
| OLD | NEW |