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/device_local_account_policy_provider.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | |
8 #include "base/values.h" | 9 #include "base/values.h" |
9 #include "chrome/browser/chromeos/policy/device_local_account.h" | 10 #include "chrome/browser/chromeos/policy/device_local_account.h" |
10 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana ger.h" | 11 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana ger.h" |
11 #include "chromeos/dbus/power_policy_controller.h" | 12 #include "chromeos/dbus/power_policy_controller.h" |
12 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 13 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
13 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 14 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
14 #include "components/policy/core/common/policy_bundle.h" | 15 #include "components/policy/core/common/policy_bundle.h" |
15 #include "components/policy/core/common/policy_map.h" | 16 #include "components/policy/core/common/policy_map.h" |
16 #include "components/policy/core/common/policy_namespace.h" | 17 #include "components/policy/core/common/policy_namespace.h" |
18 #include "components/policy/core/common/policy_switches.h" | |
19 #include "content/public/browser/browser_thread.h" | |
20 #include "net/url_request/url_request_context_getter.h" | |
17 #include "policy/policy_constants.h" | 21 #include "policy/policy_constants.h" |
18 | 22 |
19 namespace policy { | 23 namespace policy { |
20 | 24 |
21 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( | 25 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( |
22 const std::string& user_id, | 26 const std::string& user_id, |
23 DeviceLocalAccountPolicyService* service, | 27 DeviceLocalAccountPolicyService* service, |
24 scoped_ptr<PolicyMap> chrome_policy_overrides) | 28 scoped_ptr<PolicyMap> chrome_policy_overrides) |
25 : user_id_(user_id), | 29 : user_id_(user_id), |
26 service_(service), | 30 service_(service), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 NULL); | 91 NULL); |
88 } | 92 } |
89 | 93 |
90 scoped_ptr<DeviceLocalAccountPolicyProvider> provider( | 94 scoped_ptr<DeviceLocalAccountPolicyProvider> provider( |
91 new DeviceLocalAccountPolicyProvider(user_id, | 95 new DeviceLocalAccountPolicyProvider(user_id, |
92 device_local_account_policy_service, | 96 device_local_account_policy_service, |
93 chrome_policy_overrides.Pass())); | 97 chrome_policy_overrides.Pass())); |
94 return provider.Pass(); | 98 return provider.Pass(); |
95 } | 99 } |
96 | 100 |
101 void DeviceLocalAccountPolicyProvider::Init(SchemaRegistry* schema_registry) { | |
102 ConfigurationPolicyProvider::Init(schema_registry); | |
103 MaybeCreateComponentPolicyService(); | |
104 } | |
105 | |
97 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete( | 106 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete( |
98 PolicyDomain domain) const { | 107 PolicyDomain domain) const { |
99 if (domain == POLICY_DOMAIN_CHROME) | 108 if (domain == POLICY_DOMAIN_CHROME) |
100 return store_initialized_; | 109 return store_initialized_; |
110 if (ComponentCloudPolicyService::SupportsDomain(domain) && | |
111 component_policy_service_) { | |
112 return component_policy_service_->is_initialized(); | |
bartfab (slow)
2014/06/20 09:17:25
Is it correct for this method to return |true| if
Joao da Silva
2014/06/20 11:48:45
Good observation. In the next CL the component_pol
| |
113 } | |
101 return true; | 114 return true; |
102 } | 115 } |
103 | 116 |
104 void DeviceLocalAccountPolicyProvider::RefreshPolicies() { | 117 void DeviceLocalAccountPolicyProvider::RefreshPolicies() { |
105 DeviceLocalAccountPolicyBroker* broker = GetBroker(); | 118 DeviceLocalAccountPolicyBroker* broker = GetBroker(); |
106 if (broker && broker->core()->service()) { | 119 if (broker && broker->core()->service()) { |
107 waiting_for_policy_refresh_ = true; | 120 waiting_for_policy_refresh_ = true; |
108 broker->core()->service()->RefreshPolicy( | 121 broker->core()->service()->RefreshPolicy( |
109 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, | 122 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, |
110 weak_factory_.GetWeakPtr())); | 123 weak_factory_.GetWeakPtr())); |
111 } else { | 124 } else { |
112 UpdateFromBroker(); | 125 UpdateFromBroker(); |
113 } | 126 } |
114 } | 127 } |
115 | 128 |
129 void DeviceLocalAccountPolicyProvider::Shutdown() { | |
130 component_policy_service_.reset(); | |
131 ConfigurationPolicyProvider::Shutdown(); | |
132 } | |
133 | |
116 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( | 134 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( |
117 const std::string& user_id) { | 135 const std::string& user_id) { |
118 if (user_id == user_id_) | 136 if (user_id == user_id_) { |
137 MaybeCreateComponentPolicyService(); | |
119 UpdateFromBroker(); | 138 UpdateFromBroker(); |
139 } | |
120 } | 140 } |
121 | 141 |
122 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { | 142 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { |
143 MaybeCreateComponentPolicyService(); | |
123 UpdateFromBroker(); | 144 UpdateFromBroker(); |
124 } | 145 } |
125 | 146 |
147 void DeviceLocalAccountPolicyProvider::OnBrokerShutdown( | |
148 DeviceLocalAccountPolicyBroker* broker) { | |
149 if (broker->user_id() == user_id_) { | |
150 // The |component_policy_service_| relies on the broker's CloudPolicyCore, | |
bartfab (slow)
2014/06/20 09:17:24
Nit: s/broker/|broker|/
Joao da Silva
2014/06/20 11:48:45
Obsolete in the next CL.
| |
151 // so destroy it if the broker is going away. | |
bartfab (slow)
2014/06/20 09:17:25
Nit: s/broker/|broker|/
Joao da Silva
2014/06/20 11:48:45
Same
| |
152 component_policy_service_.reset(); | |
153 } | |
154 } | |
155 | |
156 void DeviceLocalAccountPolicyProvider::OnComponentCloudPolicyUpdated() { | |
157 UpdateFromBroker(); | |
158 } | |
159 | |
126 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() { | 160 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() { |
127 return service_->GetBrokerForUser(user_id_); | 161 return service_->GetBrokerForUser(user_id_); |
128 } | 162 } |
129 | 163 |
130 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { | 164 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { |
131 waiting_for_policy_refresh_ = false; | 165 waiting_for_policy_refresh_ = false; |
132 UpdateFromBroker(); | 166 UpdateFromBroker(); |
133 } | 167 } |
134 | 168 |
135 void DeviceLocalAccountPolicyProvider::UpdateFromBroker() { | 169 void DeviceLocalAccountPolicyProvider::UpdateFromBroker() { |
(...skipping 10 matching lines...) Expand all Loading... | |
146 // Wait for the refresh to finish. | 180 // Wait for the refresh to finish. |
147 return; | 181 return; |
148 } | 182 } |
149 } else { | 183 } else { |
150 // Keep existing policy, but do send an update. | 184 // Keep existing policy, but do send an update. |
151 waiting_for_policy_refresh_ = false; | 185 waiting_for_policy_refresh_ = false; |
152 weak_factory_.InvalidateWeakPtrs(); | 186 weak_factory_.InvalidateWeakPtrs(); |
153 bundle->CopyFrom(policies()); | 187 bundle->CopyFrom(policies()); |
154 } | 188 } |
155 | 189 |
190 if (component_policy_service_) | |
191 bundle->MergeFrom(component_policy_service_->policy()); | |
192 | |
156 // Apply overrides. | 193 // Apply overrides. |
157 if (chrome_policy_overrides_) { | 194 if (chrome_policy_overrides_) { |
158 PolicyMap& chrome_policy = | 195 PolicyMap& chrome_policy = |
159 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 196 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
160 for (PolicyMap::const_iterator it(chrome_policy_overrides_->begin()); | 197 for (PolicyMap::const_iterator it(chrome_policy_overrides_->begin()); |
161 it != chrome_policy_overrides_->end(); | 198 it != chrome_policy_overrides_->end(); |
162 ++it) { | 199 ++it) { |
163 const PolicyMap::Entry& entry = it->second; | 200 const PolicyMap::Entry& entry = it->second; |
164 chrome_policy.Set( | 201 chrome_policy.Set( |
165 it->first, entry.level, entry.scope, entry.value->DeepCopy(), NULL); | 202 it->first, entry.level, entry.scope, entry.value->DeepCopy(), NULL); |
166 } | 203 } |
167 } | 204 } |
168 | 205 |
169 UpdatePolicy(bundle.Pass()); | 206 UpdatePolicy(bundle.Pass()); |
170 } | 207 } |
171 | 208 |
209 void DeviceLocalAccountPolicyProvider::MaybeCreateComponentPolicyService() { | |
210 if (component_policy_service_) | |
211 return; // Already started. | |
212 | |
213 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
214 switches::kDisableComponentCloudPolicy)) { | |
215 // Disabled via the command line. | |
216 return; | |
217 } | |
218 | |
219 DeviceLocalAccountPolicyBroker* broker = GetBroker(); | |
220 if (!broker || !schema_registry()) | |
221 return; // Missing broker or not initialized yet. | |
222 | |
223 scoped_ptr<ResourceCache> resource_cache( | |
224 new ResourceCache(broker->GetComponentPolicyCachePath(), | |
225 content::BrowserThread::GetMessageLoopProxyForThread( | |
226 content::BrowserThread::FILE))); | |
227 | |
228 component_policy_service_.reset(new ComponentCloudPolicyService( | |
229 this, | |
230 schema_registry(), | |
231 broker->core(), | |
232 resource_cache.Pass(), | |
233 service_->request_context(), | |
234 content::BrowserThread::GetMessageLoopProxyForThread( | |
235 content::BrowserThread::FILE), | |
236 content::BrowserThread::GetMessageLoopProxyForThread( | |
237 content::BrowserThread::IO))); | |
238 } | |
239 | |
172 } // namespace policy | 240 } // namespace policy |
OLD | NEW |