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

Side by Side Diff: chrome/browser/chromeos/policy/user_network_configuration_updater.cc

Issue 547553005: Make ONCCertificateImporter async. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nss_util_deadcode
Patch Set: Fixed compilation. 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 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" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/chromeos/net/onc_utils.h" 12 #include "chrome/browser/chromeos/net/onc_utils.h"
13 #include "chrome/browser/net/nss_context.h" 13 #include "chrome/browser/net/nss_context.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chromeos/network/managed_network_configuration_handler.h" 15 #include "chromeos/network/managed_network_configuration_handler.h"
16 #include "chromeos/network/onc/onc_certificate_importer_impl.h" 16 #include "chromeos/network/onc/onc_certificate_importer_impl.h"
17 #include "components/user_manager/user.h" 17 #include "components/user_manager/user.h"
18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
19 #include "net/cert/x509_certificate.h" 20 #include "net/cert/x509_certificate.h"
20 #include "policy/policy_constants.h" 21 #include "policy/policy_constants.h"
21 22
22 namespace policy { 23 namespace policy {
23 24
24 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {} 25 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {}
25 26
26 // static 27 // static
27 scoped_ptr<UserNetworkConfigurationUpdater> 28 scoped_ptr<UserNetworkConfigurationUpdater>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest( 78 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest(
78 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { 79 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) {
79 SetCertificateImporter(certificate_importer.Pass()); 80 SetCertificateImporter(certificate_importer.Pass());
80 } 81 }
81 82
82 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates( 83 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates(
83 net::CertificateList* certs) const { 84 net::CertificateList* certs) const {
84 *certs = web_trust_certs_; 85 *certs = web_trust_certs_;
85 } 86 }
86 87
88 void UserNetworkConfigurationUpdater::OnCertificatesImported(
89 bool /* unused success */,
90 const net::CertificateList& onc_trusted_certificates) {
91 web_trust_certs_.clear();
92 if (allow_trusted_certificates_from_policy_)
93 web_trust_certs_ = onc_trusted_certificates;
94 NotifyTrustAnchorsChanged();
95 }
96
87 void UserNetworkConfigurationUpdater::ImportCertificates( 97 void UserNetworkConfigurationUpdater::ImportCertificates(
88 const base::ListValue& certificates_onc) { 98 const base::ListValue& certificates_onc) {
89 // If certificate importer is not yet set, cache the certificate onc. It will 99 // If certificate importer is not yet set, cache the certificate onc. It will
90 // be imported when the certificate importer gets set. 100 // be imported when the certificate importer gets set.
91 if (!certificate_importer_) { 101 if (!certificate_importer_) {
92 pending_certificates_onc_.reset(certificates_onc.DeepCopy()); 102 pending_certificates_onc_.reset(certificates_onc.DeepCopy());
93 return; 103 return;
94 } 104 }
95 105
96 web_trust_certs_.clear();
97 certificate_importer_->ImportCertificates( 106 certificate_importer_->ImportCertificates(
98 certificates_onc, 107 certificates_onc,
99 onc_source_, 108 onc_source_,
100 allow_trusted_certificates_from_policy_ ? &web_trust_certs_ : NULL); 109 base::Bind(&UserNetworkConfigurationUpdater::OnCertificatesImported,
101 110 base::Unretained(this)));
102 NotifyTrustAnchorsChanged();
103 } 111 }
104 112
105 void UserNetworkConfigurationUpdater::ApplyNetworkPolicy( 113 void UserNetworkConfigurationUpdater::ApplyNetworkPolicy(
106 base::ListValue* network_configs_onc, 114 base::ListValue* network_configs_onc,
107 base::DictionaryValue* global_network_config) { 115 base::DictionaryValue* global_network_config) {
108 DCHECK(user_); 116 DCHECK(user_);
109 chromeos::onc::ExpandStringPlaceholdersInNetworksForUser(user_, 117 chromeos::onc::ExpandStringPlaceholdersInNetworksForUser(user_,
110 network_configs_onc); 118 network_configs_onc);
111 network_config_handler_->SetPolicy(onc_source_, 119 network_config_handler_->SetPolicy(onc_source_,
112 user_->username_hash(), 120 user_->username_hash(),
(...skipping 12 matching lines...) Expand all
125 profile, 133 profile,
126 base::Bind( 134 base::Bind(
127 &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter, 135 &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter,
128 weak_factory_.GetWeakPtr())); 136 weak_factory_.GetWeakPtr()));
129 } 137 }
130 138
131 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter( 139 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter(
132 net::NSSCertDatabase* database) { 140 net::NSSCertDatabase* database) {
133 DCHECK(database); 141 DCHECK(database);
134 SetCertificateImporter(scoped_ptr<chromeos::onc::CertificateImporter>( 142 SetCertificateImporter(scoped_ptr<chromeos::onc::CertificateImporter>(
135 new chromeos::onc::CertificateImporterImpl(database))); 143 new chromeos::onc::CertificateImporterImpl(
144 content::BrowserThread::GetMessageLoopProxyForThread(
145 content::BrowserThread::IO),
146 database)));
136 } 147 }
137 148
138 void UserNetworkConfigurationUpdater::SetCertificateImporter( 149 void UserNetworkConfigurationUpdater::SetCertificateImporter(
139 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { 150 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) {
140 certificate_importer_ = certificate_importer.Pass(); 151 certificate_importer_ = certificate_importer.Pass();
141 152
142 if (pending_certificates_onc_) 153 if (pending_certificates_onc_)
143 ImportCertificates(*pending_certificates_onc_); 154 ImportCertificates(*pending_certificates_onc_);
144 pending_certificates_onc_.reset(); 155 pending_certificates_onc_.reset();
145 } 156 }
146 157
147 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() { 158 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() {
148 FOR_EACH_OBSERVER(WebTrustedCertsObserver, 159 FOR_EACH_OBSERVER(WebTrustedCertsObserver,
149 observer_list_, 160 observer_list_,
150 OnTrustAnchorsChanged(web_trust_certs_)); 161 OnTrustAnchorsChanged(web_trust_certs_));
151 } 162 }
152 163
153 } // namespace policy 164 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698