| OLD | NEW |
| 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/login/oauth1_token_fetcher.h" | 5 #include "chrome/browser/chromeos/login/oauth1_token_fetcher.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 9 #include "chrome/browser/chromeos/cros/network_library.h" | 9 #include "chrome/browser/chromeos/cros/network_library.h" |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 12 #include "google_apis/gaia/google_service_auth_error.h" | 11 #include "google_apis/gaia/google_service_auth_error.h" |
| 13 | 12 |
| 14 using content::BrowserThread; | 13 using content::BrowserThread; |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 // OAuth token request max retry count. | 17 // OAuth token request max retry count. |
| 19 const int kMaxOAuth1TokenRequestAttemptCount = 5; | 18 const int kMaxOAuth1TokenRequestAttemptCount = 5; |
| 20 // OAuth token request retry delay in milliseconds. | 19 // OAuth token request retry delay in milliseconds. |
| 21 const int kOAuth1TokenRequestRestartDelay = 3000; | 20 const int kOAuth1TokenRequestRestartDelay = 3000; |
| 22 | 21 |
| 23 // The service scope of the OAuth v2 token that ChromeOS login will be | 22 // The service scope of the OAuth v2 token that ChromeOS login will be |
| 24 // requesting. | 23 // requesting. |
| 25 const char kServiceScopeChromeOS[] = | 24 const char kServiceScopeChromeOS[] = |
| 26 "https://www.googleapis.com/auth/chromesync"; | 25 "https://www.googleapis.com/auth/chromesync"; |
| 27 | 26 |
| 28 } // namespace | 27 } // namespace |
| 29 | 28 |
| 30 namespace chromeos { | 29 namespace chromeos { |
| 31 | 30 |
| 32 OAuth1TokenFetcher::OAuth1TokenFetcher(OAuth1TokenFetcher::Delegate* delegate, | 31 OAuth1TokenFetcher::OAuth1TokenFetcher( |
| 33 Profile* auth_profile) | 32 OAuth1TokenFetcher::Delegate* delegate, |
| 33 net::URLRequestContextGetter* auth_context_getter) |
| 34 : delegate_(delegate), | 34 : delegate_(delegate), |
| 35 auth_profile_(auth_profile), | 35 oauth_fetcher_(this, auth_context_getter, kServiceScopeChromeOS), |
| 36 oauth_fetcher_(this, | |
| 37 auth_profile_->GetRequestContext(), | |
| 38 kServiceScopeChromeOS), | |
| 39 retry_count_(0) { | 36 retry_count_(0) { |
| 40 DCHECK(delegate); | 37 DCHECK(delegate); |
| 41 } | 38 } |
| 42 | 39 |
| 43 OAuth1TokenFetcher::~OAuth1TokenFetcher() { | 40 OAuth1TokenFetcher::~OAuth1TokenFetcher() { |
| 44 } | 41 } |
| 45 | 42 |
| 46 void OAuth1TokenFetcher::Start() { | 43 void OAuth1TokenFetcher::Start() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 48 if (CrosLibrary::Get()->libcros_loaded()) { | 45 if (CrosLibrary::Get()->libcros_loaded()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 68 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED || | 65 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED || |
| 69 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE || | 66 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE || |
| 70 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) && | 67 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) && |
| 71 retry_count_++ < kMaxOAuth1TokenRequestAttemptCount) { | 68 retry_count_++ < kMaxOAuth1TokenRequestAttemptCount) { |
| 72 BrowserThread::PostDelayedTask( | 69 BrowserThread::PostDelayedTask( |
| 73 BrowserThread::UI, FROM_HERE, | 70 BrowserThread::UI, FROM_HERE, |
| 74 base::Bind(&OAuth1TokenFetcher::Start, AsWeakPtr()), | 71 base::Bind(&OAuth1TokenFetcher::Start, AsWeakPtr()), |
| 75 base::TimeDelta::FromMilliseconds(kOAuth1TokenRequestRestartDelay)); | 72 base::TimeDelta::FromMilliseconds(kOAuth1TokenRequestRestartDelay)); |
| 76 return true; | 73 return true; |
| 77 } | 74 } |
| 78 LOG(WARNING) << "Unrecoverable error or retry count max reached."; | 75 LOG(ERROR) << "Unrecoverable error or retry count max reached."; |
| 79 return false; | 76 return false; |
| 80 } | 77 } |
| 81 | 78 |
| 82 void OAuth1TokenFetcher::OnGetOAuthTokenSuccess( | 79 void OAuth1TokenFetcher::OnGetOAuthTokenSuccess( |
| 83 const std::string& oauth_token) { | 80 const std::string& oauth_token) { |
| 84 VLOG(1) << "Got OAuth request token!"; | 81 LOG(INFO) << "Got OAuth request token!"; |
| 85 } | 82 } |
| 86 | 83 |
| 87 void OAuth1TokenFetcher::OnGetOAuthTokenFailure( | 84 void OAuth1TokenFetcher::OnGetOAuthTokenFailure( |
| 88 const GoogleServiceAuthError& error) { | 85 const GoogleServiceAuthError& error) { |
| 89 LOG(WARNING) << "Failed to get OAuth1 request token, error: " | 86 LOG(ERROR) << "Failed to get OAuth1 request token, error: " |
| 90 << error.state(); | 87 << error.state(); |
| 91 if (!RetryOnError(error)) | 88 if (!RetryOnError(error)) |
| 92 delegate_->OnOAuth1AccessTokenFetchFailed(); | 89 delegate_->OnOAuth1AccessTokenFetchFailed(); |
| 93 } | 90 } |
| 94 | 91 |
| 95 void OAuth1TokenFetcher::OnOAuthGetAccessTokenSuccess( | 92 void OAuth1TokenFetcher::OnOAuthGetAccessTokenSuccess( |
| 96 const std::string& token, | 93 const std::string& token, |
| 97 const std::string& secret) { | 94 const std::string& secret) { |
| 98 VLOG(1) << "Got OAuth v1 token!"; | 95 LOG(INFO) << "Got OAuth v1 token!"; |
| 99 retry_count_ = 0; | 96 retry_count_ = 0; |
| 100 delegate_->OnOAuth1AccessTokenAvailable(token, secret); | 97 delegate_->OnOAuth1AccessTokenAvailable(token, secret); |
| 101 } | 98 } |
| 102 | 99 |
| 103 void OAuth1TokenFetcher::OnOAuthGetAccessTokenFailure( | 100 void OAuth1TokenFetcher::OnOAuthGetAccessTokenFailure( |
| 104 const GoogleServiceAuthError& error) { | 101 const GoogleServiceAuthError& error) { |
| 105 LOG(WARNING) << "Failed fetching OAuth1 access token, error: " | 102 LOG(ERROR) << "Failed fetching OAuth1 access token, error: " |
| 106 << error.state(); | 103 << error.state(); |
| 107 if (!RetryOnError(error)) | 104 if (!RetryOnError(error)) |
| 108 delegate_->OnOAuth1AccessTokenFetchFailed(); | 105 delegate_->OnOAuth1AccessTokenFetchFailed(); |
| 109 } | 106 } |
| 110 | 107 |
| 111 } // namespace chromeos | 108 } // namespace chromeos |
| OLD | NEW |