Chromium Code Reviews| Index: chrome/browser/chromeos/login/login_utils.cc |
| diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc |
| index 52ffb3c6e36dc6e127faab35688264363f6a2d27..93529c0e9545b1f6fb59f5c1a4db900586144254 100644 |
| --- a/chrome/browser/chromeos/login/login_utils.cc |
| +++ b/chrome/browser/chromeos/login/login_utils.cc |
| @@ -94,10 +94,15 @@ namespace chromeos { |
| namespace { |
| -// OAuth token verification retry count. |
| +// OAuth token verification max retry count. |
| const int kMaxOAuthTokenVerificationAttemptCount = 5; |
| -// OAuth token verification retry delay. |
| -const int kOAuthVerificationRestartDelay = 10000; // ms |
| +// OAuth token verification retry delay in milliseconds. |
| +const int kOAuthVerificationRestartDelay = 10000; |
| + |
| +// OAuth token request max retry count. |
| +const int kMaxOAuthTokenRequestAttemptCount = 5; |
| +// OAuth token request retry delay in milliseconds. |
| +const int kOAuthTokenRequestRestartDelay = 3000; |
| // Affixes for Auth token received from ClientLogin request. |
| const char kAuthPrefix[] = "Auth="; |
| @@ -334,7 +339,7 @@ class OAuthLoginVerifier : public base::SupportsWeakPtr<OAuthLoginVerifier>, |
| delegate_->OnOAuthVerificationFailed(username_); |
| } |
| - void OnCookueFetchFailed(const GoogleServiceAuthError& error) { |
| + void OnCookieFetchFailed(const GoogleServiceAuthError& error) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (!RetryOnError(error)) |
| delegate_->OnUserCookiesFetchFailed(username_); |
| @@ -350,7 +355,7 @@ class OAuthLoginVerifier : public base::SupportsWeakPtr<OAuthLoginVerifier>, |
| const GoogleServiceAuthError& error) OVERRIDE { |
| DVLOG(1) << "Failed IssueAuthToken request," |
| << " error.state=" << error.state(); |
| - OnCookueFetchFailed(error); |
| + OnCookieFetchFailed(error); |
| } |
| virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE { |
| @@ -364,7 +369,7 @@ class OAuthLoginVerifier : public base::SupportsWeakPtr<OAuthLoginVerifier>, |
| const GoogleServiceAuthError& error) OVERRIDE { |
| DVLOG(1) << "Failed MergeSession request," |
| << " error.state=" << error.state(); |
| - OnCookueFetchFailed(error); |
| + OnCookieFetchFailed(error); |
| } |
| OAuthLoginVerifier::Delegate* delegate_; |
| @@ -548,7 +553,8 @@ class LoginUtilsImpl |
| has_cookies_(false), |
| delegate_(NULL), |
| job_restart_request_(NULL), |
| - should_restore_auth_session_(false) { |
| + should_restore_auth_session_(false), |
| + token_request_count_(0) { |
| net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| } |
| @@ -676,6 +682,9 @@ class LoginUtilsImpl |
| // online state change. |
| bool should_restore_auth_session_; |
| + // Number of retries we have requested for OAuth1 access token. |
| + int token_request_count_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); |
| }; |
| @@ -890,7 +899,18 @@ void LoginUtilsImpl::OnProfileCreated( |
| // authentication UI. |
| // |
| // TODO(rickcam) We should use an isolated App here. |
| - FetchOAuth1AccessToken(authenticator_->authentication_profile()); |
| + NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); |
| + if (network_library && network_library->Connected()) { |
| + FetchOAuth1AccessToken(authenticator_->authentication_profile()); |
| + } else { |
| + VLOG(1) << "Network is unreacheable; deferring token request."; |
| + BrowserThread::PostDelayedTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&LoginUtilsImpl::FetchOAuth1AccessToken, |
| + base::Unretained(this), |
| + authenticator_->authentication_profile()), |
| + base::TimeDelta::FromMilliseconds(kOAuthTokenRequestRestartDelay)); |
| + } |
| } |
| } |
| @@ -1273,13 +1293,24 @@ void LoginUtilsImpl::StopBackgroundFetchers() { |
| void LoginUtilsImpl::OnGetOAuthTokenSuccess(const std::string& oauth_token) { |
| VLOG(1) << "Got OAuth request token!"; |
| + token_request_count_ = 0; |
| } |
| void LoginUtilsImpl::OnGetOAuthTokenFailure( |
| const GoogleServiceAuthError& error) { |
| - // TODO(zelidrag): Pop up sync setup UI here? |
| LOG(WARNING) << "Failed fetching OAuth request token, error: " |
| << error.state(); |
| + // If the request failed due to network flakiness, try again. |
|
zel
2012/05/25 15:19:36
Since this process is no longer super simple, let'
kochi
2012/05/28 08:46:12
Done.
|
| + if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE && |
|
Nikita (slow)
2012/05/25 18:12:08
error.state() == GoogleServiceAuthError::CONNECTIO
kochi
2012/05/28 08:46:12
Done.
|
| + token_request_count_++ < kMaxOAuthTokenRequestAttemptCount) { |
| + BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&LoginUtilsImpl::FetchOAuth1AccessToken, |
| + base::Unretained(this), |
| + authenticator_->authentication_profile()), |
| + base::TimeDelta::FromMilliseconds(kOAuthTokenRequestRestartDelay)); |
| + return; |
| + } |
| + LOG(WARNING) << "Unrecoverable error or retry count max reached, giving up."; |
| } |
| void LoginUtilsImpl::OnOAuthGetAccessTokenSuccess(const std::string& token, |