| 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> | 7 #include <utility> |
| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 bundle->MergeFrom(component_policy_service_->policy()); | 107 bundle->MergeFrom(component_policy_service_->policy()); |
| 108 UpdatePolicy(std::move(bundle)); | 108 UpdatePolicy(std::move(bundle)); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 void CloudPolicyManager::GetChromePolicy(PolicyMap* policy_map) { | 112 void CloudPolicyManager::GetChromePolicy(PolicyMap* policy_map) { |
| 113 policy_map->CopyFrom(store()->policy_map()); | 113 policy_map->CopyFrom(store()->policy_map()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void CloudPolicyManager::CreateComponentCloudPolicyService( | 116 void CloudPolicyManager::CreateComponentCloudPolicyService( |
| 117 const std::string& policy_type, |
| 117 const base::FilePath& policy_cache_path, | 118 const base::FilePath& policy_cache_path, |
| 118 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 119 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 119 CloudPolicyClient* client) { | 120 CloudPolicyClient* client) { |
| 120 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 121 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 121 // Init() must have been called. | 122 // Init() must have been called. |
| 122 CHECK(schema_registry()); | 123 CHECK(schema_registry()); |
| 123 // Called at most once. | 124 // Called at most once. |
| 124 CHECK(!component_policy_service_); | 125 CHECK(!component_policy_service_); |
| 125 // The core can't be connected yet. | 126 // The core can't be connected yet. |
| 126 // See the comments on ComponentCloudPolicyService for the details. | 127 // See the comments on ComponentCloudPolicyService for the details. |
| 127 CHECK(!core()->client()); | 128 CHECK(!core()->client()); |
| 128 | 129 |
| 129 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 130 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 130 switches::kDisableComponentCloudPolicy) || | 131 switches::kDisableComponentCloudPolicy) || |
| 131 policy_cache_path.empty()) { | 132 policy_cache_path.empty()) { |
| 132 return; | 133 return; |
| 133 } | 134 } |
| 134 | 135 |
| 135 // TODO(joaodasilva): Move the |file_task_runner_| to the blocking pool. | 136 // TODO(joaodasilva): Move the |file_task_runner_| to the blocking pool. |
| 136 // Currently it's not possible because the ComponentCloudPolicyStore is | 137 // Currently it's not possible because the ComponentCloudPolicyStore is |
| 137 // NonThreadSafe and doesn't support getting calls from different threads. | 138 // NonThreadSafe and doesn't support getting calls from different threads. |
| 138 std::unique_ptr<ResourceCache> resource_cache( | 139 std::unique_ptr<ResourceCache> resource_cache( |
| 139 new ResourceCache(policy_cache_path, file_task_runner_)); | 140 new ResourceCache(policy_cache_path, file_task_runner_)); |
| 140 component_policy_service_.reset(new ComponentCloudPolicyService( | 141 component_policy_service_.reset(new ComponentCloudPolicyService( |
| 141 this, schema_registry(), core(), client, std::move(resource_cache), | 142 policy_type, this, schema_registry(), core(), client, |
| 142 request_context, file_task_runner_, io_task_runner_)); | 143 std::move(resource_cache), request_context, file_task_runner_, |
| 144 io_task_runner_)); |
| 143 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 145 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 144 } | 146 } |
| 145 | 147 |
| 146 void CloudPolicyManager::ClearAndDestroyComponentCloudPolicyService() { | 148 void CloudPolicyManager::ClearAndDestroyComponentCloudPolicyService() { |
| 147 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 149 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 148 if (component_policy_service_) { | 150 if (component_policy_service_) { |
| 149 component_policy_service_->ClearCache(); | 151 component_policy_service_->ClearCache(); |
| 150 component_policy_service_.reset(); | 152 component_policy_service_.reset(); |
| 151 } | 153 } |
| 152 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 154 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 153 } | 155 } |
| 154 | 156 |
| 155 void CloudPolicyManager::OnRefreshComplete(bool success) { | 157 void CloudPolicyManager::OnRefreshComplete(bool success) { |
| 156 waiting_for_policy_refresh_ = false; | 158 waiting_for_policy_refresh_ = false; |
| 157 CheckAndPublishPolicy(); | 159 CheckAndPublishPolicy(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 } // namespace policy | 162 } // namespace policy |
| OLD | NEW |