Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_local_account_external_data_service.cc
blobc08094fd72d3779c668b8aef96a2bfcb99aca1e6
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/policy/device_local_account_external_data_service.h"
7 #include <set>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/files/file_path.h"
12 #include "base/location.h"
13 #include "base/logging.h"
14 #include "base/path_service.h"
15 #include "base/sequenced_task_runner.h"
16 #include "chromeos/chromeos_paths.h"
17 #include "components/policy/core/common/cloud/cloud_policy_store.h"
18 #include "policy/policy_constants.h"
20 namespace policy {
22 DeviceLocalAccountExternalDataService::DeviceLocalAccountExternalDataService(
23 DeviceLocalAccountPolicyService* parent,
24 scoped_refptr<base::SequencedTaskRunner> backend_task_runner,
25 scoped_refptr<base::SequencedTaskRunner> io_task_runner)
26 : parent_(parent),
27 backend_task_runner_(backend_task_runner),
28 io_task_runner_(io_task_runner) {
29 base::FilePath cache_dir;
30 CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA,
31 &cache_dir));
32 resource_cache_.reset(new ResourceCache(cache_dir, backend_task_runner));
33 parent_->AddObserver(this);
36 DeviceLocalAccountExternalDataService::
37 ~DeviceLocalAccountExternalDataService() {
38 parent_->RemoveObserver(this);
39 #if !defined(NDEBUG)
40 for (ExternalDataManagerMap::const_iterator it =
41 external_data_managers_.begin();
42 it != external_data_managers_.end(); ++it) {
43 DCHECK(it->second->HasOneRef());
45 #endif // !defined(NDEBUG)
46 backend_task_runner_->DeleteSoon(FROM_HERE, resource_cache_.release());
49 void DeviceLocalAccountExternalDataService::OnPolicyUpdated(
50 const std::string& user_id) {
53 void DeviceLocalAccountExternalDataService::OnDeviceLocalAccountsChanged() {
54 std::set<std::string> account_ids;
55 for (ExternalDataManagerMap::iterator it = external_data_managers_.begin();
56 it != external_data_managers_.end(); ) {
57 if (it->second->HasOneRef()) {
58 external_data_managers_.erase(it++);
59 } else {
60 account_ids.insert(it->first);
61 ++it;
64 backend_task_runner_->PostTask(FROM_HERE, base::Bind(
65 &ResourceCache::PurgeOtherKeys,
66 base::Unretained(resource_cache_.get()),
67 account_ids));
70 scoped_refptr<DeviceLocalAccountExternalDataManager>
71 DeviceLocalAccountExternalDataService::GetExternalDataManager(
72 const std::string& account_id,
73 CloudPolicyStore* policy_store) {
74 scoped_refptr<DeviceLocalAccountExternalDataManager>& external_data_manager =
75 external_data_managers_[account_id];
76 if (!external_data_manager.get()) {
77 external_data_manager = new DeviceLocalAccountExternalDataManager(
78 account_id,
79 base::Bind(&GetChromePolicyDetails),
80 backend_task_runner_,
81 io_task_runner_,
82 resource_cache_.get());
84 external_data_manager->SetPolicyStore(policy_store);
85 return external_data_manager;
88 } // namespace policy