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

Side by Side Diff: chrome/browser/chromeos/login/oauth2_login_verifier.cc

Issue 148463004: Perform /ListAccounts check before session merge to see if there is a need for session merge at all. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
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/login/oauth2_login_verifier.h" 5 #include "chrome/browser/chromeos/login/oauth2_login_verifier.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 system_request_context_(system_request_context), 59 system_request_context_(system_request_context),
60 user_request_context_(user_request_context), 60 user_request_context_(user_request_context),
61 access_token_(oauthlogin_access_token), 61 access_token_(oauthlogin_access_token),
62 retry_count_(0) { 62 retry_count_(0) {
63 DCHECK(delegate); 63 DCHECK(delegate);
64 } 64 }
65 65
66 OAuth2LoginVerifier::~OAuth2LoginVerifier() { 66 OAuth2LoginVerifier::~OAuth2LoginVerifier() {
67 } 67 }
68 68
69 void OAuth2LoginVerifier::VerifyUserCookies(Profile* profile) {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
71
72 if (DelayNetworkCall(base::Bind(&OAuth2LoginVerifier::VerifyUserCookies,
73 AsWeakPtr(),
74 profile))) {
75 return;
76 }
77
78 StartAuthCookiesVerification();
79 }
80
69 void OAuth2LoginVerifier::VerifyProfileTokens(Profile* profile) { 81 void OAuth2LoginVerifier::VerifyProfileTokens(Profile* profile) {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
71 83
72 // Delay the verification if the network is not connected or on a captive 84 if (DelayNetworkCall(base::Bind(&OAuth2LoginVerifier::VerifyProfileTokens,
73 // portal. 85 AsWeakPtr(),
74 const NetworkState* default_network = 86 profile))) {
75 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
76 NetworkPortalDetector* detector = NetworkPortalDetector::Get();
77 if (!default_network ||
78 default_network->connection_state() == shill::kStatePortal ||
79 (detector && detector->GetCaptivePortalState(default_network).status !=
80 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE)) {
81 // If network is offline, defer the token fetching until online.
82 LOG(WARNING) << "Network is offline. Deferring OAuth2 access token fetch.";
83 BrowserThread::PostDelayedTask(
84 BrowserThread::UI,
85 FROM_HERE,
86 base::Bind(
87 &OAuth2LoginVerifier::VerifyProfileTokens, AsWeakPtr(), profile),
88 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
89 return; 87 return;
90 } 88 }
91 89
92 gaia_token_.clear(); 90 gaia_token_.clear();
93 if (access_token_.empty()) { 91 if (access_token_.empty()) {
94 // Fetch /OAuthLogin scoped access token. 92 // Fetch /OAuthLogin scoped access token.
95 StartFetchingOAuthLoginAccessToken(profile); 93 StartFetchingOAuthLoginAccessToken(profile);
96 } else { 94 } else {
97 // If OAuthLogin-scoped access token already exists (if it's generated 95 // If OAuthLogin-scoped access token already exists (if it's generated
98 // together with freshly minted refresh token), then fetch GAIA uber token. 96 // together with freshly minted refresh token), then fetch GAIA uber token.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Schedule post-merge verification to analyze how many LSID/SID overruns 156 // Schedule post-merge verification to analyze how many LSID/SID overruns
159 // were created by the session restore. 157 // were created by the session restore.
160 SchedulePostMergeVerification(); 158 SchedulePostMergeVerification();
161 } 159 }
162 160
163 void OAuth2LoginVerifier::SchedulePostMergeVerification() { 161 void OAuth2LoginVerifier::SchedulePostMergeVerification() {
164 BrowserThread::PostDelayedTask( 162 BrowserThread::PostDelayedTask(
165 BrowserThread::UI, 163 BrowserThread::UI,
166 FROM_HERE, 164 FROM_HERE,
167 base::Bind( 165 base::Bind(
168 &OAuth2LoginVerifier::StartPostRestoreVerification, AsWeakPtr()), 166 &OAuth2LoginVerifier::StartAuthCookiesVerification, AsWeakPtr()),
169 base::TimeDelta::FromMilliseconds(kPostResoreVerificationDelay)); 167 base::TimeDelta::FromMilliseconds(kPostResoreVerificationDelay));
170 } 168 }
171 169
172 void OAuth2LoginVerifier::StartPostRestoreVerification() { 170 void OAuth2LoginVerifier::StartAuthCookiesVerification() {
173 gaia_fetcher_.reset( 171 gaia_fetcher_.reset(
174 new GaiaAuthFetcher(this, 172 new GaiaAuthFetcher(this,
175 std::string(GaiaConstants::kChromeOSSource), 173 std::string(GaiaConstants::kChromeOSSource),
176 user_request_context_.get())); 174 user_request_context_.get()));
177 gaia_fetcher_->StartListAccounts(); 175 gaia_fetcher_->StartListAccounts();
178 } 176 }
179 177
180 void OAuth2LoginVerifier::OnMergeSessionFailure( 178 void OAuth2LoginVerifier::OnMergeSessionFailure(
181 const GoogleServiceAuthError& error) { 179 const GoogleServiceAuthError& error) {
182 LOG(WARNING) << "Failed MergeSession request," << " error: " << error.state(); 180 LOG(WARNING) << "Failed MergeSession request," << " error: " << error.state();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 226 }
229 227
230 void OAuth2LoginVerifier::OnListAccountsFailure( 228 void OAuth2LoginVerifier::OnListAccountsFailure(
231 const GoogleServiceAuthError& error) { 229 const GoogleServiceAuthError& error) {
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
233 LOG(WARNING) << "Failed to get list of session accounts, " 231 LOG(WARNING) << "Failed to get list of session accounts, "
234 << " error: " << error.state(); 232 << " error: " << error.state();
235 RetryOnError( 233 RetryOnError(
236 "ListAccounts", 234 "ListAccounts",
237 error, 235 error,
238 base::Bind(&OAuth2LoginVerifier::StartPostRestoreVerification, 236 base::Bind(&OAuth2LoginVerifier::StartAuthCookiesVerification,
239 AsWeakPtr()), 237 AsWeakPtr()),
240 base::Bind(&Delegate::OnListAccountsFailure, 238 base::Bind(&Delegate::OnListAccountsFailure,
241 base::Unretained(delegate_))); 239 base::Unretained(delegate_)));
242 } 240 }
243 241
244 void OAuth2LoginVerifier::RetryOnError(const char* operation_id, 242 void OAuth2LoginVerifier::RetryOnError(const char* operation_id,
245 const GoogleServiceAuthError& error, 243 const GoogleServiceAuthError& error,
246 const base::Closure& task_to_retry, 244 const base::Closure& task_to_retry,
247 const ErrorHandler& error_handler) { 245 const ErrorHandler& error_handler) {
248 if (IsConnectionOrServiceError(error) && 246 if (IsConnectionOrServiceError(error) &&
(...skipping 12 matching lines...) Expand all
261 LOG(WARNING) << "Unrecoverable error or retry count max reached for " 259 LOG(WARNING) << "Unrecoverable error or retry count max reached for "
262 << operation_id; 260 << operation_id;
263 UMA_HISTOGRAM_ENUMERATION( 261 UMA_HISTOGRAM_ENUMERATION(
264 base::StringPrintf("OAuth2Login.%sFailure", operation_id), 262 base::StringPrintf("OAuth2Login.%sFailure", operation_id),
265 error.state(), 263 error.state(),
266 GoogleServiceAuthError::NUM_STATES); 264 GoogleServiceAuthError::NUM_STATES);
267 265
268 error_handler.Run(IsConnectionOrServiceError(error)); 266 error_handler.Run(IsConnectionOrServiceError(error));
269 } 267 }
270 268
269 bool OAuth2LoginVerifier::DelayNetworkCall(const base::Closure& callback) {
270 // Delay the verification if the network is not connected or on a captive
271 // portal.
272 const NetworkState* default_network =
273 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
274 NetworkPortalDetector* detector = NetworkPortalDetector::Get();
275 if (!default_network ||
276 default_network->connection_state() == shill::kStatePortal ||
277 (detector && detector->GetCaptivePortalState(default_network).status !=
278 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE)) {
279 // If network is offline, defer the token fetching until online.
280 LOG(WARNING) << "Network is offline. Deferring call.";
281 BrowserThread::PostDelayedTask(
282 BrowserThread::UI,
283 FROM_HERE,
284 callback,
285 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
286 return true;
287 }
288
289 return false;
290 }
291
271 } // namespace chromeos 292 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698