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