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

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

Powered by Google App Engine
This is Rietveld 408576698