| 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" | |
| 9 #include "base/values.h" | 8 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/policy/device_local_account.h" | 9 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 11 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" | 10 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" |
| 12 #include "chromeos/dbus/power_policy_controller.h" | 11 #include "chromeos/dbus/power_policy_controller.h" |
| 13 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 12 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
| 14 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 13 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
| 15 #include "components/policy/core/common/policy_bundle.h" | 14 #include "components/policy/core/common/policy_bundle.h" |
| 16 #include "components/policy/core/common/policy_map.h" | 15 #include "components/policy/core/common/policy_map.h" |
| 17 #include "components/policy/core/common/policy_namespace.h" | 16 #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" | |
| 21 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
| 22 | 18 |
| 23 namespace policy { | 19 namespace policy { |
| 24 | 20 |
| 25 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( | 21 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( |
| 26 const std::string& user_id, | 22 const std::string& user_id, |
| 27 DeviceLocalAccountPolicyService* service, | 23 DeviceLocalAccountPolicyService* service, |
| 28 scoped_ptr<PolicyMap> chrome_policy_overrides) | 24 scoped_ptr<PolicyMap> chrome_policy_overrides) |
| 29 : user_id_(user_id), | 25 : user_id_(user_id), |
| 30 service_(service), | 26 service_(service), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 NULL); | 87 NULL); |
| 92 } | 88 } |
| 93 | 89 |
| 94 scoped_ptr<DeviceLocalAccountPolicyProvider> provider( | 90 scoped_ptr<DeviceLocalAccountPolicyProvider> provider( |
| 95 new DeviceLocalAccountPolicyProvider(user_id, | 91 new DeviceLocalAccountPolicyProvider(user_id, |
| 96 device_local_account_policy_service, | 92 device_local_account_policy_service, |
| 97 chrome_policy_overrides.Pass())); | 93 chrome_policy_overrides.Pass())); |
| 98 return provider.Pass(); | 94 return provider.Pass(); |
| 99 } | 95 } |
| 100 | 96 |
| 101 void DeviceLocalAccountPolicyProvider::Init(SchemaRegistry* schema_registry) { | |
| 102 ConfigurationPolicyProvider::Init(schema_registry); | |
| 103 MaybeCreateComponentPolicyService(); | |
| 104 } | |
| 105 | |
| 106 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete( | 97 bool DeviceLocalAccountPolicyProvider::IsInitializationComplete( |
| 107 PolicyDomain domain) const { | 98 PolicyDomain domain) const { |
| 108 if (domain == POLICY_DOMAIN_CHROME) | 99 if (domain == POLICY_DOMAIN_CHROME) |
| 109 return store_initialized_; | 100 return store_initialized_; |
| 110 if (ComponentCloudPolicyService::SupportsDomain(domain) && | |
| 111 component_policy_service_) { | |
| 112 return component_policy_service_->is_initialized(); | |
| 113 } | |
| 114 return true; | 101 return true; |
| 115 } | 102 } |
| 116 | 103 |
| 117 void DeviceLocalAccountPolicyProvider::RefreshPolicies() { | 104 void DeviceLocalAccountPolicyProvider::RefreshPolicies() { |
| 118 DeviceLocalAccountPolicyBroker* broker = GetBroker(); | 105 DeviceLocalAccountPolicyBroker* broker = GetBroker(); |
| 119 if (broker && broker->core()->service()) { | 106 if (broker && broker->core()->service()) { |
| 120 waiting_for_policy_refresh_ = true; | 107 waiting_for_policy_refresh_ = true; |
| 121 broker->core()->service()->RefreshPolicy( | 108 broker->core()->service()->RefreshPolicy( |
| 122 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, | 109 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, |
| 123 weak_factory_.GetWeakPtr())); | 110 weak_factory_.GetWeakPtr())); |
| 124 } else { | 111 } else { |
| 125 UpdateFromBroker(); | 112 UpdateFromBroker(); |
| 126 } | 113 } |
| 127 } | 114 } |
| 128 | 115 |
| 129 void DeviceLocalAccountPolicyProvider::Shutdown() { | |
| 130 component_policy_service_.reset(); | |
| 131 ConfigurationPolicyProvider::Shutdown(); | |
| 132 } | |
| 133 | |
| 134 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( | 116 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( |
| 135 const std::string& user_id) { | 117 const std::string& user_id) { |
| 136 if (user_id == user_id_) { | 118 if (user_id == user_id_) |
| 137 MaybeCreateComponentPolicyService(); | |
| 138 UpdateFromBroker(); | 119 UpdateFromBroker(); |
| 139 } | |
| 140 } | 120 } |
| 141 | 121 |
| 142 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { | 122 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { |
| 143 MaybeCreateComponentPolicyService(); | |
| 144 UpdateFromBroker(); | |
| 145 } | |
| 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, | |
| 151 // so destroy it if the broker is going away. | |
| 152 component_policy_service_.reset(); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 void DeviceLocalAccountPolicyProvider::OnComponentCloudPolicyUpdated() { | |
| 157 UpdateFromBroker(); | 123 UpdateFromBroker(); |
| 158 } | 124 } |
| 159 | 125 |
| 160 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() { | 126 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() { |
| 161 return service_->GetBrokerForUser(user_id_); | 127 return service_->GetBrokerForUser(user_id_); |
| 162 } | 128 } |
| 163 | 129 |
| 164 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { | 130 void DeviceLocalAccountPolicyProvider::ReportPolicyRefresh(bool success) { |
| 165 waiting_for_policy_refresh_ = false; | 131 waiting_for_policy_refresh_ = false; |
| 166 UpdateFromBroker(); | 132 UpdateFromBroker(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 180 // Wait for the refresh to finish. | 146 // Wait for the refresh to finish. |
| 181 return; | 147 return; |
| 182 } | 148 } |
| 183 } else { | 149 } else { |
| 184 // Keep existing policy, but do send an update. | 150 // Keep existing policy, but do send an update. |
| 185 waiting_for_policy_refresh_ = false; | 151 waiting_for_policy_refresh_ = false; |
| 186 weak_factory_.InvalidateWeakPtrs(); | 152 weak_factory_.InvalidateWeakPtrs(); |
| 187 bundle->CopyFrom(policies()); | 153 bundle->CopyFrom(policies()); |
| 188 } | 154 } |
| 189 | 155 |
| 190 if (component_policy_service_) | |
| 191 bundle->MergeFrom(component_policy_service_->policy()); | |
| 192 | |
| 193 // Apply overrides. | 156 // Apply overrides. |
| 194 if (chrome_policy_overrides_) { | 157 if (chrome_policy_overrides_) { |
| 195 PolicyMap& chrome_policy = | 158 PolicyMap& chrome_policy = |
| 196 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 159 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 197 for (PolicyMap::const_iterator it(chrome_policy_overrides_->begin()); | 160 for (PolicyMap::const_iterator it(chrome_policy_overrides_->begin()); |
| 198 it != chrome_policy_overrides_->end(); | 161 it != chrome_policy_overrides_->end(); |
| 199 ++it) { | 162 ++it) { |
| 200 const PolicyMap::Entry& entry = it->second; | 163 const PolicyMap::Entry& entry = it->second; |
| 201 chrome_policy.Set( | 164 chrome_policy.Set( |
| 202 it->first, entry.level, entry.scope, entry.value->DeepCopy(), NULL); | 165 it->first, entry.level, entry.scope, entry.value->DeepCopy(), NULL); |
| 203 } | 166 } |
| 204 } | 167 } |
| 205 | 168 |
| 206 UpdatePolicy(bundle.Pass()); | 169 UpdatePolicy(bundle.Pass()); |
| 207 } | 170 } |
| 208 | 171 |
| 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 | |
| 240 } // namespace policy | 172 } // namespace policy |
| OLD | NEW |