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/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
12 #include "base/files/file_path.h" | |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
15 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
16 #include "base/path_service.h" | 15 #include "base/path_service.h" |
17 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
17 #include "base/stl_util.h" | |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/chromeos/policy/device_local_account.h" | 20 #include "chrome/browser/chromeos/policy/device_local_account.h" |
21 #include "chrome/browser/chromeos/policy/device_local_account_external_data_serv ice.h" | 21 #include "chrome/browser/chromeos/policy/device_local_account_external_data_serv ice.h" |
22 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" | 22 #include "chrome/browser/chromeos/policy/device_local_account_policy_store.h" |
23 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 23 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
24 #include "chrome/common/chrome_content_client.h" | 24 #include "chrome/common/chrome_content_client.h" |
25 #include "chromeos/chromeos_paths.h" | 25 #include "chromeos/chromeos_paths.h" |
26 #include "chromeos/dbus/session_manager_client.h" | 26 #include "chromeos/dbus/session_manager_client.h" |
27 #include "chromeos/settings/cros_settings_names.h" | 27 #include "chromeos/settings/cros_settings_names.h" |
28 #include "chromeos/settings/cros_settings_provider.h" | 28 #include "chromeos/settings/cros_settings_provider.h" |
29 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 29 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
30 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 30 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
31 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 31 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
32 #include "components/policy/core/common/cloud/device_management_service.h" | 32 #include "components/policy/core/common/cloud/device_management_service.h" |
33 #include "components/policy/core/common/cloud/system_policy_request_context.h" | 33 #include "components/policy/core/common/cloud/system_policy_request_context.h" |
34 #include "content/public/browser/browser_thread.h" | |
34 #include "net/url_request/url_request_context_getter.h" | 35 #include "net/url_request/url_request_context_getter.h" |
35 #include "policy/policy_constants.h" | 36 #include "policy/policy_constants.h" |
36 #include "policy/proto/device_management_backend.pb.h" | 37 #include "policy/proto/device_management_backend.pb.h" |
37 #include "url/gurl.h" | 38 #include "url/gurl.h" |
38 | 39 |
39 namespace em = enterprise_management; | 40 namespace em = enterprise_management; |
40 | 41 |
41 namespace policy { | 42 namespace policy { |
42 | 43 |
43 namespace { | 44 namespace { |
(...skipping 21 matching lines...) Expand all Loading... | |
65 new CloudPolicyClient(std::string(), std::string(), | 66 new CloudPolicyClient(std::string(), std::string(), |
66 kPolicyVerificationKeyHash, | 67 kPolicyVerificationKeyHash, |
67 USER_AFFILIATION_MANAGED, | 68 USER_AFFILIATION_MANAGED, |
68 NULL, device_management_service, request_context)); | 69 NULL, device_management_service, request_context)); |
69 client->SetupRegistration(policy_data->request_token(), | 70 client->SetupRegistration(policy_data->request_token(), |
70 policy_data->device_id()); | 71 policy_data->device_id()); |
71 return client.Pass(); | 72 return client.Pass(); |
72 } | 73 } |
73 | 74 |
74 // Get the subdirectory of the cache directory in which force-installed | 75 // Get the subdirectory of the cache directory in which force-installed |
75 // extensions are cached for |account_id|. | 76 // extensions are cached for |account_id|. This is also used for the |
bartfab (slow)
2014/06/20 09:17:25
Nit: Why not reword the comment to talk about both
Joao da Silva
2014/06/20 11:48:45
Done.
| |
76 std::string GetCacheSubdirectoryForAccountID(const std::string& account_id) { | 77 // component policy cache. |
78 std::string EncodeAccountId(const std::string& account_id) { | |
bartfab (slow)
2014/06/20 09:17:25
Why did you rename this? "Encode" could mean a mil
Joao da Silva
2014/06/20 11:48:45
Done.
| |
77 return base::HexEncode(account_id.c_str(), account_id.size()); | 79 return base::HexEncode(account_id.c_str(), account_id.size()); |
78 } | 80 } |
79 | 81 |
80 // Cleans up the cache directory by removing subdirectories that are not found | 82 // Cleans up the cache directory by removing subdirectories that are not found |
81 // in |subdirectories_to_keep|. Only caches whose cache directory is found in | 83 // in |subdirectories_to_keep|. Only caches whose cache directory is found in |
82 // |subdirectories_to_keep| may be running while the clean-up is in progress. | 84 // |subdirectories_to_keep| may be running while the clean-up is in progress. |
83 void DeleteOrphanedExtensionCaches( | 85 void DeleteOrphanedCaches( |
86 const base::FilePath& cache_root_dir, | |
84 const std::set<std::string>& subdirectories_to_keep) { | 87 const std::set<std::string>& subdirectories_to_keep) { |
85 base::FilePath cache_root_dir; | |
86 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, | |
87 &cache_root_dir)); | |
88 base::FileEnumerator enumerator(cache_root_dir, | 88 base::FileEnumerator enumerator(cache_root_dir, |
89 false, | 89 false, |
90 base::FileEnumerator::DIRECTORIES); | 90 base::FileEnumerator::DIRECTORIES); |
91 for (base::FilePath path = enumerator.Next(); !path.empty(); | 91 for (base::FilePath path = enumerator.Next(); !path.empty(); |
92 path = enumerator.Next()) { | 92 path = enumerator.Next()) { |
93 const std::string subdirectory(path.BaseName().MaybeAsASCII()); | 93 const std::string subdirectory(path.BaseName().MaybeAsASCII()); |
94 if (subdirectories_to_keep.find(subdirectory) == | 94 if (!ContainsKey(subdirectories_to_keep, subdirectory)) |
95 subdirectories_to_keep.end()) { | |
96 base::DeleteFile(path, true); | 95 base::DeleteFile(path, true); |
97 } | |
98 } | 96 } |
99 } | 97 } |
100 | 98 |
101 // Removes the subdirectory belonging to |account_id_to_delete| from the cache | 99 // Removes the subdirectory belonging to |account_id_to_delete| from the cache |
102 // directory. No cache belonging to |account_id_to_delete| may be running while | 100 // directory. No cache belonging to |account_id_to_delete| may be running while |
103 // the removal is in progress. | 101 // the removal is in progress. |
104 void DeleteObsoleteExtensionCache(const std::string& account_id_to_delete) { | 102 void DeleteObsoleteExtensionCache(const std::string& account_id_to_delete) { |
105 base::FilePath cache_root_dir; | 103 base::FilePath cache_root_dir; |
106 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, | 104 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
107 &cache_root_dir)); | 105 &cache_root_dir)); |
108 const base::FilePath path = cache_root_dir | 106 const base::FilePath path = |
109 .Append(GetCacheSubdirectoryForAccountID(account_id_to_delete)); | 107 cache_root_dir.Append(EncodeAccountId(account_id_to_delete)); |
110 if (base::DirectoryExists(path)) | 108 if (base::DirectoryExists(path)) |
111 base::DeleteFile(path, true); | 109 base::DeleteFile(path, true); |
112 } | 110 } |
113 | 111 |
114 } // namespace | 112 } // namespace |
115 | 113 |
116 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker( | 114 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker( |
117 const DeviceLocalAccount& account, | 115 const DeviceLocalAccount& account, |
116 const base::FilePath& component_policy_cache_path, | |
118 scoped_ptr<DeviceLocalAccountPolicyStore> store, | 117 scoped_ptr<DeviceLocalAccountPolicyStore> store, |
119 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, | 118 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, |
120 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 119 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
121 : account_id_(account.account_id), | 120 : account_id_(account.account_id), |
122 user_id_(account.user_id), | 121 user_id_(account.user_id), |
122 component_policy_cache_path_(component_policy_cache_path), | |
123 store_(store.Pass()), | 123 store_(store.Pass()), |
124 external_data_manager_(external_data_manager), | 124 external_data_manager_(external_data_manager), |
125 core_(PolicyNamespaceKey(dm_protocol::kChromePublicAccountPolicyType, | 125 core_(PolicyNamespaceKey(dm_protocol::kChromePublicAccountPolicyType, |
126 store_->account_id()), | 126 store_->account_id()), |
127 store_.get(), | 127 store_.get(), |
128 task_runner) { | 128 task_runner) { |
129 base::FilePath cache_root_dir; | 129 base::FilePath cache_root_dir; |
130 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, | 130 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
131 &cache_root_dir)); | 131 &cache_root_dir)); |
132 extension_loader_ = new chromeos::DeviceLocalAccountExternalPolicyLoader( | 132 extension_loader_ = new chromeos::DeviceLocalAccountExternalPolicyLoader( |
133 store_.get(), | 133 store_.get(), cache_root_dir.Append(EncodeAccountId(account.account_id))); |
134 cache_root_dir.Append( | |
135 GetCacheSubdirectoryForAccountID(account.account_id))); | |
136 } | 134 } |
137 | 135 |
138 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() { | 136 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() { |
139 external_data_manager_->SetPolicyStore(NULL); | 137 external_data_manager_->SetPolicyStore(NULL); |
140 external_data_manager_->Disconnect(); | 138 external_data_manager_->Disconnect(); |
141 } | 139 } |
142 | 140 |
143 void DeviceLocalAccountPolicyBroker::Initialize() { | 141 void DeviceLocalAccountPolicyBroker::Initialize() { |
144 store_->Load(); | 142 store_->Load(); |
145 } | 143 } |
(...skipping 29 matching lines...) Expand all Loading... | |
175 | 173 |
176 std::string DeviceLocalAccountPolicyBroker::GetDisplayName() const { | 174 std::string DeviceLocalAccountPolicyBroker::GetDisplayName() const { |
177 std::string display_name; | 175 std::string display_name; |
178 const base::Value* display_name_value = | 176 const base::Value* display_name_value = |
179 store_->policy_map().GetValue(policy::key::kUserDisplayName); | 177 store_->policy_map().GetValue(policy::key::kUserDisplayName); |
180 if (display_name_value) | 178 if (display_name_value) |
181 display_name_value->GetAsString(&display_name); | 179 display_name_value->GetAsString(&display_name); |
182 return display_name; | 180 return display_name; |
183 } | 181 } |
184 | 182 |
183 base::FilePath DeviceLocalAccountPolicyBroker::GetComponentPolicyCachePath() | |
184 const { | |
185 return component_policy_cache_path_; | |
186 } | |
187 | |
185 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService( | 188 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService( |
186 chromeos::SessionManagerClient* session_manager_client, | 189 chromeos::SessionManagerClient* session_manager_client, |
187 chromeos::DeviceSettingsService* device_settings_service, | 190 chromeos::DeviceSettingsService* device_settings_service, |
188 chromeos::CrosSettings* cros_settings, | 191 chromeos::CrosSettings* cros_settings, |
189 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, | 192 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, |
190 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, | 193 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, |
191 scoped_refptr<base::SequencedTaskRunner> | 194 scoped_refptr<base::SequencedTaskRunner> |
192 external_data_service_backend_task_runner, | 195 external_data_service_backend_task_runner, |
193 scoped_refptr<base::SequencedTaskRunner> io_task_runner, | 196 scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
194 scoped_refptr<net::URLRequestContextGetter> request_context) | 197 scoped_refptr<net::URLRequestContextGetter> request_context) |
195 : session_manager_client_(session_manager_client), | 198 : session_manager_client_(session_manager_client), |
196 device_settings_service_(device_settings_service), | 199 device_settings_service_(device_settings_service), |
197 cros_settings_(cros_settings), | 200 cros_settings_(cros_settings), |
198 device_management_service_(NULL), | 201 device_management_service_(NULL), |
199 waiting_for_cros_settings_(false), | 202 waiting_for_cros_settings_(false), |
200 orphan_cache_deletion_state_(NOT_STARTED), | 203 orphan_cache_deletion_state_(NOT_STARTED), |
201 store_background_task_runner_(store_background_task_runner), | 204 store_background_task_runner_(store_background_task_runner), |
202 extension_cache_task_runner_(extension_cache_task_runner), | 205 extension_cache_task_runner_(extension_cache_task_runner), |
203 request_context_(request_context), | 206 request_context_(request_context), |
204 local_accounts_subscription_(cros_settings_->AddSettingsObserver( | 207 local_accounts_subscription_(cros_settings_->AddSettingsObserver( |
205 chromeos::kAccountsPrefDeviceLocalAccounts, | 208 chromeos::kAccountsPrefDeviceLocalAccounts, |
206 base::Bind(&DeviceLocalAccountPolicyService:: | 209 base::Bind(&DeviceLocalAccountPolicyService:: |
207 UpdateAccountListIfNonePending, | 210 UpdateAccountListIfNonePending, |
208 base::Unretained(this)))), | 211 base::Unretained(this)))), |
209 weak_factory_(this) { | 212 weak_factory_(this) { |
213 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY, | |
214 &component_policy_cache_root_)); | |
210 external_data_service_.reset(new DeviceLocalAccountExternalDataService( | 215 external_data_service_.reset(new DeviceLocalAccountExternalDataService( |
211 this, | 216 this, |
212 external_data_service_backend_task_runner, | 217 external_data_service_backend_task_runner, |
213 io_task_runner)); | 218 io_task_runner)); |
214 UpdateAccountList(); | 219 UpdateAccountList(); |
215 } | 220 } |
216 | 221 |
217 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() { | 222 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() { |
218 DCHECK(!request_context_); | 223 DCHECK(!request_context_); |
219 DCHECK(policy_brokers_.empty()); | 224 DCHECK(policy_brokers_.empty()); |
(...skipping 28 matching lines...) Expand all Loading... | |
248 | 253 |
249 return entry->second; | 254 return entry->second; |
250 } | 255 } |
251 | 256 |
252 bool DeviceLocalAccountPolicyService::IsPolicyAvailableForUser( | 257 bool DeviceLocalAccountPolicyService::IsPolicyAvailableForUser( |
253 const std::string& user_id) { | 258 const std::string& user_id) { |
254 DeviceLocalAccountPolicyBroker* broker = GetBrokerForUser(user_id); | 259 DeviceLocalAccountPolicyBroker* broker = GetBrokerForUser(user_id); |
255 return broker && broker->core()->store()->is_managed(); | 260 return broker && broker->core()->store()->is_managed(); |
256 } | 261 } |
257 | 262 |
263 scoped_refptr<net::URLRequestContextGetter> | |
264 DeviceLocalAccountPolicyService::request_context() const { | |
265 return request_context_; | |
266 } | |
267 | |
258 void DeviceLocalAccountPolicyService::AddObserver(Observer* observer) { | 268 void DeviceLocalAccountPolicyService::AddObserver(Observer* observer) { |
259 observers_.AddObserver(observer); | 269 observers_.AddObserver(observer); |
260 } | 270 } |
261 | 271 |
262 void DeviceLocalAccountPolicyService::RemoveObserver(Observer* observer) { | 272 void DeviceLocalAccountPolicyService::RemoveObserver(Observer* observer) { |
263 observers_.RemoveObserver(observer); | 273 observers_.RemoveObserver(observer); |
264 } | 274 } |
265 | 275 |
266 void DeviceLocalAccountPolicyService::OnStoreLoaded(CloudPolicyStore* store) { | 276 void DeviceLocalAccountPolicyService::OnStoreLoaded(CloudPolicyStore* store) { |
267 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store); | 277 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 session_manager_client_, | 417 session_manager_client_, |
408 device_settings_service_, | 418 device_settings_service_, |
409 store_background_task_runner_)); | 419 store_background_task_runner_)); |
410 store->AddObserver(this); | 420 store->AddObserver(this); |
411 scoped_refptr<DeviceLocalAccountExternalDataManager> | 421 scoped_refptr<DeviceLocalAccountExternalDataManager> |
412 external_data_manager = | 422 external_data_manager = |
413 external_data_service_->GetExternalDataManager(it->account_id, | 423 external_data_service_->GetExternalDataManager(it->account_id, |
414 store.get()); | 424 store.get()); |
415 broker.reset(new DeviceLocalAccountPolicyBroker( | 425 broker.reset(new DeviceLocalAccountPolicyBroker( |
416 *it, | 426 *it, |
427 component_policy_cache_root_.Append(EncodeAccountId(it->account_id)), | |
417 store.Pass(), | 428 store.Pass(), |
418 external_data_manager, | 429 external_data_manager, |
419 base::MessageLoopProxy::current())); | 430 base::MessageLoopProxy::current())); |
420 } | 431 } |
421 | 432 |
422 // Fire up the cloud connection for fetching policy for the account from | 433 // Fire up the cloud connection for fetching policy for the account from |
423 // the cloud if this is an enterprise-managed device. | 434 // the cloud if this is an enterprise-managed device. |
424 broker->ConnectIfPossible(device_settings_service_, | 435 broker->ConnectIfPossible(device_settings_service_, |
425 device_management_service_, | 436 device_management_service_, |
426 request_context_); | 437 request_context_); |
427 | 438 |
428 policy_brokers_[it->user_id] = broker.release(); | 439 policy_brokers_[it->user_id] = broker.release(); |
429 if (!broker_initialized) { | 440 if (!broker_initialized) { |
430 // The broker must be initialized after it has been added to | 441 // The broker must be initialized after it has been added to |
431 // |policy_brokers_|. | 442 // |policy_brokers_|. |
432 policy_brokers_[it->user_id]->Initialize(); | 443 policy_brokers_[it->user_id]->Initialize(); |
433 } | 444 } |
434 | 445 |
435 if (orphan_cache_deletion_state_ == NOT_STARTED) { | 446 subdirectories_to_keep.insert(EncodeAccountId(it->account_id)); |
436 subdirectories_to_keep.insert( | |
437 GetCacheSubdirectoryForAccountID(it->account_id)); | |
438 } | |
439 } | |
440 | |
441 std::set<std::string> obsolete_account_ids; | |
442 for (PolicyBrokerMap::const_iterator it = old_policy_brokers.begin(); | |
443 it != old_policy_brokers.end(); ++it) { | |
444 obsolete_account_ids.insert(it->second->account_id()); | |
445 } | 447 } |
446 | 448 |
447 if (orphan_cache_deletion_state_ == NOT_STARTED) { | 449 if (orphan_cache_deletion_state_ == NOT_STARTED) { |
448 DCHECK(old_policy_brokers.empty()); | 450 DCHECK(old_policy_brokers.empty()); |
449 DCHECK(busy_extension_cache_directories_.empty()); | 451 DCHECK(busy_extension_cache_directories_.empty()); |
450 | 452 |
451 // If this method is running for the first time, no extension caches have | 453 // If this method is running for the first time, no extension caches have |
452 // been started yet. Take this opportunity to do a clean-up by removing | 454 // been started yet. Take this opportunity to do a clean-up by removing |
453 // orphaned cache directories not found in |subdirectories_to_keep| from the | 455 // orphaned cache directories not found in |subdirectories_to_keep| from the |
454 // cache directory. | 456 // cache directory. |
455 orphan_cache_deletion_state_ = IN_PROGRESS; | 457 orphan_cache_deletion_state_ = IN_PROGRESS; |
458 | |
459 base::FilePath cache_root_dir; | |
460 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, | |
461 &cache_root_dir)); | |
456 extension_cache_task_runner_->PostTaskAndReply( | 462 extension_cache_task_runner_->PostTaskAndReply( |
457 FROM_HERE, | 463 FROM_HERE, |
458 base::Bind(&DeleteOrphanedExtensionCaches, subdirectories_to_keep), | 464 base::Bind( |
459 base::Bind(&DeviceLocalAccountPolicyService:: | 465 &DeleteOrphanedCaches, cache_root_dir, subdirectories_to_keep), |
460 OnOrphanedExtensionCachesDeleted, | 466 base::Bind( |
461 weak_factory_.GetWeakPtr())); | 467 &DeviceLocalAccountPolicyService::OnOrphanedExtensionCachesDeleted, |
468 weak_factory_.GetWeakPtr())); | |
462 | 469 |
463 // Start the extension caches for all brokers. These belong to accounts in | 470 // Start the extension caches for all brokers. These belong to accounts in |
464 // |account_ids| and are not affected by the clean-up. | 471 // |account_ids| and are not affected by the clean-up. |
465 StartExtensionCachesIfPossible(); | 472 StartExtensionCachesIfPossible(); |
466 } else { | 473 } else { |
467 // If this method has run before, obsolete brokers may exist. Shut down | 474 // If this method has run before, obsolete brokers may exist. Shut down |
468 // their extension caches and delete the brokers. | 475 // their extension caches and delete the brokers. |
469 DeleteBrokers(&old_policy_brokers); | 476 DeleteBrokers(&old_policy_brokers); |
470 | 477 |
471 if (orphan_cache_deletion_state_ == DONE) { | 478 if (orphan_cache_deletion_state_ == DONE) { |
472 // If the initial clean-up of orphaned cache directories has been | 479 // If the initial clean-up of orphaned cache directories has been |
473 // complete, start any extension caches that are not running yet but can | 480 // complete, start any extension caches that are not running yet but can |
474 // be started now because their cache directories are not busy. | 481 // be started now because their cache directories are not busy. |
475 StartExtensionCachesIfPossible(); | 482 StartExtensionCachesIfPossible(); |
476 } | 483 } |
477 } | 484 } |
478 | 485 |
486 // Purge the component policy caches of any accounts that have been removed. | |
487 // Do this only after any obsolete brokers have been destroyed. | |
488 // TODO(joaodasilva): for now this must be posted to the FILE thread, | |
489 // to avoid racing with the ComponentCloudPolicyStore. Use a task runner | |
490 // once that class supports another background thread too. | |
491 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | |
492 base::Bind(&DeleteOrphanedCaches, | |
493 component_policy_cache_root_, | |
494 subdirectories_to_keep)); | |
495 | |
479 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceLocalAccountsChanged()); | 496 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceLocalAccountsChanged()); |
480 } | 497 } |
481 | 498 |
482 void DeviceLocalAccountPolicyService::DeleteBrokers(PolicyBrokerMap* map) { | 499 void DeviceLocalAccountPolicyService::DeleteBrokers(PolicyBrokerMap* map) { |
483 for (PolicyBrokerMap::iterator it = map->begin(); it != map->end(); ++it) { | 500 for (PolicyBrokerMap::iterator it = map->begin(); it != map->end(); ++it) { |
484 it->second->core()->store()->RemoveObserver(this); | 501 it->second->core()->store()->RemoveObserver(this); |
485 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> | 502 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> |
486 extension_loader = it->second->extension_loader(); | 503 extension_loader = it->second->extension_loader(); |
487 if (extension_loader->IsCacheRunning()) { | 504 if (extension_loader->IsCacheRunning()) { |
488 DCHECK(!IsExtensionCacheDirectoryBusy(it->second->account_id())); | 505 DCHECK(!IsExtensionCacheDirectoryBusy(it->second->account_id())); |
489 busy_extension_cache_directories_.insert(it->second->account_id()); | 506 busy_extension_cache_directories_.insert(it->second->account_id()); |
490 extension_loader->StopCache(base::Bind( | 507 extension_loader->StopCache(base::Bind( |
491 &DeviceLocalAccountPolicyService::OnObsoleteExtensionCacheShutdown, | 508 &DeviceLocalAccountPolicyService::OnObsoleteExtensionCacheShutdown, |
492 weak_factory_.GetWeakPtr(), | 509 weak_factory_.GetWeakPtr(), |
493 it->second->account_id())); | 510 it->second->account_id())); |
494 } | 511 } |
512 FOR_EACH_OBSERVER(Observer, observers_, OnBrokerShutdown(it->second)); | |
495 delete it->second; | 513 delete it->second; |
496 } | 514 } |
497 map->clear(); | 515 map->clear(); |
498 } | 516 } |
499 | 517 |
500 DeviceLocalAccountPolicyBroker* | 518 DeviceLocalAccountPolicyBroker* |
501 DeviceLocalAccountPolicyService::GetBrokerForStore( | 519 DeviceLocalAccountPolicyService::GetBrokerForStore( |
502 CloudPolicyStore* store) { | 520 CloudPolicyStore* store) { |
503 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); | 521 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); |
504 it != policy_brokers_.end(); ++it) { | 522 it != policy_brokers_.end(); ++it) { |
505 if (it->second->core()->store() == store) | 523 if (it->second->core()->store() == store) |
506 return it->second; | 524 return it->second; |
507 } | 525 } |
508 return NULL; | 526 return NULL; |
509 } | 527 } |
510 | 528 |
511 } // namespace policy | 529 } // namespace policy |
OLD | NEW |