| 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 "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.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/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 16 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| 17 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 17 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" | 19 #include "chrome/browser/policy/cloud/cloud_external_data_manager.h" |
| 20 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" | 20 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" |
| 21 #include "chrome/browser/policy/cloud/resource_cache.h" | 21 #include "chrome/browser/policy/cloud/resource_cache.h" |
| 22 #include "chrome/browser/policy/policy_bundle.h" | 22 #include "chrome/browser/policy/policy_bundle.h" |
| 23 #include "chrome/common/chrome_switches.h" | |
| 24 #include "components/policy/core/common/policy_pref_names.h" | 23 #include "components/policy/core/common/policy_pref_names.h" |
| 24 #include "components/policy/core/common/policy_switches.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 27 | 27 |
| 28 namespace em = enterprise_management; | 28 namespace em = enterprise_management; |
| 29 | 29 |
| 30 namespace policy { | 30 namespace policy { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // UMA histogram names. | 34 // UMA histogram names. |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void UserCloudPolicyManagerChromeOS::OnClientError( | 225 void UserCloudPolicyManagerChromeOS::OnClientError( |
| 226 CloudPolicyClient* cloud_policy_client) { | 226 CloudPolicyClient* cloud_policy_client) { |
| 227 DCHECK_EQ(client(), cloud_policy_client); | 227 DCHECK_EQ(client(), cloud_policy_client); |
| 228 if (wait_for_policy_fetch_) { | 228 if (wait_for_policy_fetch_) { |
| 229 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError, | 229 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError, |
| 230 cloud_policy_client->status()); | 230 cloud_policy_client->status()); |
| 231 } | 231 } |
| 232 CancelWaitForPolicyFetch(); | 232 CancelWaitForPolicyFetch(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() { | |
| 236 core()->RefreshSoon(); | |
| 237 } | |
| 238 | |
| 239 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { | 235 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { |
| 240 CheckAndPublishPolicy(); | 236 CheckAndPublishPolicy(); |
| 241 StartRefreshSchedulerIfReady(); | 237 StartRefreshSchedulerIfReady(); |
| 242 } | 238 } |
| 243 | 239 |
| 244 void UserCloudPolicyManagerChromeOS::CreateComponentCloudPolicyService( | 240 void UserCloudPolicyManagerChromeOS::CreateComponentCloudPolicyService( |
| 245 const scoped_refptr<net::URLRequestContextGetter>& request_context) { | 241 const scoped_refptr<net::URLRequestContextGetter>& request_context) { |
| 246 // Init() must have been called. | 242 // Init() must have been called. |
| 247 DCHECK(schema_registry()); | 243 DCHECK(schema_registry()); |
| 248 // Called at most once. | 244 // Called at most once. |
| 249 DCHECK(!component_policy_service_); | 245 DCHECK(!component_policy_service_); |
| 250 | 246 |
| 251 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 247 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 252 switches::kEnableComponentCloudPolicy)) { | 248 switches::kEnableComponentCloudPolicy)) { |
| 253 return; | 249 return; |
| 254 } | 250 } |
| 255 | 251 |
| 256 // TODO(joaodasilva): Move the |backend_task_runner| to the blocking pool. | 252 // TODO(joaodasilva): Move the |backend_task_runner| to the blocking pool. |
| 257 // Currently it's not possible because the ComponentCloudPolicyStore is | 253 // Currently it's not possible because the ComponentCloudPolicyStore is |
| 258 // NonThreadSafe and doesn't support getting calls from different threads. | 254 // NonThreadSafe and doesn't support getting calls from different threads. |
| 259 scoped_refptr<base::SequencedTaskRunner> backend_task_runner = | 255 scoped_refptr<base::SequencedTaskRunner> backend_task_runner = |
| 260 content::BrowserThread::GetMessageLoopProxyForThread( | 256 content::BrowserThread::GetMessageLoopProxyForThread( |
| 261 content::BrowserThread::FILE); | 257 content::BrowserThread::FILE); |
| 262 scoped_ptr<ResourceCache> resource_cache( | 258 scoped_ptr<ResourceCache> resource_cache( |
| 263 new ResourceCache(resource_cache_dir_, backend_task_runner)); | 259 new ResourceCache(resource_cache_dir_, backend_task_runner)); |
| 264 component_policy_service_.reset(new ComponentCloudPolicyService( | 260 component_policy_service_.reset(new ComponentCloudPolicyService( |
| 265 this, | 261 this, |
| 266 schema_registry(), | 262 schema_registry(), |
| 267 store_.get(), | 263 core(), |
| 268 resource_cache.Pass(), | 264 resource_cache.Pass(), |
| 269 client(), | |
| 270 request_context, | 265 request_context, |
| 271 backend_task_runner, | 266 backend_task_runner, |
| 272 content::BrowserThread::GetMessageLoopProxyForThread( | 267 content::BrowserThread::GetMessageLoopProxyForThread( |
| 273 content::BrowserThread::IO))); | 268 content::BrowserThread::IO))); |
| 274 } | 269 } |
| 275 | 270 |
| 276 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { | 271 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { |
| 277 scoped_refptr<net::URLRequestContextGetter> signin_context; | 272 scoped_refptr<net::URLRequestContextGetter> signin_context; |
| 278 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); | 273 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); |
| 279 if (signin_profile) | 274 if (signin_profile) |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // OnComponentCloudPolicyUpdated() once it's ready. | 357 // OnComponentCloudPolicyUpdated() once it's ready. |
| 363 return; | 358 return; |
| 364 } | 359 } |
| 365 | 360 |
| 366 core()->StartRefreshScheduler(); | 361 core()->StartRefreshScheduler(); |
| 367 core()->TrackRefreshDelayPref(local_state_, | 362 core()->TrackRefreshDelayPref(local_state_, |
| 368 policy_prefs::kUserPolicyRefreshRate); | 363 policy_prefs::kUserPolicyRefreshRate); |
| 369 } | 364 } |
| 370 | 365 |
| 371 } // namespace policy | 366 } // namespace policy |
| OLD | NEW |