OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/network_configuration_updater.h" | 5 #include "chrome/browser/chromeos/policy/network_configuration_updater_impl_cros
.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
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/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "chrome/browser/chromeos/cros/network_library.h" | 14 #include "chrome/browser/chromeos/cros/network_library.h" |
15 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
(...skipping 30 matching lines...) Expand all Loading... |
46 } | 46 } |
47 | 47 |
48 private: | 48 private: |
49 net::CertificateList trust_anchors_; | 49 net::CertificateList trust_anchors_; |
50 | 50 |
51 DISALLOW_COPY_AND_ASSIGN(CrosTrustAnchorProvider); | 51 DISALLOW_COPY_AND_ASSIGN(CrosTrustAnchorProvider); |
52 }; | 52 }; |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 NetworkConfigurationUpdater::NetworkConfigurationUpdater( | 56 NetworkConfigurationUpdaterImplCros::NetworkConfigurationUpdaterImplCros( |
57 PolicyService* policy_service, | 57 PolicyService* policy_service, |
58 chromeos::NetworkLibrary* network_library) | 58 chromeos::NetworkLibrary* network_library) |
59 : policy_change_registrar_( | 59 : policy_change_registrar_( |
60 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), | 60 policy_service, PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())), |
61 network_library_(network_library), | 61 network_library_(network_library), |
62 user_policy_initialized_(false), | 62 user_policy_initialized_(false), |
63 allow_trusted_certificates_from_policy_(false), | 63 allow_trusted_certificates_from_policy_(false), |
64 policy_service_(policy_service), | 64 policy_service_(policy_service), |
65 cert_trust_provider_(new CrosTrustAnchorProvider()) { | 65 cert_trust_provider_(new CrosTrustAnchorProvider()) { |
66 DCHECK(network_library_); | 66 DCHECK(network_library_); |
67 policy_change_registrar_.Observe( | 67 policy_change_registrar_.Observe( |
68 key::kDeviceOpenNetworkConfiguration, | 68 key::kDeviceOpenNetworkConfiguration, |
69 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, | 69 base::Bind(&NetworkConfigurationUpdaterImplCros::OnPolicyChanged, |
70 base::Unretained(this), | 70 base::Unretained(this), |
71 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); | 71 chromeos::onc::ONC_SOURCE_DEVICE_POLICY)); |
72 policy_change_registrar_.Observe( | 72 policy_change_registrar_.Observe( |
73 key::kOpenNetworkConfiguration, | 73 key::kOpenNetworkConfiguration, |
74 base::Bind(&NetworkConfigurationUpdater::OnPolicyChanged, | 74 base::Bind(&NetworkConfigurationUpdaterImplCros::OnPolicyChanged, |
75 base::Unretained(this), | 75 base::Unretained(this), |
76 chromeos::onc::ONC_SOURCE_USER_POLICY)); | 76 chromeos::onc::ONC_SOURCE_USER_POLICY)); |
77 | 77 |
78 network_library_->AddNetworkProfileObserver(this); | 78 network_library_->AddNetworkProfileObserver(this); |
79 | 79 |
80 // Apply the current policies immediately. | 80 // Apply the current policies immediately. |
81 ApplyNetworkConfigurations(); | 81 ApplyNetworkConfigurations(); |
82 } | 82 } |
83 | 83 |
84 NetworkConfigurationUpdater::~NetworkConfigurationUpdater() { | 84 NetworkConfigurationUpdaterImplCros::~NetworkConfigurationUpdaterImplCros() { |
85 network_library_->RemoveNetworkProfileObserver(this); | 85 network_library_->RemoveNetworkProfileObserver(this); |
86 bool posted = BrowserThread::DeleteSoon( | 86 bool posted = BrowserThread::DeleteSoon( |
87 BrowserThread::IO, FROM_HERE, cert_trust_provider_); | 87 BrowserThread::IO, FROM_HERE, cert_trust_provider_); |
88 if (!posted) | 88 if (!posted) |
89 delete cert_trust_provider_; | 89 delete cert_trust_provider_; |
90 } | 90 } |
91 | 91 |
92 void NetworkConfigurationUpdater::OnProfileListChanged() { | 92 void NetworkConfigurationUpdaterImplCros::OnProfileListChanged() { |
93 VLOG(1) << "Network profile list changed, applying policies."; | 93 VLOG(1) << "Network profile list changed, applying policies."; |
94 ApplyNetworkConfigurations(); | 94 ApplyNetworkConfigurations(); |
95 } | 95 } |
96 | 96 |
97 void NetworkConfigurationUpdater::OnUserPolicyInitialized() { | 97 void NetworkConfigurationUpdaterImplCros::OnUserPolicyInitialized() { |
98 VLOG(1) << "User policy initialized, applying policies."; | 98 VLOG(1) << "User policy initialized, applying policies."; |
99 user_policy_initialized_ = true; | 99 user_policy_initialized_ = true; |
100 ApplyNetworkConfigurations(); | 100 ApplyNetworkConfigurations(); |
101 } | 101 } |
102 | 102 |
| 103 void NetworkConfigurationUpdaterImplCros:: |
| 104 set_allow_trusted_certificates_from_policy(bool allow) { |
| 105 allow_trusted_certificates_from_policy_ = allow; |
| 106 } |
| 107 |
103 net::CertTrustAnchorProvider* | 108 net::CertTrustAnchorProvider* |
104 NetworkConfigurationUpdater::GetCertTrustAnchorProvider() { | 109 NetworkConfigurationUpdaterImplCros::GetCertTrustAnchorProvider() { |
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
106 return cert_trust_provider_; | 111 return cert_trust_provider_; |
107 } | 112 } |
108 | 113 |
109 void NetworkConfigurationUpdater::OnPolicyChanged( | 114 void NetworkConfigurationUpdaterImplCros::OnPolicyChanged( |
110 chromeos::onc::ONCSource onc_source, | 115 chromeos::onc::ONCSource onc_source, |
111 const base::Value* previous, | 116 const base::Value* previous, |
112 const base::Value* current) { | 117 const base::Value* current) { |
113 VLOG(1) << "Policy for ONC source " | 118 VLOG(1) << "Policy for ONC source " |
114 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; | 119 << chromeos::onc::GetSourceAsString(onc_source) << " changed."; |
115 ApplyNetworkConfigurations(); | 120 ApplyNetworkConfigurations(); |
116 } | 121 } |
117 | 122 |
118 void NetworkConfigurationUpdater::ApplyNetworkConfigurations() { | 123 void NetworkConfigurationUpdaterImplCros::ApplyNetworkConfigurations() { |
119 ApplyNetworkConfiguration(key::kDeviceOpenNetworkConfiguration, | 124 ApplyNetworkConfiguration(key::kDeviceOpenNetworkConfiguration, |
120 chromeos::onc::ONC_SOURCE_DEVICE_POLICY); | 125 chromeos::onc::ONC_SOURCE_DEVICE_POLICY); |
121 if (user_policy_initialized_) { | 126 if (user_policy_initialized_) { |
122 ApplyNetworkConfiguration(key::kOpenNetworkConfiguration, | 127 ApplyNetworkConfiguration(key::kOpenNetworkConfiguration, |
123 chromeos::onc::ONC_SOURCE_USER_POLICY); | 128 chromeos::onc::ONC_SOURCE_USER_POLICY); |
124 } | 129 } |
125 } | 130 } |
126 | 131 |
127 void NetworkConfigurationUpdater::ApplyNetworkConfiguration( | 132 void NetworkConfigurationUpdaterImplCros::ApplyNetworkConfiguration( |
128 const std::string& policy_key, | 133 const std::string& policy_key, |
129 chromeos::onc::ONCSource onc_source) { | 134 chromeos::onc::ONCSource onc_source) { |
130 VLOG(1) << "Apply policy for ONC source " | 135 VLOG(1) << "Apply policy for ONC source " |
131 << chromeos::onc::GetSourceAsString(onc_source); | 136 << chromeos::onc::GetSourceAsString(onc_source); |
132 const PolicyMap& policies = policy_service_->GetPolicies( | 137 const PolicyMap& policies = policy_service_->GetPolicies( |
133 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 138 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
134 const base::Value* policy_value = policies.GetValue(policy_key); | 139 const base::Value* policy_value = policies.GetValue(policy_key); |
135 | 140 |
136 std::string new_network_config; | 141 std::string new_network_config; |
137 if (policy_value != NULL) { | 142 if (policy_value != NULL) { |
(...skipping 24 matching lines...) Expand all Loading... |
162 BrowserThread::PostTask( | 167 BrowserThread::PostTask( |
163 BrowserThread::IO, FROM_HERE, | 168 BrowserThread::IO, FROM_HERE, |
164 base::Bind(&CrosTrustAnchorProvider::SetTrustAnchors, | 169 base::Bind(&CrosTrustAnchorProvider::SetTrustAnchors, |
165 base::Unretained(static_cast<CrosTrustAnchorProvider*>( | 170 base::Unretained(static_cast<CrosTrustAnchorProvider*>( |
166 cert_trust_provider_)), | 171 cert_trust_provider_)), |
167 base::Passed(&web_trust_certs))); | 172 base::Passed(&web_trust_certs))); |
168 } | 173 } |
169 } | 174 } |
170 | 175 |
171 } // namespace policy | 176 } // namespace policy |
OLD | NEW |