Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc

Issue 1108983002: Fetch policy with refresh token. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment and unit test Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 } 70 }
71 71
72 } // namespace 72 } // namespace
73 73
74 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( 74 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS(
75 scoped_ptr<CloudPolicyStore> store, 75 scoped_ptr<CloudPolicyStore> store,
76 scoped_ptr<CloudExternalDataManager> external_data_manager, 76 scoped_ptr<CloudExternalDataManager> external_data_manager,
77 const base::FilePath& component_policy_cache_path, 77 const base::FilePath& component_policy_cache_path,
78 bool wait_for_policy_fetch, 78 bool wait_for_policy_fetch,
79 const std::string& refresh_token,
79 base::TimeDelta initial_policy_fetch_timeout, 80 base::TimeDelta initial_policy_fetch_timeout,
80 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 81 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
81 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, 82 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner,
82 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner) 83 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner)
83 : CloudPolicyManager(dm_protocol::kChromeUserPolicyType, 84 : CloudPolicyManager(dm_protocol::kChromeUserPolicyType,
84 std::string(), 85 std::string(),
85 store.get(), 86 store.get(),
86 task_runner, 87 task_runner,
87 file_task_runner, 88 file_task_runner,
88 io_task_runner), 89 io_task_runner),
89 store_(store.Pass()), 90 store_(store.Pass()),
90 external_data_manager_(external_data_manager.Pass()), 91 external_data_manager_(external_data_manager.Pass()),
91 component_policy_cache_path_(component_policy_cache_path), 92 component_policy_cache_path_(component_policy_cache_path),
92 wait_for_policy_fetch_(wait_for_policy_fetch), 93 wait_for_policy_fetch_(wait_for_policy_fetch),
94 refresh_token_(refresh_token),
93 policy_fetch_timeout_(false, false) { 95 policy_fetch_timeout_(false, false) {
94 time_init_started_ = base::Time::Now(); 96 time_init_started_ = base::Time::Now();
95 if (wait_for_policy_fetch_ && !initial_policy_fetch_timeout.is_max()) { 97 if (wait_for_policy_fetch_ && !initial_policy_fetch_timeout.is_max()) {
96 policy_fetch_timeout_.Start( 98 policy_fetch_timeout_.Start(
97 FROM_HERE, 99 FROM_HERE,
98 initial_policy_fetch_timeout, 100 initial_policy_fetch_timeout,
99 base::Bind(&UserCloudPolicyManagerChromeOS::OnBlockingFetchTimeout, 101 base::Bind(&UserCloudPolicyManagerChromeOS::OnBlockingFetchTimeout,
100 base::Unretained(this))); 102 base::Unretained(this)));
101 } 103 }
102 } 104 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // In that case, the signin Profile is used to authenticate a Gaia request to 207 // 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. 208 // fetch a refresh token, and then the policy token is fetched.
207 // 209 //
208 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder 210 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder
209 // service will eventually call OnAccessTokenAvailable() once an access token 211 // service will eventually call OnAccessTokenAvailable() once an access token
210 // is available. That call may have already happened while waiting for 212 // is available. That call may have already happened while waiting for
211 // initialization of the CloudPolicyService, so in that case check if an 213 // initialization of the CloudPolicyService, so in that case check if an
212 // access token is already available. 214 // access token is already available.
213 if (!client()->is_registered()) { 215 if (!client()->is_registered()) {
214 if (wait_for_policy_fetch_) { 216 if (wait_for_policy_fetch_) {
215 FetchPolicyOAuthTokenUsingSigninContext(); 217 FetchPolicyOAuthToken();
216 } else if (!access_token_.empty()) { 218 } else if (!access_token_.empty()) {
217 OnAccessTokenAvailable(access_token_); 219 OnAccessTokenAvailable(access_token_);
218 } 220 }
219 } 221 }
220 222
221 if (!wait_for_policy_fetch_) { 223 if (!wait_for_policy_fetch_) {
222 // If this isn't blocking on a policy fetch then 224 // If this isn't blocking on a policy fetch then
223 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. 225 // CloudPolicyManager::OnStoreLoaded() already published the cached policy.
224 // Start the refresh scheduler now, which will eventually refresh the 226 // Start the refresh scheduler now, which will eventually refresh the
225 // cached policy or make the first fetch once the OAuth2 token is 227 // cached policy or make the first fetch once the OAuth2 token is
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 CloudPolicyManager::GetChromePolicy(policy_map); 281 CloudPolicyManager::GetChromePolicy(policy_map);
280 282
281 // If the store has a verified policy blob received from the server then apply 283 // 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 284 // the defaults for policies that haven't been configured by the administrator
283 // given that this is an enterprise user. 285 // given that this is an enterprise user.
284 if (!store()->has_policy()) 286 if (!store()->has_policy())
285 return; 287 return;
286 SetEnterpriseUsersDefaults(policy_map); 288 SetEnterpriseUsersDefaults(policy_map);
287 } 289 }
288 290
289 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthTokenUsingSigninContext() { 291 void UserCloudPolicyManagerChromeOS::FetchPolicyOAuthToken() {
292 if (!refresh_token_.empty()) {
Mattias Nissler (ping if slow) 2015/04/28 06:50:43 It's kinda inconsistent that the signin_context be
achuithb 2015/04/28 18:20:08 Done.
293 token_fetcher_.reset(new PolicyOAuth2TokenFetcher(
294 std::string(), g_browser_process->system_request_context(),
295 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched,
296 base::Unretained(this))));
297 token_fetcher_->StartWithRefreshToken(refresh_token_);
298 return;
299 }
300
290 scoped_refptr<net::URLRequestContextGetter> signin_context = 301 scoped_refptr<net::URLRequestContextGetter> signin_context =
291 chromeos::login::GetSigninContext(); 302 chromeos::login::GetSigninContext();
292 if (!signin_context.get()) { 303 if (!signin_context.get()) {
293 LOG(ERROR) << "No signin context for policy oauth token fetch!"; 304 LOG(ERROR) << "No signin context for policy oauth token fetch!";
294 OnOAuth2PolicyTokenFetched( 305 OnOAuth2PolicyTokenFetched(
295 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE)); 306 std::string(), GoogleServiceAuthError(GoogleServiceAuthError::NONE));
296 return; 307 return;
297 } 308 }
298 309
299 token_fetcher_.reset(new PolicyOAuth2TokenFetcher( 310 token_fetcher_.reset(new PolicyOAuth2TokenFetcher(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 // OnComponentCloudPolicyUpdated() once it's ready. 397 // OnComponentCloudPolicyUpdated() once it's ready.
387 return; 398 return;
388 } 399 }
389 400
390 core()->StartRefreshScheduler(); 401 core()->StartRefreshScheduler();
391 core()->TrackRefreshDelayPref(local_state_, 402 core()->TrackRefreshDelayPref(local_state_,
392 policy_prefs::kUserPolicyRefreshRate); 403 policy_prefs::kUserPolicyRefreshRate);
393 } 404 }
394 405
395 } // namespace policy 406 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698