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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "policy/policy_constants.h" | 42 #include "policy/policy_constants.h" |
43 #include "policy/proto/device_management_backend.pb.h" | 43 #include "policy/proto/device_management_backend.pb.h" |
44 #include "url/gurl.h" | 44 #include "url/gurl.h" |
45 | 45 |
46 namespace em = enterprise_management; | 46 namespace em = enterprise_management; |
47 | 47 |
48 namespace policy { | 48 namespace policy { |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
52 // Creates and initializes a cloud policy client. Returns NULL if the device | 52 // Creates and initializes a cloud policy client. Returns nullptr if the device |
53 // doesn't have credentials in device settings (i.e. is not | 53 // doesn't have credentials in device settings (i.e. is not |
54 // enterprise-enrolled). | 54 // enterprise-enrolled). |
55 scoped_ptr<CloudPolicyClient> CreateClient( | 55 scoped_ptr<CloudPolicyClient> CreateClient( |
56 chromeos::DeviceSettingsService* device_settings_service, | 56 chromeos::DeviceSettingsService* device_settings_service, |
57 DeviceManagementService* device_management_service, | 57 DeviceManagementService* device_management_service, |
58 scoped_refptr<net::URLRequestContextGetter> system_request_context) { | 58 scoped_refptr<net::URLRequestContextGetter> system_request_context) { |
59 const em::PolicyData* policy_data = device_settings_service->policy_data(); | 59 const em::PolicyData* policy_data = device_settings_service->policy_data(); |
60 if (!policy_data || | 60 if (!policy_data || |
61 !policy_data->has_request_token() || | 61 !policy_data->has_request_token() || |
62 !policy_data->has_device_id() || | 62 !policy_data->has_device_id() || |
63 !device_management_service) { | 63 !device_management_service) { |
64 return scoped_ptr<CloudPolicyClient>(); | 64 return scoped_ptr<CloudPolicyClient>(); |
65 } | 65 } |
66 | 66 |
67 scoped_refptr<net::URLRequestContextGetter> request_context = | 67 scoped_refptr<net::URLRequestContextGetter> request_context = |
68 new SystemPolicyRequestContext( | 68 new SystemPolicyRequestContext( |
69 system_request_context, GetUserAgent()); | 69 system_request_context, GetUserAgent()); |
70 | 70 |
71 scoped_ptr<CloudPolicyClient> client( | 71 scoped_ptr<CloudPolicyClient> client(new CloudPolicyClient( |
72 new CloudPolicyClient(std::string(), std::string(), | 72 std::string(), std::string(), kPolicyVerificationKeyHash, |
73 kPolicyVerificationKeyHash, | 73 USER_AFFILIATION_MANAGED, nullptr, device_management_service, |
74 USER_AFFILIATION_MANAGED, | 74 request_context)); |
75 NULL, 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.Pass(); | 77 return client.Pass(); |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 scoped_ptr<DeviceLocalAccountPolicyStore> store, | 121 scoped_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 : account_id_(account.account_id), | 125 : account_id_(account.account_id), |
127 user_id_(account.user_id), | 126 user_id_(account.user_id), |
128 component_policy_cache_path_(component_policy_cache_path), | 127 component_policy_cache_path_(component_policy_cache_path), |
129 store_(store.Pass()), | 128 store_(store.Pass()), |
130 extension_tracker_(account, store_.get(), &schema_registry_), | 129 extension_tracker_(account, store_.get(), &schema_registry_), |
131 external_data_manager_(external_data_manager), | 130 external_data_manager_(external_data_manager), |
132 core_(PolicyNamespaceKey(dm_protocol::kChromePublicAccountPolicyType, | 131 core_(dm_protocol::kChromePublicAccountPolicyType, |
133 store_->account_id()), | 132 store_->account_id(), |
134 store_.get(), | 133 store_.get(), |
135 task_runner), | 134 task_runner), |
136 policy_update_callback_(policy_update_callback) { | 135 policy_update_callback_(policy_update_callback) { |
137 base::FilePath cache_root_dir; | 136 base::FilePath cache_root_dir; |
138 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, | 137 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
139 &cache_root_dir)); | 138 &cache_root_dir)); |
140 extension_loader_ = new chromeos::DeviceLocalAccountExternalPolicyLoader( | 139 extension_loader_ = new chromeos::DeviceLocalAccountExternalPolicyLoader( |
141 store_.get(), | 140 store_.get(), |
142 cache_root_dir.Append( | 141 cache_root_dir.Append( |
143 GetCacheSubdirectoryForAccountID(account.account_id))); | 142 GetCacheSubdirectoryForAccountID(account.account_id))); |
144 store_->AddObserver(this); | 143 store_->AddObserver(this); |
145 | 144 |
146 // Unblock the |schema_registry_| so that the |component_policy_service_| | 145 // Unblock the |schema_registry_| so that the |component_policy_service_| |
147 // starts using it. | 146 // starts using it. |
148 schema_registry_.RegisterComponent( | 147 schema_registry_.RegisterComponent( |
149 PolicyNamespace(POLICY_DOMAIN_CHROME, ""), | 148 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()), |
150 g_browser_process->browser_policy_connector()->GetChromeSchema()); | 149 g_browser_process->browser_policy_connector()->GetChromeSchema()); |
151 schema_registry_.SetReady(POLICY_DOMAIN_CHROME); | 150 schema_registry_.SetReady(POLICY_DOMAIN_CHROME); |
152 schema_registry_.SetReady(POLICY_DOMAIN_EXTENSIONS); | 151 schema_registry_.SetReady(POLICY_DOMAIN_EXTENSIONS); |
153 } | 152 } |
154 | 153 |
155 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() { | 154 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() { |
156 store_->RemoveObserver(this); | 155 store_->RemoveObserver(this); |
157 external_data_manager_->SetPolicyStore(NULL); | 156 external_data_manager_->SetPolicyStore(nullptr); |
158 external_data_manager_->Disconnect(); | 157 external_data_manager_->Disconnect(); |
159 } | 158 } |
160 | 159 |
161 void DeviceLocalAccountPolicyBroker::Initialize() { | 160 void DeviceLocalAccountPolicyBroker::Initialize() { |
162 store_->Load(); | 161 store_->Load(); |
163 } | 162 } |
164 | 163 |
165 void DeviceLocalAccountPolicyBroker::ConnectIfPossible( | 164 void DeviceLocalAccountPolicyBroker::ConnectIfPossible( |
166 chromeos::DeviceSettingsService* device_settings_service, | 165 chromeos::DeviceSettingsService* device_settings_service, |
167 DeviceManagementService* device_management_service, | 166 DeviceManagementService* device_management_service, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 chromeos::CrosSettings* cros_settings, | 244 chromeos::CrosSettings* cros_settings, |
246 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, | 245 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, |
247 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, | 246 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, |
248 scoped_refptr<base::SequencedTaskRunner> | 247 scoped_refptr<base::SequencedTaskRunner> |
249 external_data_service_backend_task_runner, | 248 external_data_service_backend_task_runner, |
250 scoped_refptr<base::SequencedTaskRunner> io_task_runner, | 249 scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
251 scoped_refptr<net::URLRequestContextGetter> request_context) | 250 scoped_refptr<net::URLRequestContextGetter> request_context) |
252 : session_manager_client_(session_manager_client), | 251 : session_manager_client_(session_manager_client), |
253 device_settings_service_(device_settings_service), | 252 device_settings_service_(device_settings_service), |
254 cros_settings_(cros_settings), | 253 cros_settings_(cros_settings), |
255 device_management_service_(NULL), | 254 device_management_service_(nullptr), |
256 waiting_for_cros_settings_(false), | 255 waiting_for_cros_settings_(false), |
257 orphan_extension_cache_deletion_state_(NOT_STARTED), | 256 orphan_extension_cache_deletion_state_(NOT_STARTED), |
258 store_background_task_runner_(store_background_task_runner), | 257 store_background_task_runner_(store_background_task_runner), |
259 extension_cache_task_runner_(extension_cache_task_runner), | 258 extension_cache_task_runner_(extension_cache_task_runner), |
260 request_context_(request_context), | 259 request_context_(request_context), |
261 local_accounts_subscription_(cros_settings_->AddSettingsObserver( | 260 local_accounts_subscription_(cros_settings_->AddSettingsObserver( |
262 chromeos::kAccountsPrefDeviceLocalAccounts, | 261 chromeos::kAccountsPrefDeviceLocalAccounts, |
263 base::Bind(&DeviceLocalAccountPolicyService:: | 262 base::Bind(&DeviceLocalAccountPolicyService:: |
264 UpdateAccountListIfNonePending, | 263 UpdateAccountListIfNonePending, |
265 base::Unretained(this)))), | 264 base::Unretained(this)))), |
266 weak_factory_(this) { | 265 weak_factory_(this) { |
267 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY, | 266 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY, |
268 &component_policy_cache_root_)); | 267 &component_policy_cache_root_)); |
269 external_data_service_.reset(new DeviceLocalAccountExternalDataService( | 268 external_data_service_.reset(new DeviceLocalAccountExternalDataService( |
270 this, | 269 this, |
271 external_data_service_backend_task_runner, | 270 external_data_service_backend_task_runner, |
272 io_task_runner)); | 271 io_task_runner)); |
273 UpdateAccountList(); | 272 UpdateAccountList(); |
274 } | 273 } |
275 | 274 |
276 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() { | 275 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() { |
277 DCHECK(!request_context_.get()); | 276 DCHECK(!request_context_.get()); |
278 DCHECK(policy_brokers_.empty()); | 277 DCHECK(policy_brokers_.empty()); |
279 } | 278 } |
280 | 279 |
281 void DeviceLocalAccountPolicyService::Shutdown() { | 280 void DeviceLocalAccountPolicyService::Shutdown() { |
282 device_management_service_ = NULL; | 281 device_management_service_ = nullptr; |
283 request_context_ = NULL; | 282 request_context_ = nullptr; |
284 DeleteBrokers(&policy_brokers_); | 283 DeleteBrokers(&policy_brokers_); |
285 } | 284 } |
286 | 285 |
287 void DeviceLocalAccountPolicyService::Connect( | 286 void DeviceLocalAccountPolicyService::Connect( |
288 DeviceManagementService* device_management_service) { | 287 DeviceManagementService* device_management_service) { |
289 DCHECK(!device_management_service_); | 288 DCHECK(!device_management_service_); |
290 device_management_service_ = device_management_service; | 289 device_management_service_ = device_management_service; |
291 | 290 |
292 // Connect the brokers. | 291 // Connect the brokers. |
293 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); | 292 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); |
294 it != policy_brokers_.end(); ++it) { | 293 it != policy_brokers_.end(); ++it) { |
295 it->second->ConnectIfPossible(device_settings_service_, | 294 it->second->ConnectIfPossible(device_settings_service_, |
296 device_management_service_, | 295 device_management_service_, |
297 request_context_); | 296 request_context_); |
298 } | 297 } |
299 } | 298 } |
300 | 299 |
301 DeviceLocalAccountPolicyBroker* | 300 DeviceLocalAccountPolicyBroker* |
302 DeviceLocalAccountPolicyService::GetBrokerForUser( | 301 DeviceLocalAccountPolicyService::GetBrokerForUser( |
303 const std::string& user_id) { | 302 const std::string& user_id) { |
304 PolicyBrokerMap::iterator entry = policy_brokers_.find(user_id); | 303 PolicyBrokerMap::iterator entry = policy_brokers_.find(user_id); |
305 if (entry == policy_brokers_.end()) | 304 if (entry == policy_brokers_.end()) |
306 return NULL; | 305 return nullptr; |
307 | 306 |
308 return entry->second; | 307 return entry->second; |
309 } | 308 } |
310 | 309 |
311 bool DeviceLocalAccountPolicyService::IsPolicyAvailableForUser( | 310 bool DeviceLocalAccountPolicyService::IsPolicyAvailableForUser( |
312 const std::string& user_id) { | 311 const std::string& user_id) { |
313 DeviceLocalAccountPolicyBroker* broker = GetBrokerForUser(user_id); | 312 DeviceLocalAccountPolicyBroker* broker = GetBrokerForUser(user_id); |
314 return broker && broker->core()->store()->is_managed(); | 313 return broker && broker->core()->store()->is_managed(); |
315 } | 314 } |
316 | 315 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 } | 550 } |
552 | 551 |
553 DeviceLocalAccountPolicyBroker* | 552 DeviceLocalAccountPolicyBroker* |
554 DeviceLocalAccountPolicyService::GetBrokerForStore( | 553 DeviceLocalAccountPolicyService::GetBrokerForStore( |
555 CloudPolicyStore* store) { | 554 CloudPolicyStore* store) { |
556 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); | 555 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); |
557 it != policy_brokers_.end(); ++it) { | 556 it != policy_brokers_.end(); ++it) { |
558 if (it->second->core()->store() == store) | 557 if (it->second->core()->store() == store) |
559 return it->second; | 558 return it->second; |
560 } | 559 } |
561 return NULL; | 560 return nullptr; |
562 } | 561 } |
563 | 562 |
564 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated( | 563 void DeviceLocalAccountPolicyService::NotifyPolicyUpdated( |
565 const std::string& user_id) { | 564 const std::string& user_id) { |
566 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id)); | 565 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id)); |
567 } | 566 } |
568 | 567 |
569 } // namespace policy | 568 } // namespace policy |
OLD | NEW |