| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/login/helper.h" |
| 15 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 16 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| 16 #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" |
| 17 #include "chrome/browser/chromeos/policy/wildcard_login_checker.h" | 18 #include "chrome/browser/chromeos/policy/wildcard_login_checker.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 19 #include "chrome/browser/lifetime/application_lifetime.h" | 19 #include "chrome/browser/lifetime/application_lifetime.h" |
| 20 #include "chrome/common/chrome_content_client.h" | 20 #include "chrome/common/chrome_content_client.h" |
| 21 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" | 21 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" |
| 22 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 22 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
| 23 #include "components/policy/core/common/cloud/device_management_service.h" | 23 #include "components/policy/core/common/cloud/device_management_service.h" |
| 24 #include "components/policy/core/common/cloud/system_policy_request_context.h" | 24 #include "components/policy/core/common/cloud/system_policy_request_context.h" |
| 25 #include "components/policy/core/common/policy_map.h" | 25 #include "components/policy/core/common/policy_map.h" |
| 26 #include "components/policy/core/common/policy_pref_names.h" | 26 #include "components/policy/core/common/policy_pref_names.h" |
| 27 #include "components/policy/core/common/policy_types.h" | 27 #include "components/policy/core/common/policy_types.h" |
| 28 #include "components/user_manager/user_manager.h" | 28 #include "components/user_manager/user_manager.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // In that case, the signin Profile is used to authenticate a Gaia request to | 205 // In that case, the signin Profile is used to authenticate a Gaia request to |
| 206 // fetch a refresh token, and then the policy token is fetched. | 206 // fetch a refresh token, and then the policy token is fetched. |
| 207 // | 207 // |
| 208 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder | 208 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder |
| 209 // service will eventually call OnAccessTokenAvailable() once an access token | 209 // service will eventually call OnAccessTokenAvailable() once an access token |
| 210 // is available. That call may have already happened while waiting for | 210 // is available. That call may have already happened while waiting for |
| 211 // initialization of the CloudPolicyService, so in that case check if an | 211 // initialization of the CloudPolicyService, so in that case check if an |
| 212 // access token is already available. | 212 // access token is already available. |
| 213 if (!client()->is_registered()) { | 213 if (!client()->is_registered()) { |
| 214 if (wait_for_policy_fetch_) { | 214 if (wait_for_policy_fetch_) { |
| 215 FetchPolicyOAuthTokenUsingSigninProfile(); | 215 FetchPolicyOAuthTokenUsingSigninContext(); |
| 216 } else if (!access_token_.empty()) { | 216 } else if (!access_token_.empty()) { |
| 217 OnAccessTokenAvailable(access_token_); | 217 OnAccessTokenAvailable(access_token_); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| 221 if (!wait_for_policy_fetch_) { | 221 if (!wait_for_policy_fetch_) { |
| 222 // If this isn't blocking on a policy fetch then | 222 // If this isn't blocking on a policy fetch then |
| 223 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. | 223 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. |
| 224 // Start the refresh scheduler now, which will eventually refresh the | 224 // Start the refresh scheduler now, which will eventually refresh the |
| 225 // cached policy or make the first fetch once the OAuth2 token is | 225 // cached policy or make the first fetch once the OAuth2 token is |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 CloudPolicyManager::GetChromePolicy(policy_map); | 279 CloudPolicyManager::GetChromePolicy(policy_map); |
| 280 | 280 |
| 281 // If the store has a verified policy blob received from the server then apply | 281 // If the store has a verified policy blob received from the server then apply |
| 282 // the defaults for policies that haven't been configured by the administrator | 282 // the defaults for policies that haven't been configured by the administrator |
| 283 // given that this is an enterprise user. | 283 // given that this is an enterprise user. |
| 284 if (!store()->has_policy()) | 284 if (!store()->has_policy()) |
| 285 return; | 285 return; |
| 286 SetEnterpriseUsersDefaults(policy_map); | 286 SetEnterpriseUsersDefaults(policy_map); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninProfile() { | 289 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninContext() { |
| 290 scoped_refptr<net::URLRequestContextGetter> signin_context; | 290 scoped_refptr<net::URLRequestContextGetter> signin_context = |
| 291 Profile* signin_profile = chromeos::ProfileHelper::GetSigninProfile(); | 291 chromeos::login::GetSigninContext(); |
| 292 if (signin_profile) | |
| 293 signin_context = signin_profile->GetRequestContext(); | |
| 294 if (!signin_context.get()) { | 292 if (!signin_context.get()) { |
| 295 LOG(ERROR) << "No signin Profile for policy oauth token fetch!"; | 293 LOG(ERROR) << "No signin context for policy oauth token fetch!"; |
| 296 OnOAuth2PolicyTokenFetched( | 294 OnOAuth2PolicyTokenFetched( |
| 297 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE)); | 295 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
| 298 return; | 296 return; |
| 299 } | 297 } |
| 300 | 298 |
| 301 token_fetcher_.reset(new PolicyOAuth2TokenFetcher( | 299 token_fetcher_.reset(new PolicyOAuth2TokenFetcher( |
| 302 signin_context.get(), | 300 signin_context.get(), |
| 303 g_browser_process->system_request_context(), | 301 g_browser_process->system_request_context(), |
| 304 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched, | 302 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched, |
| 305 base::Unretained(this)))); | 303 base::Unretained(this)))); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // OnComponentCloudPolicyUpdated() once it's ready. | 386 // OnComponentCloudPolicyUpdated() once it's ready. |
| 389 return; | 387 return; |
| 390 } | 388 } |
| 391 | 389 |
| 392 core()->StartRefreshScheduler(); | 390 core()->StartRefreshScheduler(); |
| 393 core()->TrackRefreshDelayPref(local_state_, | 391 core()->TrackRefreshDelayPref(local_state_, |
| 394 policy_prefs::kUserPolicyRefreshRate); | 392 policy_prefs::kUserPolicyRefreshRate); |
| 395 } | 393 } |
| 396 | 394 |
| 397 } // namespace policy | 395 } // namespace policy |
| OLD | NEW |