| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 15 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
| 16 #include "components/policy/core/common/policy_bundle.h" | 16 #include "components/policy/core/common/policy_bundle.h" |
| 17 #include "components/policy/core/common/policy_map.h" | 17 #include "components/policy/core/common/policy_map.h" |
| 18 #include "components/policy/core/common/policy_switches.h" | 18 #include "components/policy/core/common/policy_switches.h" |
| 19 #include "components/policy/core/common/schema_registry.h" |
| 19 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
| 21 | 22 |
| 22 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 23 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 23 #include "components/policy/core/common/cloud/resource_cache.h" | 24 #include "components/policy/core/common/cloud/resource_cache.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace policy { | 27 namespace policy { |
| 27 | 28 |
| 28 CloudPolicyManager::CloudPolicyManager( | 29 CloudPolicyManager::CloudPolicyManager( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 111 } |
| 111 | 112 |
| 112 void CloudPolicyManager::GetChromePolicy(PolicyMap* policy_map) { | 113 void CloudPolicyManager::GetChromePolicy(PolicyMap* policy_map) { |
| 113 policy_map->CopyFrom(store()->policy_map()); | 114 policy_map->CopyFrom(store()->policy_map()); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void CloudPolicyManager::CreateComponentCloudPolicyService( | 117 void CloudPolicyManager::CreateComponentCloudPolicyService( |
| 117 const std::string& policy_type, | 118 const std::string& policy_type, |
| 118 const base::FilePath& policy_cache_path, | 119 const base::FilePath& policy_cache_path, |
| 119 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 120 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 120 CloudPolicyClient* client) { | 121 CloudPolicyClient* client, |
| 122 SchemaRegistry* schema_registry) { |
| 121 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 123 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 122 // Init() must have been called. | 124 // Init() must have been called. |
| 123 CHECK(schema_registry()); | 125 CHECK(schema_registry); |
| 124 // Called at most once. | 126 // Called at most once. |
| 125 CHECK(!component_policy_service_); | 127 CHECK(!component_policy_service_); |
| 126 // The core can't be connected yet. | 128 // The core can't be connected yet. |
| 127 // See the comments on ComponentCloudPolicyService for the details. | 129 // See the comments on ComponentCloudPolicyService for the details. |
| 128 CHECK(!core()->client()); | 130 CHECK(!core()->client()); |
| 129 | 131 |
| 130 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 132 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 131 switches::kDisableComponentCloudPolicy) || | 133 switches::kDisableComponentCloudPolicy) || |
| 132 policy_cache_path.empty()) { | 134 policy_cache_path.empty()) { |
| 133 return; | 135 return; |
| 134 } | 136 } |
| 135 | 137 |
| 136 // TODO(joaodasilva): Move the |file_task_runner_| to the blocking pool. | 138 // TODO(joaodasilva): Move the |file_task_runner_| to the blocking pool. |
| 137 // Currently it's not possible because the ComponentCloudPolicyStore is | 139 // Currently it's not possible because the ComponentCloudPolicyStore is |
| 138 // NonThreadSafe and doesn't support getting calls from different threads. | 140 // NonThreadSafe and doesn't support getting calls from different threads. |
| 139 std::unique_ptr<ResourceCache> resource_cache( | 141 std::unique_ptr<ResourceCache> resource_cache( |
| 140 new ResourceCache(policy_cache_path, file_task_runner_)); | 142 new ResourceCache(policy_cache_path, file_task_runner_)); |
| 141 component_policy_service_.reset(new ComponentCloudPolicyService( | 143 component_policy_service_.reset(new ComponentCloudPolicyService( |
| 142 policy_type, this, schema_registry(), core(), client, | 144 policy_type, this, schema_registry, core(), client, |
| 143 std::move(resource_cache), request_context, file_task_runner_, | 145 std::move(resource_cache), request_context, file_task_runner_, |
| 144 io_task_runner_)); | 146 io_task_runner_)); |
| 145 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 147 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 146 } | 148 } |
| 147 | 149 |
| 148 void CloudPolicyManager::ClearAndDestroyComponentCloudPolicyService() { | 150 void CloudPolicyManager::ClearAndDestroyComponentCloudPolicyService() { |
| 149 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 151 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 150 if (component_policy_service_) { | 152 if (component_policy_service_) { |
| 151 component_policy_service_->ClearCache(); | 153 component_policy_service_->ClearCache(); |
| 152 component_policy_service_.reset(); | 154 component_policy_service_.reset(); |
| 153 } | 155 } |
| 154 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) | 156 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) |
| 155 } | 157 } |
| 156 | 158 |
| 157 void CloudPolicyManager::OnRefreshComplete(bool success) { | 159 void CloudPolicyManager::OnRefreshComplete(bool success) { |
| 158 waiting_for_policy_refresh_ = false; | 160 waiting_for_policy_refresh_ = false; |
| 159 CheckAndPublishPolicy(); | 161 CheckAndPublishPolicy(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 } // namespace policy | 164 } // namespace policy |
| OLD | NEW |