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

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

Issue 1767443002: Add enterprise enrollment support for fake users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 9 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/policy_oauth2_token_fetcher.h" 5 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 13 matching lines...) Expand all
24 namespace { 24 namespace {
25 25
26 // Max retry count for token fetching requests. 26 // Max retry count for token fetching requests.
27 const int kMaxRequestAttemptCount = 5; 27 const int kMaxRequestAttemptCount = 5;
28 28
29 // OAuth token request retry delay in milliseconds. 29 // OAuth token request retry delay in milliseconds.
30 const int kRequestRestartDelay = 3000; 30 const int kRequestRestartDelay = 3000;
31 31
32 } // namespace 32 } // namespace
33 33
34 bool PolicyOAuth2TokenFetcher::enable_fake_for_testing_ = false;
achuithb 2016/03/03 22:45:00 do we use comment //static here? I think we do?
jdufault 2016/03/04 20:42:47 Done.
35
34 PolicyOAuth2TokenFetcher::PolicyOAuth2TokenFetcher() { 36 PolicyOAuth2TokenFetcher::PolicyOAuth2TokenFetcher() {
35 } 37 }
36 38
37 PolicyOAuth2TokenFetcher::~PolicyOAuth2TokenFetcher() { 39 PolicyOAuth2TokenFetcher::~PolicyOAuth2TokenFetcher() {
38 } 40 }
39 41
40 void PolicyOAuth2TokenFetcher::StartWithSigninContext( 42 void PolicyOAuth2TokenFetcher::StartWithSigninContext(
41 net::URLRequestContextGetter* auth_context_getter, 43 net::URLRequestContextGetter* auth_context_getter,
42 net::URLRequestContextGetter* system_context_getter, 44 net::URLRequestContextGetter* system_context_getter,
43 const TokenCallback& callback) { 45 const TokenCallback& callback) {
44 DCHECK(!refresh_token_fetcher_ && !access_token_fetcher_); 46 DCHECK(!refresh_token_fetcher_ && !access_token_fetcher_);
45 47
46 auth_context_getter_ = auth_context_getter; 48 auth_context_getter_ = auth_context_getter;
47 system_context_getter_ = system_context_getter; 49 system_context_getter_ = system_context_getter;
48 callback_ = callback; 50 callback_ = callback;
51
52 if (enable_fake_for_testing_) {
achuithb 2016/03/03 22:45:00 Rather than pollute this class, is it possible to
jdufault 2016/03/03 23:11:04 Sure; I will have to make PolicyOAuth2TokenFetcher
achuithb 2016/03/03 23:23:43 I think that would be cleaner?
achuithb 2016/03/04 19:12:37 Or maybe this is too much work for not much gain.
jdufault 2016/03/04 20:42:47 Done. Also moved the impl header file to the cc fi
53 OnGetTokenSuccess("authcode",
54 base::Time::Now() + base::TimeDelta::FromMinutes(5));
55 return;
56 }
57
49 StartFetchingRefreshToken(); 58 StartFetchingRefreshToken();
50 } 59 }
51 60
52 void PolicyOAuth2TokenFetcher::StartWithAuthCode( 61 void PolicyOAuth2TokenFetcher::StartWithAuthCode(
53 const std::string& auth_code, 62 const std::string& auth_code,
54 net::URLRequestContextGetter* system_context_getter, 63 net::URLRequestContextGetter* system_context_getter,
55 const TokenCallback& callback) { 64 const TokenCallback& callback) {
56 DCHECK(!refresh_token_fetcher_ && !access_token_fetcher_); 65 DCHECK(!refresh_token_fetcher_ && !access_token_fetcher_);
57 66
58 auth_code_ = auth_code; 67 auth_code_ = auth_code;
59 system_context_getter_ = system_context_getter; 68 system_context_getter_ = system_context_getter;
60 callback_ = callback; 69 callback_ = callback;
70
71 if (enable_fake_for_testing_) {
72 OnGetTokenSuccess("authcode",
73 base::Time::Now() + base::TimeDelta::FromMinutes(5));
74 return;
75 }
76
61 StartFetchingRefreshToken(); 77 StartFetchingRefreshToken();
62 } 78 }
63 79
64 void PolicyOAuth2TokenFetcher::StartWithRefreshToken( 80 void PolicyOAuth2TokenFetcher::StartWithRefreshToken(
65 const std::string& oauth2_refresh_token, 81 const std::string& oauth2_refresh_token,
66 net::URLRequestContextGetter* system_context_getter, 82 net::URLRequestContextGetter* system_context_getter,
67 const TokenCallback& callback) { 83 const TokenCallback& callback) {
68 DCHECK(!refresh_token_fetcher_ && !access_token_fetcher_); 84 DCHECK(!refresh_token_fetcher_ && !access_token_fetcher_);
69 85
70 oauth2_refresh_token_ = oauth2_refresh_token; 86 oauth2_refresh_token_ = oauth2_refresh_token;
71 system_context_getter_ = system_context_getter; 87 system_context_getter_ = system_context_getter;
72 callback_ = callback; 88 callback_ = callback;
89
90 if (enable_fake_for_testing_) {
91 OnGetTokenSuccess("authcode",
92 base::Time::Now() + base::TimeDelta::FromMinutes(5));
93 return;
94 }
95
73 StartFetchingAccessToken(); 96 StartFetchingAccessToken();
74 } 97 }
75 98
76 void PolicyOAuth2TokenFetcher::StartFetchingRefreshToken() { 99 void PolicyOAuth2TokenFetcher::StartFetchingRefreshToken() {
77 if (auth_code_.empty()) { 100 if (auth_code_.empty()) {
78 refresh_token_fetcher_.reset(new GaiaAuthFetcher( 101 refresh_token_fetcher_.reset(new GaiaAuthFetcher(
79 this, GaiaConstants::kChromeSource, auth_context_getter_.get())); 102 this, GaiaConstants::kChromeSource, auth_context_getter_.get()));
80 refresh_token_fetcher_->StartCookieForOAuthLoginTokenExchange( 103 refresh_token_fetcher_->StartCookieForOAuthLoginTokenExchange(
81 std::string()); 104 std::string());
82 } else { 105 } else {
(...skipping 10 matching lines...) Expand all
93 access_token_fetcher_.reset( 116 access_token_fetcher_.reset(
94 new OAuth2AccessTokenFetcherImpl(this, 117 new OAuth2AccessTokenFetcherImpl(this,
95 system_context_getter_.get(), 118 system_context_getter_.get(),
96 oauth2_refresh_token_)); 119 oauth2_refresh_token_));
97 access_token_fetcher_->Start( 120 access_token_fetcher_->Start(
98 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), 121 GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
99 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), 122 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
100 scopes); 123 scopes);
101 } 124 }
102 125
126 void PolicyOAuth2TokenFetcher::EnableFakeForTesting() {
127 enable_fake_for_testing_ = true;
128 }
129
103 void PolicyOAuth2TokenFetcher::OnClientOAuthSuccess( 130 void PolicyOAuth2TokenFetcher::OnClientOAuthSuccess(
104 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { 131 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) {
105 VLOG(1) << "OAuth2 tokens for policy fetching succeeded."; 132 VLOG(1) << "OAuth2 tokens for policy fetching succeeded.";
106 oauth2_refresh_token_ = oauth2_tokens.refresh_token; 133 oauth2_refresh_token_ = oauth2_tokens.refresh_token;
107 retry_count_ = 0; 134 retry_count_ = 0;
108 StartFetchingAccessToken(); 135 StartFetchingAccessToken();
109 } 136 }
110 137
111 void PolicyOAuth2TokenFetcher::OnClientOAuthFailure( 138 void PolicyOAuth2TokenFetcher::OnClientOAuthFailure(
112 const GoogleServiceAuthError& error) { 139 const GoogleServiceAuthError& error) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 181 }
155 182
156 void PolicyOAuth2TokenFetcher::ForwardPolicyToken( 183 void PolicyOAuth2TokenFetcher::ForwardPolicyToken(
157 const std::string& token, 184 const std::string& token,
158 const GoogleServiceAuthError& error) { 185 const GoogleServiceAuthError& error) {
159 if (!callback_.is_null()) 186 if (!callback_.is_null())
160 callback_.Run(token, error); 187 callback_.Run(token, error);
161 } 188 }
162 189
163 } // namespace policy 190 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698