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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h"
8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
10 #include "chrome/browser/chromeos/login/user.h"
11 #include "chrome/browser/chromeos/net/onc_utils.h"
12 #include "chromeos/network/managed_network_configuration_handler.h"
13 #include "chromeos/network/onc/onc_certificate_importer.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "net/cert/x509_certificate.h"
16 #include "policy/policy_constants.h"
20 UserNetworkConfigurationUpdater::~UserNetworkConfigurationUpdater() {}
23 scoped_ptr
<UserNetworkConfigurationUpdater
>
24 UserNetworkConfigurationUpdater::CreateForUserPolicy(
25 bool allow_trusted_certs_from_policy
,
26 const chromeos::User
& user
,
27 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer
,
28 PolicyService
* policy_service
,
29 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler
) {
30 scoped_ptr
<UserNetworkConfigurationUpdater
> updater(
31 new UserNetworkConfigurationUpdater(allow_trusted_certs_from_policy
,
33 certificate_importer
.Pass(),
35 network_config_handler
));
37 return updater
.Pass();
40 void UserNetworkConfigurationUpdater::AddTrustedCertsObserver(
41 WebTrustedCertsObserver
* observer
) {
42 observer_list_
.AddObserver(observer
);
45 void UserNetworkConfigurationUpdater::RemoveTrustedCertsObserver(
46 WebTrustedCertsObserver
* observer
) {
47 observer_list_
.RemoveObserver(observer
);
50 UserNetworkConfigurationUpdater::UserNetworkConfigurationUpdater(
51 bool allow_trusted_certs_from_policy
,
52 const chromeos::User
& user
,
53 scoped_ptr
<chromeos::onc::CertificateImporter
> certificate_importer
,
54 PolicyService
* policy_service
,
55 chromeos::ManagedNetworkConfigurationHandler
* network_config_handler
)
56 : NetworkConfigurationUpdater(onc::ONC_SOURCE_USER_POLICY
,
57 key::kOpenNetworkConfiguration
,
58 certificate_importer
.Pass(),
60 network_config_handler
),
61 allow_trusted_certificates_from_policy_(allow_trusted_certs_from_policy
),
64 void UserNetworkConfigurationUpdater::GetWebTrustedCertificates(
65 net::CertificateList
* certs
) const {
66 *certs
= web_trust_certs_
;
69 void UserNetworkConfigurationUpdater::ImportCertificates(
70 const base::ListValue
& certificates_onc
) {
71 web_trust_certs_
.clear();
72 certificate_importer_
->ImportCertificates(
75 allow_trusted_certificates_from_policy_
? &web_trust_certs_
: NULL
);
77 NotifyTrustAnchorsChanged();
80 void UserNetworkConfigurationUpdater::ApplyNetworkPolicy(
81 base::ListValue
* network_configs_onc
,
82 base::DictionaryValue
* global_network_config
) {
84 chromeos::onc::ExpandStringPlaceholdersInNetworksForUser(user_
,
86 network_config_handler_
->SetPolicy(onc_source_
,
87 user_
->username_hash(),
89 *global_network_config
);
92 void UserNetworkConfigurationUpdater::NotifyTrustAnchorsChanged() {
93 FOR_EACH_OBSERVER(WebTrustedCertsObserver
,
95 OnTrustAnchorsChanged(web_trust_certs_
));