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_service.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
6 | 6 |
| 7 #include <utility> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 scoped_refptr<net::URLRequestContextGetter> request_context = | 68 scoped_refptr<net::URLRequestContextGetter> request_context = |
68 new SystemPolicyRequestContext( | 69 new SystemPolicyRequestContext( |
69 system_request_context, GetUserAgent()); | 70 system_request_context, GetUserAgent()); |
70 | 71 |
71 scoped_ptr<CloudPolicyClient> client( | 72 scoped_ptr<CloudPolicyClient> client( |
72 new CloudPolicyClient(std::string(), std::string(), | 73 new CloudPolicyClient(std::string(), std::string(), |
73 kPolicyVerificationKeyHash, | 74 kPolicyVerificationKeyHash, |
74 device_management_service, request_context)); | 75 device_management_service, request_context)); |
75 client->SetupRegistration(policy_data->request_token(), | 76 client->SetupRegistration(policy_data->request_token(), |
76 policy_data->device_id()); | 77 policy_data->device_id()); |
77 return client.Pass(); | 78 return client; |
78 } | 79 } |
79 | 80 |
80 // Get the subdirectory of the force-installed extension cache and the component | 81 // Get the subdirectory of the force-installed extension cache and the component |
81 // policy cache used for |account_id|. | 82 // policy cache used for |account_id|. |
82 std::string GetCacheSubdirectoryForAccountID(const std::string& account_id) { | 83 std::string GetCacheSubdirectoryForAccountID(const std::string& account_id) { |
83 return base::HexEncode(account_id.c_str(), account_id.size()); | 84 return base::HexEncode(account_id.c_str(), account_id.size()); |
84 } | 85 } |
85 | 86 |
86 // Cleans up the cache directory by removing subdirectories that are not found | 87 // Cleans up the cache directory by removing subdirectories that are not found |
87 // in |subdirectories_to_keep|. Only caches whose cache directory is found in | 88 // in |subdirectories_to_keep|. Only caches whose cache directory is found in |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 const base::FilePath& component_policy_cache_path, | 121 const base::FilePath& component_policy_cache_path, |
121 scoped_ptr<DeviceLocalAccountPolicyStore> store, | 122 scoped_ptr<DeviceLocalAccountPolicyStore> store, |
122 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, | 123 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, |
123 const base::Closure& policy_update_callback, | 124 const base::Closure& policy_update_callback, |
124 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 125 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
125 AffiliatedInvalidationServiceProvider* invalidation_service_provider) | 126 AffiliatedInvalidationServiceProvider* invalidation_service_provider) |
126 : invalidation_service_provider_(invalidation_service_provider), | 127 : invalidation_service_provider_(invalidation_service_provider), |
127 account_id_(account.account_id), | 128 account_id_(account.account_id), |
128 user_id_(account.user_id), | 129 user_id_(account.user_id), |
129 component_policy_cache_path_(component_policy_cache_path), | 130 component_policy_cache_path_(component_policy_cache_path), |
130 store_(store.Pass()), | 131 store_(std::move(store)), |
131 extension_tracker_(account, store_.get(), &schema_registry_), | 132 extension_tracker_(account, store_.get(), &schema_registry_), |
132 external_data_manager_(external_data_manager), | 133 external_data_manager_(external_data_manager), |
133 core_(dm_protocol::kChromePublicAccountPolicyType, | 134 core_(dm_protocol::kChromePublicAccountPolicyType, |
134 store_->account_id(), | 135 store_->account_id(), |
135 store_.get(), | 136 store_.get(), |
136 task_runner), | 137 task_runner), |
137 policy_update_callback_(policy_update_callback) { | 138 policy_update_callback_(policy_update_callback) { |
138 base::FilePath cache_root_dir; | 139 base::FilePath cache_root_dir; |
139 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, | 140 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
140 &cache_root_dir)); | 141 &cache_root_dir)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (core_.client()) | 175 if (core_.client()) |
175 return; | 176 return; |
176 | 177 |
177 scoped_ptr<CloudPolicyClient> client(CreateClient(device_settings_service, | 178 scoped_ptr<CloudPolicyClient> client(CreateClient(device_settings_service, |
178 device_management_service, | 179 device_management_service, |
179 request_context)); | 180 request_context)); |
180 if (!client) | 181 if (!client) |
181 return; | 182 return; |
182 | 183 |
183 CreateComponentCloudPolicyService(request_context, client.get()); | 184 CreateComponentCloudPolicyService(request_context, client.get()); |
184 core_.Connect(client.Pass()); | 185 core_.Connect(std::move(client)); |
185 external_data_manager_->Connect(request_context); | 186 external_data_manager_->Connect(request_context); |
186 core_.StartRefreshScheduler(); | 187 core_.StartRefreshScheduler(); |
187 UpdateRefreshDelay(); | 188 UpdateRefreshDelay(); |
188 invalidator_.reset(new AffiliatedCloudPolicyInvalidator( | 189 invalidator_.reset(new AffiliatedCloudPolicyInvalidator( |
189 em::DeviceRegisterRequest::DEVICE, | 190 em::DeviceRegisterRequest::DEVICE, |
190 &core_, | 191 &core_, |
191 invalidation_service_provider_)); | 192 invalidation_service_provider_)); |
192 } | 193 } |
193 | 194 |
194 void DeviceLocalAccountPolicyBroker::UpdateRefreshDelay() { | 195 void DeviceLocalAccountPolicyBroker::UpdateRefreshDelay() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // Disabled via the command line. | 232 // Disabled via the command line. |
232 return; | 233 return; |
233 } | 234 } |
234 | 235 |
235 scoped_ptr<ResourceCache> resource_cache( | 236 scoped_ptr<ResourceCache> resource_cache( |
236 new ResourceCache(component_policy_cache_path_, | 237 new ResourceCache(component_policy_cache_path_, |
237 content::BrowserThread::GetMessageLoopProxyForThread( | 238 content::BrowserThread::GetMessageLoopProxyForThread( |
238 content::BrowserThread::FILE))); | 239 content::BrowserThread::FILE))); |
239 | 240 |
240 component_policy_service_.reset(new ComponentCloudPolicyService( | 241 component_policy_service_.reset(new ComponentCloudPolicyService( |
241 this, | 242 this, &schema_registry_, core(), client, std::move(resource_cache), |
242 &schema_registry_, | 243 request_context, content::BrowserThread::GetMessageLoopProxyForThread( |
243 core(), | 244 content::BrowserThread::FILE), |
244 client, | |
245 resource_cache.Pass(), | |
246 request_context, | |
247 content::BrowserThread::GetMessageLoopProxyForThread( | |
248 content::BrowserThread::FILE), | |
249 content::BrowserThread::GetMessageLoopProxyForThread( | 245 content::BrowserThread::GetMessageLoopProxyForThread( |
250 content::BrowserThread::IO))); | 246 content::BrowserThread::IO))); |
251 } | 247 } |
252 | 248 |
253 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService( | 249 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService( |
254 chromeos::SessionManagerClient* session_manager_client, | 250 chromeos::SessionManagerClient* session_manager_client, |
255 chromeos::DeviceSettingsService* device_settings_service, | 251 chromeos::DeviceSettingsService* device_settings_service, |
256 chromeos::CrosSettings* cros_settings, | 252 chromeos::CrosSettings* cros_settings, |
257 AffiliatedInvalidationServiceProvider* invalidation_service_provider, | 253 AffiliatedInvalidationServiceProvider* invalidation_service_provider, |
258 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, | 254 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 scoped_ptr<DeviceLocalAccountPolicyStore> store( | 456 scoped_ptr<DeviceLocalAccountPolicyStore> store( |
461 new DeviceLocalAccountPolicyStore(it->account_id, | 457 new DeviceLocalAccountPolicyStore(it->account_id, |
462 session_manager_client_, | 458 session_manager_client_, |
463 device_settings_service_, | 459 device_settings_service_, |
464 store_background_task_runner_)); | 460 store_background_task_runner_)); |
465 scoped_refptr<DeviceLocalAccountExternalDataManager> | 461 scoped_refptr<DeviceLocalAccountExternalDataManager> |
466 external_data_manager = | 462 external_data_manager = |
467 external_data_service_->GetExternalDataManager(it->account_id, | 463 external_data_service_->GetExternalDataManager(it->account_id, |
468 store.get()); | 464 store.get()); |
469 broker.reset(new DeviceLocalAccountPolicyBroker( | 465 broker.reset(new DeviceLocalAccountPolicyBroker( |
470 *it, | 466 *it, component_policy_cache_root_.Append( |
471 component_policy_cache_root_.Append( | 467 GetCacheSubdirectoryForAccountID(it->account_id)), |
472 GetCacheSubdirectoryForAccountID(it->account_id)), | 468 std::move(store), external_data_manager, |
473 store.Pass(), | |
474 external_data_manager, | |
475 base::Bind(&DeviceLocalAccountPolicyService::NotifyPolicyUpdated, | 469 base::Bind(&DeviceLocalAccountPolicyService::NotifyPolicyUpdated, |
476 base::Unretained(this), | 470 base::Unretained(this), it->user_id), |
477 it->user_id), | 471 base::ThreadTaskRunnerHandle::Get(), invalidation_service_provider_)); |
478 base::ThreadTaskRunnerHandle::Get(), | |
479 invalidation_service_provider_)); | |
480 } | 472 } |
481 | 473 |
482 // Fire up the cloud connection for fetching policy for the account from | 474 // Fire up the cloud connection for fetching policy for the account from |
483 // the cloud if this is an enterprise-managed device. | 475 // the cloud if this is an enterprise-managed device. |
484 broker->ConnectIfPossible(device_settings_service_, | 476 broker->ConnectIfPossible(device_settings_service_, |
485 device_management_service_, | 477 device_management_service_, |
486 request_context_); | 478 request_context_); |
487 | 479 |
488 policy_brokers_[it->user_id] = broker.release(); | 480 policy_brokers_[it->user_id] = broker.release(); |
489 if (!broker_initialized) { | 481 if (!broker_initialized) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 566 } |
575 return nullptr; | 567 return nullptr; |
576 } | 568 } |
577 | 569 |
578 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated( | 570 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated( |
579 const std::string& user_id) { | 571 const std::string& user_id) { |
580 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id)); | 572 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id)); |
581 } | 573 } |
582 | 574 |
583 } // namespace policy | 575 } // namespace policy |
OLD | NEW |