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 <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "url/gurl.h" | 47 #include "url/gurl.h" |
48 | 48 |
49 namespace em = enterprise_management; | 49 namespace em = enterprise_management; |
50 | 50 |
51 namespace policy { | 51 namespace policy { |
52 | 52 |
53 namespace { | 53 namespace { |
54 | 54 |
55 // Creates and initializes a cloud policy client. Returns nullptr if the device | 55 // Creates and initializes a cloud policy client. Returns nullptr if the device |
56 // is not enterprise-enrolled. | 56 // is not enterprise-enrolled. |
57 scoped_ptr<CloudPolicyClient> CreateClient( | 57 std::unique_ptr<CloudPolicyClient> CreateClient( |
58 chromeos::DeviceSettingsService* device_settings_service, | 58 chromeos::DeviceSettingsService* device_settings_service, |
59 DeviceManagementService* device_management_service, | 59 DeviceManagementService* device_management_service, |
60 scoped_refptr<net::URLRequestContextGetter> system_request_context) { | 60 scoped_refptr<net::URLRequestContextGetter> system_request_context) { |
61 const em::PolicyData* policy_data = device_settings_service->policy_data(); | 61 const em::PolicyData* policy_data = device_settings_service->policy_data(); |
62 if (!policy_data || | 62 if (!policy_data || |
63 GetManagementMode(*policy_data) != MANAGEMENT_MODE_ENTERPRISE_MANAGED || | 63 GetManagementMode(*policy_data) != MANAGEMENT_MODE_ENTERPRISE_MANAGED || |
64 !device_management_service) { | 64 !device_management_service) { |
65 return scoped_ptr<CloudPolicyClient>(); | 65 return std::unique_ptr<CloudPolicyClient>(); |
66 } | 66 } |
67 | 67 |
68 scoped_refptr<net::URLRequestContextGetter> request_context = | 68 scoped_refptr<net::URLRequestContextGetter> request_context = |
69 new SystemPolicyRequestContext( | 69 new SystemPolicyRequestContext( |
70 system_request_context, GetUserAgent()); | 70 system_request_context, GetUserAgent()); |
71 | 71 |
72 scoped_ptr<CloudPolicyClient> client( | 72 std::unique_ptr<CloudPolicyClient> client(new CloudPolicyClient( |
73 new CloudPolicyClient(std::string(), std::string(), | 73 std::string(), std::string(), kPolicyVerificationKeyHash, |
74 kPolicyVerificationKeyHash, | 74 device_management_service, request_context)); |
75 device_management_service, request_context)); | |
76 client->SetupRegistration(policy_data->request_token(), | 75 client->SetupRegistration(policy_data->request_token(), |
77 policy_data->device_id()); | 76 policy_data->device_id()); |
78 return client; | 77 return client; |
79 } | 78 } |
80 | 79 |
81 // Get the subdirectory of the force-installed extension cache and the component | 80 // Get the subdirectory of the force-installed extension cache and the component |
82 // policy cache used for |account_id|. | 81 // policy cache used for |account_id|. |
83 std::string GetCacheSubdirectoryForAccountID(const std::string& account_id) { | 82 std::string GetCacheSubdirectoryForAccountID(const std::string& account_id) { |
84 return base::HexEncode(account_id.c_str(), account_id.size()); | 83 return base::HexEncode(account_id.c_str(), account_id.size()); |
85 } | 84 } |
(...skipping 26 matching lines...) Expand all Loading... |
112 GetCacheSubdirectoryForAccountID(account_id_to_delete)); | 111 GetCacheSubdirectoryForAccountID(account_id_to_delete)); |
113 if (base::DirectoryExists(path)) | 112 if (base::DirectoryExists(path)) |
114 base::DeleteFile(path, true); | 113 base::DeleteFile(path, true); |
115 } | 114 } |
116 | 115 |
117 } // namespace | 116 } // namespace |
118 | 117 |
119 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker( | 118 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker( |
120 const DeviceLocalAccount& account, | 119 const DeviceLocalAccount& account, |
121 const base::FilePath& component_policy_cache_path, | 120 const base::FilePath& component_policy_cache_path, |
122 scoped_ptr<DeviceLocalAccountPolicyStore> store, | 121 std::unique_ptr<DeviceLocalAccountPolicyStore> store, |
123 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, | 122 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, |
124 const base::Closure& policy_update_callback, | 123 const base::Closure& policy_update_callback, |
125 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 124 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
126 AffiliatedInvalidationServiceProvider* invalidation_service_provider) | 125 AffiliatedInvalidationServiceProvider* invalidation_service_provider) |
127 : invalidation_service_provider_(invalidation_service_provider), | 126 : invalidation_service_provider_(invalidation_service_provider), |
128 account_id_(account.account_id), | 127 account_id_(account.account_id), |
129 user_id_(account.user_id), | 128 user_id_(account.user_id), |
130 component_policy_cache_path_(component_policy_cache_path), | 129 component_policy_cache_path_(component_policy_cache_path), |
131 store_(std::move(store)), | 130 store_(std::move(store)), |
132 extension_tracker_(account, store_.get(), &schema_registry_), | 131 extension_tracker_(account, store_.get(), &schema_registry_), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return invalidator_ != nullptr; | 167 return invalidator_ != nullptr; |
169 } | 168 } |
170 | 169 |
171 void DeviceLocalAccountPolicyBroker::ConnectIfPossible( | 170 void DeviceLocalAccountPolicyBroker::ConnectIfPossible( |
172 chromeos::DeviceSettingsService* device_settings_service, | 171 chromeos::DeviceSettingsService* device_settings_service, |
173 DeviceManagementService* device_management_service, | 172 DeviceManagementService* device_management_service, |
174 scoped_refptr<net::URLRequestContextGetter> request_context) { | 173 scoped_refptr<net::URLRequestContextGetter> request_context) { |
175 if (core_.client()) | 174 if (core_.client()) |
176 return; | 175 return; |
177 | 176 |
178 scoped_ptr<CloudPolicyClient> client(CreateClient(device_settings_service, | 177 std::unique_ptr<CloudPolicyClient> client(CreateClient( |
179 device_management_service, | 178 device_settings_service, device_management_service, request_context)); |
180 request_context)); | |
181 if (!client) | 179 if (!client) |
182 return; | 180 return; |
183 | 181 |
184 CreateComponentCloudPolicyService(request_context, client.get()); | 182 CreateComponentCloudPolicyService(request_context, client.get()); |
185 core_.Connect(std::move(client)); | 183 core_.Connect(std::move(client)); |
186 external_data_manager_->Connect(request_context); | 184 external_data_manager_->Connect(request_context); |
187 core_.StartRefreshScheduler(); | 185 core_.StartRefreshScheduler(); |
188 UpdateRefreshDelay(); | 186 UpdateRefreshDelay(); |
189 invalidator_.reset(new AffiliatedCloudPolicyInvalidator( | 187 invalidator_.reset(new AffiliatedCloudPolicyInvalidator( |
190 em::DeviceRegisterRequest::DEVICE, | 188 em::DeviceRegisterRequest::DEVICE, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 224 |
227 void DeviceLocalAccountPolicyBroker::CreateComponentCloudPolicyService( | 225 void DeviceLocalAccountPolicyBroker::CreateComponentCloudPolicyService( |
228 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 226 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
229 CloudPolicyClient* client) { | 227 CloudPolicyClient* client) { |
230 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 228 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
231 switches::kDisableComponentCloudPolicy)) { | 229 switches::kDisableComponentCloudPolicy)) { |
232 // Disabled via the command line. | 230 // Disabled via the command line. |
233 return; | 231 return; |
234 } | 232 } |
235 | 233 |
236 scoped_ptr<ResourceCache> resource_cache( | 234 std::unique_ptr<ResourceCache> resource_cache( |
237 new ResourceCache(component_policy_cache_path_, | 235 new ResourceCache(component_policy_cache_path_, |
238 content::BrowserThread::GetMessageLoopProxyForThread( | 236 content::BrowserThread::GetMessageLoopProxyForThread( |
239 content::BrowserThread::FILE))); | 237 content::BrowserThread::FILE))); |
240 | 238 |
241 component_policy_service_.reset(new ComponentCloudPolicyService( | 239 component_policy_service_.reset(new ComponentCloudPolicyService( |
242 this, &schema_registry_, core(), client, std::move(resource_cache), | 240 this, &schema_registry_, core(), client, std::move(resource_cache), |
243 request_context, content::BrowserThread::GetMessageLoopProxyForThread( | 241 request_context, content::BrowserThread::GetMessageLoopProxyForThread( |
244 content::BrowserThread::FILE), | 242 content::BrowserThread::FILE), |
245 content::BrowserThread::GetMessageLoopProxyForThread( | 243 content::BrowserThread::GetMessageLoopProxyForThread( |
246 content::BrowserThread::IO))); | 244 content::BrowserThread::IO))); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 PolicyBrokerMap old_policy_brokers; | 436 PolicyBrokerMap old_policy_brokers; |
439 policy_brokers_.swap(old_policy_brokers); | 437 policy_brokers_.swap(old_policy_brokers); |
440 std::set<std::string> subdirectories_to_keep; | 438 std::set<std::string> subdirectories_to_keep; |
441 const std::vector<DeviceLocalAccount> device_local_accounts = | 439 const std::vector<DeviceLocalAccount> device_local_accounts = |
442 GetDeviceLocalAccounts(cros_settings_); | 440 GetDeviceLocalAccounts(cros_settings_); |
443 for (std::vector<DeviceLocalAccount>::const_iterator it = | 441 for (std::vector<DeviceLocalAccount>::const_iterator it = |
444 device_local_accounts.begin(); | 442 device_local_accounts.begin(); |
445 it != device_local_accounts.end(); ++it) { | 443 it != device_local_accounts.end(); ++it) { |
446 PolicyBrokerMap::iterator broker_it = old_policy_brokers.find(it->user_id); | 444 PolicyBrokerMap::iterator broker_it = old_policy_brokers.find(it->user_id); |
447 | 445 |
448 scoped_ptr<DeviceLocalAccountPolicyBroker> broker; | 446 std::unique_ptr<DeviceLocalAccountPolicyBroker> broker; |
449 bool broker_initialized = false; | 447 bool broker_initialized = false; |
450 if (broker_it != old_policy_brokers.end()) { | 448 if (broker_it != old_policy_brokers.end()) { |
451 // Reuse the existing broker if present. | 449 // Reuse the existing broker if present. |
452 broker.reset(broker_it->second); | 450 broker.reset(broker_it->second); |
453 old_policy_brokers.erase(broker_it); | 451 old_policy_brokers.erase(broker_it); |
454 broker_initialized = true; | 452 broker_initialized = true; |
455 } else { | 453 } else { |
456 scoped_ptr<DeviceLocalAccountPolicyStore> store( | 454 std::unique_ptr<DeviceLocalAccountPolicyStore> store( |
457 new DeviceLocalAccountPolicyStore(it->account_id, | 455 new DeviceLocalAccountPolicyStore( |
458 session_manager_client_, | 456 it->account_id, session_manager_client_, device_settings_service_, |
459 device_settings_service_, | 457 store_background_task_runner_)); |
460 store_background_task_runner_)); | |
461 scoped_refptr<DeviceLocalAccountExternalDataManager> | 458 scoped_refptr<DeviceLocalAccountExternalDataManager> |
462 external_data_manager = | 459 external_data_manager = |
463 external_data_service_->GetExternalDataManager(it->account_id, | 460 external_data_service_->GetExternalDataManager(it->account_id, |
464 store.get()); | 461 store.get()); |
465 broker.reset(new DeviceLocalAccountPolicyBroker( | 462 broker.reset(new DeviceLocalAccountPolicyBroker( |
466 *it, component_policy_cache_root_.Append( | 463 *it, component_policy_cache_root_.Append( |
467 GetCacheSubdirectoryForAccountID(it->account_id)), | 464 GetCacheSubdirectoryForAccountID(it->account_id)), |
468 std::move(store), external_data_manager, | 465 std::move(store), external_data_manager, |
469 base::Bind(&DeviceLocalAccountPolicyService::NotifyPolicyUpdated, | 466 base::Bind(&DeviceLocalAccountPolicyService::NotifyPolicyUpdated, |
470 base::Unretained(this), it->user_id), | 467 base::Unretained(this), it->user_id), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 } | 563 } |
567 return nullptr; | 564 return nullptr; |
568 } | 565 } |
569 | 566 |
570 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated( | 567 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated( |
571 const std::string& user_id) { | 568 const std::string& user_id) { |
572 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id)); | 569 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id)); |
573 } | 570 } |
574 | 571 |
575 } // namespace policy | 572 } // namespace policy |
OLD | NEW |