Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: trunk/src/chrome/browser/chromeos/policy/device_local_account_policy_service.cc

Issue 343103005: Revert 278518 "Wire up component cloud policy to device local ac..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/sequenced_task_runner.h" 17 #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"
35 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
36 #include "policy/policy_constants.h" 35 #include "policy/policy_constants.h"
37 #include "policy/proto/device_management_backend.pb.h" 36 #include "policy/proto/device_management_backend.pb.h"
38 #include "url/gurl.h" 37 #include "url/gurl.h"
39 38
40 namespace em = enterprise_management; 39 namespace em = enterprise_management;
41 40
42 namespace policy { 41 namespace policy {
43 42
44 namespace { 43 namespace {
(...skipping 21 matching lines...) Expand all
66 new CloudPolicyClient(std::string(), std::string(), 65 new CloudPolicyClient(std::string(), std::string(),
67 kPolicyVerificationKeyHash, 66 kPolicyVerificationKeyHash,
68 USER_AFFILIATION_MANAGED, 67 USER_AFFILIATION_MANAGED,
69 NULL, device_management_service, request_context)); 68 NULL, device_management_service, request_context));
70 client->SetupRegistration(policy_data->request_token(), 69 client->SetupRegistration(policy_data->request_token(),
71 policy_data->device_id()); 70 policy_data->device_id());
72 return client.Pass(); 71 return client.Pass();
73 } 72 }
74 73
75 // Get the subdirectory of the cache directory in which force-installed 74 // Get the subdirectory of the cache directory in which force-installed
76 // extensions are cached for |account_id|. This is also used for the 75 // extensions are cached for |account_id|.
77 // component policy cache. 76 std::string GetCacheSubdirectoryForAccountID(const std::string& account_id) {
78 std::string EncodeAccountId(const std::string& account_id) {
79 return base::HexEncode(account_id.c_str(), account_id.size()); 77 return base::HexEncode(account_id.c_str(), account_id.size());
80 } 78 }
81 79
82 // Cleans up the cache directory by removing subdirectories that are not found 80 // Cleans up the cache directory by removing subdirectories that are not found
83 // in |subdirectories_to_keep|. Only caches whose cache directory is found in 81 // in |subdirectories_to_keep|. Only caches whose cache directory is found in
84 // |subdirectories_to_keep| may be running while the clean-up is in progress. 82 // |subdirectories_to_keep| may be running while the clean-up is in progress.
85 void DeleteOrphanedCaches( 83 void DeleteOrphanedExtensionCaches(
86 const base::FilePath& cache_root_dir,
87 const std::set<std::string>& subdirectories_to_keep) { 84 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 (!ContainsKey(subdirectories_to_keep, subdirectory)) 94 if (subdirectories_to_keep.find(subdirectory) ==
95 subdirectories_to_keep.end()) {
95 base::DeleteFile(path, true); 96 base::DeleteFile(path, true);
97 }
96 } 98 }
97 } 99 }
98 100
99 // Removes the subdirectory belonging to |account_id_to_delete| from the cache 101 // Removes the subdirectory belonging to |account_id_to_delete| from the cache
100 // directory. No cache belonging to |account_id_to_delete| may be running while 102 // directory. No cache belonging to |account_id_to_delete| may be running while
101 // the removal is in progress. 103 // the removal is in progress.
102 void DeleteObsoleteExtensionCache(const std::string& account_id_to_delete) { 104 void DeleteObsoleteExtensionCache(const std::string& account_id_to_delete) {
103 base::FilePath cache_root_dir; 105 base::FilePath cache_root_dir;
104 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, 106 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
105 &cache_root_dir)); 107 &cache_root_dir));
106 const base::FilePath path = 108 const base::FilePath path = cache_root_dir
107 cache_root_dir.Append(EncodeAccountId(account_id_to_delete)); 109 .Append(GetCacheSubdirectoryForAccountID(account_id_to_delete));
108 if (base::DirectoryExists(path)) 110 if (base::DirectoryExists(path))
109 base::DeleteFile(path, true); 111 base::DeleteFile(path, true);
110 } 112 }
111 113
112 } // namespace 114 } // namespace
113 115
114 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker( 116 DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker(
115 const DeviceLocalAccount& account, 117 const DeviceLocalAccount& account,
116 const base::FilePath& component_policy_cache_path,
117 scoped_ptr<DeviceLocalAccountPolicyStore> store, 118 scoped_ptr<DeviceLocalAccountPolicyStore> store,
118 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager, 119 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager,
119 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 120 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
120 : account_id_(account.account_id), 121 : account_id_(account.account_id),
121 user_id_(account.user_id), 122 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(), cache_root_dir.Append(EncodeAccountId(account.account_id))); 133 store_.get(),
134 cache_root_dir.Append(
135 GetCacheSubdirectoryForAccountID(account.account_id)));
134 } 136 }
135 137
136 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() { 138 DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() {
137 external_data_manager_->SetPolicyStore(NULL); 139 external_data_manager_->SetPolicyStore(NULL);
138 external_data_manager_->Disconnect(); 140 external_data_manager_->Disconnect();
139 } 141 }
140 142
141 void DeviceLocalAccountPolicyBroker::Initialize() { 143 void DeviceLocalAccountPolicyBroker::Initialize() {
142 store_->Load(); 144 store_->Load();
143 } 145 }
(...skipping 29 matching lines...) Expand all
173 175
174 std::string DeviceLocalAccountPolicyBroker::GetDisplayName() const { 176 std::string DeviceLocalAccountPolicyBroker::GetDisplayName() const {
175 std::string display_name; 177 std::string display_name;
176 const base::Value* display_name_value = 178 const base::Value* display_name_value =
177 store_->policy_map().GetValue(policy::key::kUserDisplayName); 179 store_->policy_map().GetValue(policy::key::kUserDisplayName);
178 if (display_name_value) 180 if (display_name_value)
179 display_name_value->GetAsString(&display_name); 181 display_name_value->GetAsString(&display_name);
180 return display_name; 182 return display_name;
181 } 183 }
182 184
183 base::FilePath DeviceLocalAccountPolicyBroker::GetComponentPolicyCachePath()
184 const {
185 return component_policy_cache_path_;
186 }
187
188 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService( 185 DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService(
189 chromeos::SessionManagerClient* session_manager_client, 186 chromeos::SessionManagerClient* session_manager_client,
190 chromeos::DeviceSettingsService* device_settings_service, 187 chromeos::DeviceSettingsService* device_settings_service,
191 chromeos::CrosSettings* cros_settings, 188 chromeos::CrosSettings* cros_settings,
192 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner, 189 scoped_refptr<base::SequencedTaskRunner> store_background_task_runner,
193 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner, 190 scoped_refptr<base::SequencedTaskRunner> extension_cache_task_runner,
194 scoped_refptr<base::SequencedTaskRunner> 191 scoped_refptr<base::SequencedTaskRunner>
195 external_data_service_backend_task_runner, 192 external_data_service_backend_task_runner,
196 scoped_refptr<base::SequencedTaskRunner> io_task_runner, 193 scoped_refptr<base::SequencedTaskRunner> io_task_runner,
197 scoped_refptr<net::URLRequestContextGetter> request_context) 194 scoped_refptr<net::URLRequestContextGetter> request_context)
198 : session_manager_client_(session_manager_client), 195 : session_manager_client_(session_manager_client),
199 device_settings_service_(device_settings_service), 196 device_settings_service_(device_settings_service),
200 cros_settings_(cros_settings), 197 cros_settings_(cros_settings),
201 device_management_service_(NULL), 198 device_management_service_(NULL),
202 waiting_for_cros_settings_(false), 199 waiting_for_cros_settings_(false),
203 orphan_cache_deletion_state_(NOT_STARTED), 200 orphan_cache_deletion_state_(NOT_STARTED),
204 store_background_task_runner_(store_background_task_runner), 201 store_background_task_runner_(store_background_task_runner),
205 extension_cache_task_runner_(extension_cache_task_runner), 202 extension_cache_task_runner_(extension_cache_task_runner),
206 request_context_(request_context), 203 request_context_(request_context),
207 local_accounts_subscription_(cros_settings_->AddSettingsObserver( 204 local_accounts_subscription_(cros_settings_->AddSettingsObserver(
208 chromeos::kAccountsPrefDeviceLocalAccounts, 205 chromeos::kAccountsPrefDeviceLocalAccounts,
209 base::Bind(&DeviceLocalAccountPolicyService:: 206 base::Bind(&DeviceLocalAccountPolicyService::
210 UpdateAccountListIfNonePending, 207 UpdateAccountListIfNonePending,
211 base::Unretained(this)))), 208 base::Unretained(this)))),
212 weak_factory_(this) { 209 weak_factory_(this) {
213 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY,
214 &component_policy_cache_root_));
215 external_data_service_.reset(new DeviceLocalAccountExternalDataService( 210 external_data_service_.reset(new DeviceLocalAccountExternalDataService(
216 this, 211 this,
217 external_data_service_backend_task_runner, 212 external_data_service_backend_task_runner,
218 io_task_runner)); 213 io_task_runner));
219 UpdateAccountList(); 214 UpdateAccountList();
220 } 215 }
221 216
222 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() { 217 DeviceLocalAccountPolicyService::~DeviceLocalAccountPolicyService() {
223 DCHECK(!request_context_); 218 DCHECK(!request_context_);
224 DCHECK(policy_brokers_.empty()); 219 DCHECK(policy_brokers_.empty());
(...skipping 28 matching lines...) Expand all
253 248
254 return entry->second; 249 return entry->second;
255 } 250 }
256 251
257 bool DeviceLocalAccountPolicyService::IsPolicyAvailableForUser( 252 bool DeviceLocalAccountPolicyService::IsPolicyAvailableForUser(
258 const std::string& user_id) { 253 const std::string& user_id) {
259 DeviceLocalAccountPolicyBroker* broker = GetBrokerForUser(user_id); 254 DeviceLocalAccountPolicyBroker* broker = GetBrokerForUser(user_id);
260 return broker && broker->core()->store()->is_managed(); 255 return broker && broker->core()->store()->is_managed();
261 } 256 }
262 257
263 scoped_refptr<net::URLRequestContextGetter>
264 DeviceLocalAccountPolicyService::request_context() const {
265 return request_context_;
266 }
267
268 void DeviceLocalAccountPolicyService::AddObserver(Observer* observer) { 258 void DeviceLocalAccountPolicyService::AddObserver(Observer* observer) {
269 observers_.AddObserver(observer); 259 observers_.AddObserver(observer);
270 } 260 }
271 261
272 void DeviceLocalAccountPolicyService::RemoveObserver(Observer* observer) { 262 void DeviceLocalAccountPolicyService::RemoveObserver(Observer* observer) {
273 observers_.RemoveObserver(observer); 263 observers_.RemoveObserver(observer);
274 } 264 }
275 265
276 void DeviceLocalAccountPolicyService::OnStoreLoaded(CloudPolicyStore* store) { 266 void DeviceLocalAccountPolicyService::OnStoreLoaded(CloudPolicyStore* store) {
277 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store); 267 DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 session_manager_client_, 407 session_manager_client_,
418 device_settings_service_, 408 device_settings_service_,
419 store_background_task_runner_)); 409 store_background_task_runner_));
420 store->AddObserver(this); 410 store->AddObserver(this);
421 scoped_refptr<DeviceLocalAccountExternalDataManager> 411 scoped_refptr<DeviceLocalAccountExternalDataManager>
422 external_data_manager = 412 external_data_manager =
423 external_data_service_->GetExternalDataManager(it->account_id, 413 external_data_service_->GetExternalDataManager(it->account_id,
424 store.get()); 414 store.get());
425 broker.reset(new DeviceLocalAccountPolicyBroker( 415 broker.reset(new DeviceLocalAccountPolicyBroker(
426 *it, 416 *it,
427 component_policy_cache_root_.Append(EncodeAccountId(it->account_id)),
428 store.Pass(), 417 store.Pass(),
429 external_data_manager, 418 external_data_manager,
430 base::MessageLoopProxy::current())); 419 base::MessageLoopProxy::current()));
431 } 420 }
432 421
433 // Fire up the cloud connection for fetching policy for the account from 422 // Fire up the cloud connection for fetching policy for the account from
434 // the cloud if this is an enterprise-managed device. 423 // the cloud if this is an enterprise-managed device.
435 broker->ConnectIfPossible(device_settings_service_, 424 broker->ConnectIfPossible(device_settings_service_,
436 device_management_service_, 425 device_management_service_,
437 request_context_); 426 request_context_);
438 427
439 policy_brokers_[it->user_id] = broker.release(); 428 policy_brokers_[it->user_id] = broker.release();
440 if (!broker_initialized) { 429 if (!broker_initialized) {
441 // The broker must be initialized after it has been added to 430 // The broker must be initialized after it has been added to
442 // |policy_brokers_|. 431 // |policy_brokers_|.
443 policy_brokers_[it->user_id]->Initialize(); 432 policy_brokers_[it->user_id]->Initialize();
444 } 433 }
445 434
446 subdirectories_to_keep.insert(EncodeAccountId(it->account_id)); 435 if (orphan_cache_deletion_state_ == NOT_STARTED) {
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());
447 } 445 }
448 446
449 if (orphan_cache_deletion_state_ == NOT_STARTED) { 447 if (orphan_cache_deletion_state_ == NOT_STARTED) {
450 DCHECK(old_policy_brokers.empty()); 448 DCHECK(old_policy_brokers.empty());
451 DCHECK(busy_extension_cache_directories_.empty()); 449 DCHECK(busy_extension_cache_directories_.empty());
452 450
453 // If this method is running for the first time, no extension caches have 451 // If this method is running for the first time, no extension caches have
454 // been started yet. Take this opportunity to do a clean-up by removing 452 // been started yet. Take this opportunity to do a clean-up by removing
455 // orphaned cache directories not found in |subdirectories_to_keep| from the 453 // orphaned cache directories not found in |subdirectories_to_keep| from the
456 // cache directory. 454 // cache directory.
457 orphan_cache_deletion_state_ = IN_PROGRESS; 455 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));
462 extension_cache_task_runner_->PostTaskAndReply( 456 extension_cache_task_runner_->PostTaskAndReply(
463 FROM_HERE, 457 FROM_HERE,
464 base::Bind( 458 base::Bind(&DeleteOrphanedExtensionCaches, subdirectories_to_keep),
465 &DeleteOrphanedCaches, cache_root_dir, subdirectories_to_keep), 459 base::Bind(&DeviceLocalAccountPolicyService::
466 base::Bind( 460 OnOrphanedExtensionCachesDeleted,
467 &DeviceLocalAccountPolicyService::OnOrphanedExtensionCachesDeleted, 461 weak_factory_.GetWeakPtr()));
468 weak_factory_.GetWeakPtr()));
469 462
470 // Start the extension caches for all brokers. These belong to accounts in 463 // Start the extension caches for all brokers. These belong to accounts in
471 // |account_ids| and are not affected by the clean-up. 464 // |account_ids| and are not affected by the clean-up.
472 StartExtensionCachesIfPossible(); 465 StartExtensionCachesIfPossible();
473 } else { 466 } else {
474 // If this method has run before, obsolete brokers may exist. Shut down 467 // If this method has run before, obsolete brokers may exist. Shut down
475 // their extension caches and delete the brokers. 468 // their extension caches and delete the brokers.
476 DeleteBrokers(&old_policy_brokers); 469 DeleteBrokers(&old_policy_brokers);
477 470
478 if (orphan_cache_deletion_state_ == DONE) { 471 if (orphan_cache_deletion_state_ == DONE) {
479 // If the initial clean-up of orphaned cache directories has been 472 // If the initial clean-up of orphaned cache directories has been
480 // complete, start any extension caches that are not running yet but can 473 // complete, start any extension caches that are not running yet but can
481 // be started now because their cache directories are not busy. 474 // be started now because their cache directories are not busy.
482 StartExtensionCachesIfPossible(); 475 StartExtensionCachesIfPossible();
483 } 476 }
484 } 477 }
485 478
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
496 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceLocalAccountsChanged()); 479 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceLocalAccountsChanged());
497 } 480 }
498 481
499 void DeviceLocalAccountPolicyService::DeleteBrokers(PolicyBrokerMap* map) { 482 void DeviceLocalAccountPolicyService::DeleteBrokers(PolicyBrokerMap* map) {
500 for (PolicyBrokerMap::iterator it = map->begin(); it != map->end(); ++it) { 483 for (PolicyBrokerMap::iterator it = map->begin(); it != map->end(); ++it) {
501 it->second->core()->store()->RemoveObserver(this); 484 it->second->core()->store()->RemoveObserver(this);
502 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader> 485 scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader>
503 extension_loader = it->second->extension_loader(); 486 extension_loader = it->second->extension_loader();
504 if (extension_loader->IsCacheRunning()) { 487 if (extension_loader->IsCacheRunning()) {
505 DCHECK(!IsExtensionCacheDirectoryBusy(it->second->account_id())); 488 DCHECK(!IsExtensionCacheDirectoryBusy(it->second->account_id()));
506 busy_extension_cache_directories_.insert(it->second->account_id()); 489 busy_extension_cache_directories_.insert(it->second->account_id());
507 extension_loader->StopCache(base::Bind( 490 extension_loader->StopCache(base::Bind(
508 &DeviceLocalAccountPolicyService::OnObsoleteExtensionCacheShutdown, 491 &DeviceLocalAccountPolicyService::OnObsoleteExtensionCacheShutdown,
509 weak_factory_.GetWeakPtr(), 492 weak_factory_.GetWeakPtr(),
510 it->second->account_id())); 493 it->second->account_id()));
511 } 494 }
512 FOR_EACH_OBSERVER(Observer, observers_, OnBrokerShutdown(it->second));
513 delete it->second; 495 delete it->second;
514 } 496 }
515 map->clear(); 497 map->clear();
516 } 498 }
517 499
518 DeviceLocalAccountPolicyBroker* 500 DeviceLocalAccountPolicyBroker*
519 DeviceLocalAccountPolicyService::GetBrokerForStore( 501 DeviceLocalAccountPolicyService::GetBrokerForStore(
520 CloudPolicyStore* store) { 502 CloudPolicyStore* store) {
521 for (PolicyBrokerMap::iterator it(policy_brokers_.begin()); 503 for (PolicyBrokerMap::iterator it(policy_brokers_.begin());
522 it != policy_brokers_.end(); ++it) { 504 it != policy_brokers_.end(); ++it) {
523 if (it->second->core()->store() == store) 505 if (it->second->core()->store() == store)
524 return it->second; 506 return it->second;
525 } 507 }
526 return NULL; 508 return NULL;
527 } 509 }
528 510
529 } // namespace policy 511 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698