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" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/chromeos/login/users/user.h" | 12 #include "chrome/browser/chromeos/login/users/user.h" |
13 #include "chrome/browser/chromeos/net/onc_utils.h" | 13 #include "chrome/browser/chromeos/net/onc_utils.h" |
14 #include "chrome/browser/net/nss_context.h" | 14 #include "chrome/browser/net/nss_context.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chromeos/network/managed_network_configuration_handler.h" | 16 #include "chromeos/network/managed_network_configuration_handler.h" |
17 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | 17 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
20 #include "policy/policy_constants.h" | 20 #include "policy/policy_constants.h" |
21 | 21 |
22 namespace { | |
23 | |
24 bool skip_certificate_importer_creation_for_test = false; | |
25 | |
26 } // namespace | |
27 | |
28 namespace policy { | 22 namespace policy { |
29 | 23 |
30 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {} | 24 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {} |
31 | 25 |
32 // static | 26 // static |
33 scoped_ptr<UserNetworkConfigurationUpdater> | 27 scoped_ptr<UserNetworkConfigurationUpdater> |
34 UserNetworkConfigurationUpdater::CreateForUserPolicy( | 28 UserNetworkConfigurationUpdater::CreateForUserPolicy( |
35 Profile* profile, | 29 Profile* profile, |
36 bool allow_trusted_certs_from_policy, | 30 bool allow_trusted_certs_from_policy, |
37 const chromeos::User& user, | 31 const chromeos::User& user, |
(...skipping 29 matching lines...) Expand all Loading... |
67 key::kOpenNetworkConfiguration, | 61 key::kOpenNetworkConfiguration, |
68 policy_service, | 62 policy_service, |
69 network_config_handler), | 63 network_config_handler), |
70 allow_trusted_certificates_from_policy_(allow_trusted_certs_from_policy), | 64 allow_trusted_certificates_from_policy_(allow_trusted_certs_from_policy), |
71 user_(&user), | 65 user_(&user), |
72 weak_factory_(this) { | 66 weak_factory_(this) { |
73 // The updater is created with |certificate_importer_| unset and is | 67 // The updater is created with |certificate_importer_| unset and is |
74 // responsible for creating it. This requires |GetNSSCertDatabaseForProfile| | 68 // responsible for creating it. This requires |GetNSSCertDatabaseForProfile| |
75 // call, which is not safe before the profile initialization is finalized. | 69 // call, which is not safe before the profile initialization is finalized. |
76 // Thus, listen for PROFILE_ADDED notification, on which |cert_importer_| | 70 // Thus, listen for PROFILE_ADDED notification, on which |cert_importer_| |
77 // creation should start. This behaviour can be disabled in tests. | 71 // creation should start. |
78 if (!skip_certificate_importer_creation_for_test) { | 72 registrar_.Add(this, |
79 registrar_.Add(this, | 73 chrome::NOTIFICATION_PROFILE_ADDED, |
80 chrome::NOTIFICATION_PROFILE_ADDED, | 74 content::Source<Profile>(profile)); |
81 content::Source<Profile>(profile)); | |
82 } | |
83 } | 75 } |
84 | 76 |
85 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest( | 77 void UserNetworkConfigurationUpdater::SetCertificateImporterForTest( |
86 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { | 78 scoped_ptr<chromeos::onc::CertificateImporter> certificate_importer) { |
87 SetCertificateImporter(certificate_importer.Pass()); | 79 SetCertificateImporter(certificate_importer.Pass()); |
88 } | 80 } |
89 | 81 |
90 // static | |
91 void UserNetworkConfigurationUpdater:: | |
92 SetSkipCertificateImporterCreationForTest(bool skip) { | |
93 skip_certificate_importer_creation_for_test = skip; | |
94 } | |
95 | |
96 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates( | 82 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates( |
97 net::CertificateList* certs) const { | 83 net::CertificateList* certs) const { |
98 *certs = web_trust_certs_; | 84 *certs = web_trust_certs_; |
99 } | 85 } |
100 | 86 |
101 void UserNetworkConfigurationUpdater::ImportCertificates( | 87 void UserNetworkConfigurationUpdater::ImportCertificates( |
102 const base::ListValue& certificates_onc) { | 88 const base::ListValue& certificates_onc) { |
103 // If certificate importer is not yet set, cache the certificate onc. It will | 89 // If certificate importer is not yet set, cache the certificate onc. It will |
104 // be imported when the certificate importer gets set. | 90 // be imported when the certificate importer gets set. |
105 if (!certificate_importer_) { | 91 if (!certificate_importer_) { |
(...skipping 22 matching lines...) Expand all Loading... |
128 *global_network_config); | 114 *global_network_config); |
129 } | 115 } |
130 | 116 |
131 void UserNetworkConfigurationUpdater::Observe( | 117 void UserNetworkConfigurationUpdater::Observe( |
132 int type, | 118 int type, |
133 const content::NotificationSource& source, | 119 const content::NotificationSource& source, |
134 const content::NotificationDetails& details) { | 120 const content::NotificationDetails& details) { |
135 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); | 121 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_ADDED); |
136 Profile* profile = content::Source<Profile>(source).ptr(); | 122 Profile* profile = content::Source<Profile>(source).ptr(); |
137 | 123 |
138 if (skip_certificate_importer_creation_for_test) | |
139 return; | |
140 | |
141 GetNSSCertDatabaseForProfile( | 124 GetNSSCertDatabaseForProfile( |
142 profile, | 125 profile, |
143 base::Bind( | 126 base::Bind( |
144 &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter, | 127 &UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter, |
145 weak_factory_.GetWeakPtr())); | 128 weak_factory_.GetWeakPtr())); |
146 } | 129 } |
147 | 130 |
148 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter( | 131 void UserNetworkConfigurationUpdater::CreateAndSetCertificateImporter( |
149 net::NSSCertDatabase* database) { | 132 net::NSSCertDatabase* database) { |
150 DCHECK(database); | 133 DCHECK(database); |
(...skipping 10 matching lines...) Expand all Loading... |
161 pending_certificates_onc_.reset(); | 144 pending_certificates_onc_.reset(); |
162 } | 145 } |
163 | 146 |
164 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() { | 147 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() { |
165 FOR_EACH_OBSERVER(WebTrustedCertsObserver, | 148 FOR_EACH_OBSERVER(WebTrustedCertsObserver, |
166 observer_list_, | 149 observer_list_, |
167 OnTrustAnchorsChanged(web_trust_certs_)); | 150 OnTrustAnchorsChanged(web_trust_certs_)); |
168 } | 151 } |
169 | 152 |
170 } // namespace policy | 153 } // namespace policy |
OLD | NEW |