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 "components/policy/core/common/cloud/cloud_policy_manager.h" | 5 #include "components/policy/core/common/cloud/cloud_policy_manager.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
14 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 16 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
15 #include "components/policy/core/common/policy_bundle.h" | 17 #include "components/policy/core/common/policy_bundle.h" |
16 #include "components/policy/core/common/policy_map.h" | 18 #include "components/policy/core/common/policy_map.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 94 } |
93 | 95 |
94 void CloudPolicyManager::CheckAndPublishPolicy() { | 96 void CloudPolicyManager::CheckAndPublishPolicy() { |
95 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && | 97 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && |
96 !waiting_for_policy_refresh_) { | 98 !waiting_for_policy_refresh_) { |
97 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); | 99 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); |
98 GetChromePolicy( | 100 GetChromePolicy( |
99 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); | 101 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); |
100 if (component_policy_service_) | 102 if (component_policy_service_) |
101 bundle->MergeFrom(component_policy_service_->policy()); | 103 bundle->MergeFrom(component_policy_service_->policy()); |
102 UpdatePolicy(bundle.Pass()); | 104 UpdatePolicy(std::move(bundle)); |
103 } | 105 } |
104 } | 106 } |
105 | 107 |
106 void CloudPolicyManager::GetChromePolicy(PolicyMap* policy_map) { | 108 void CloudPolicyManager::GetChromePolicy(PolicyMap* policy_map) { |
107 policy_map->CopyFrom(store()->policy_map()); | 109 policy_map->CopyFrom(store()->policy_map()); |
108 } | 110 } |
109 | 111 |
110 void CloudPolicyManager::CreateComponentCloudPolicyService( | 112 void CloudPolicyManager::CreateComponentCloudPolicyService( |
111 const base::FilePath& policy_cache_path, | 113 const base::FilePath& policy_cache_path, |
112 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 114 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
(...skipping 12 matching lines...) Expand all Loading... |
125 policy_cache_path.empty()) { | 127 policy_cache_path.empty()) { |
126 return; | 128 return; |
127 } | 129 } |
128 | 130 |
129 // TODO(joaodasilva): Move the |file_task_runner_| to the blocking pool. | 131 // TODO(joaodasilva): Move the |file_task_runner_| to the blocking pool. |
130 // Currently it's not possible because the ComponentCloudPolicyStore is | 132 // Currently it's not possible because the ComponentCloudPolicyStore is |
131 // NonThreadSafe and doesn't support getting calls from different threads. | 133 // NonThreadSafe and doesn't support getting calls from different threads. |
132 scoped_ptr<ResourceCache> resource_cache( | 134 scoped_ptr<ResourceCache> resource_cache( |
133 new ResourceCache(policy_cache_path, file_task_runner_)); | 135 new ResourceCache(policy_cache_path, file_task_runner_)); |
134 component_policy_service_.reset(new ComponentCloudPolicyService( | 136 component_policy_service_.reset(new ComponentCloudPolicyService( |
135 this, | 137 this, schema_registry(), core(), client, std::move(resource_cache), |
136 schema_registry(), | 138 request_context, file_task_runner_, io_task_runner_)); |
137 core(), | |
138 client, | |
139 resource_cache.Pass(), | |
140 request_context, | |
141 file_task_runner_, | |
142 io_task_runner_)); | |
143 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 139 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
144 } | 140 } |
145 | 141 |
146 void CloudPolicyManager::ClearAndDestroyComponentCloudPolicyService() { | 142 void CloudPolicyManager::ClearAndDestroyComponentCloudPolicyService() { |
147 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 143 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
148 if (component_policy_service_) { | 144 if (component_policy_service_) { |
149 component_policy_service_->ClearCache(); | 145 component_policy_service_->ClearCache(); |
150 component_policy_service_.reset(); | 146 component_policy_service_.reset(); |
151 } | 147 } |
152 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 148 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
153 } | 149 } |
154 | 150 |
155 void CloudPolicyManager::OnRefreshComplete(bool success) { | 151 void CloudPolicyManager::OnRefreshComplete(bool success) { |
156 waiting_for_policy_refresh_ = false; | 152 waiting_for_policy_refresh_ = false; |
157 CheckAndPublishPolicy(); | 153 CheckAndPublishPolicy(); |
158 } | 154 } |
159 | 155 |
160 } // namespace policy | 156 } // namespace policy |
OLD | NEW |