| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signin/oauth2_login_verifier.h" | 5 #include "chrome/browser/chromeos/login/signin/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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 user_request_context_(user_request_context), | 57 user_request_context_(user_request_context), |
| 58 access_token_(oauthlogin_access_token), | 58 access_token_(oauthlogin_access_token), |
| 59 retry_count_(0) { | 59 retry_count_(0) { |
| 60 DCHECK(delegate); | 60 DCHECK(delegate); |
| 61 } | 61 } |
| 62 | 62 |
| 63 OAuth2LoginVerifier::~OAuth2LoginVerifier() { | 63 OAuth2LoginVerifier::~OAuth2LoginVerifier() { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void OAuth2LoginVerifier::VerifyUserCookies(Profile* profile) { | 66 void OAuth2LoginVerifier::VerifyUserCookies(Profile* profile) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 68 | 68 |
| 69 // Delay the verification if the network is not connected or on a captive | 69 // Delay the verification if the network is not connected or on a captive |
| 70 // portal. | 70 // portal. |
| 71 DelayNetworkCall( | 71 DelayNetworkCall( |
| 72 base::TimeDelta::FromMilliseconds(kRequestRestartDelay), | 72 base::TimeDelta::FromMilliseconds(kRequestRestartDelay), |
| 73 base::Bind(&OAuth2LoginVerifier::StartAuthCookiesVerification, | 73 base::Bind(&OAuth2LoginVerifier::StartAuthCookiesVerification, |
| 74 AsWeakPtr())); | 74 AsWeakPtr())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void OAuth2LoginVerifier::VerifyProfileTokens(Profile* profile) { | 77 void OAuth2LoginVerifier::VerifyProfileTokens(Profile* profile) { |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 79 | 79 |
| 80 // Delay the verification if the network is not connected or on a captive | 80 // Delay the verification if the network is not connected or on a captive |
| 81 // portal. | 81 // portal. |
| 82 DelayNetworkCall(base::TimeDelta::FromMilliseconds(kRequestRestartDelay), | 82 DelayNetworkCall(base::TimeDelta::FromMilliseconds(kRequestRestartDelay), |
| 83 base::Bind(&OAuth2LoginVerifier::VerifyProfileTokensImpl, | 83 base::Bind(&OAuth2LoginVerifier::VerifyProfileTokensImpl, |
| 84 AsWeakPtr(), profile)); | 84 AsWeakPtr(), profile)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void OAuth2LoginVerifier::VerifyProfileTokensImpl(Profile* profile) { | 87 void OAuth2LoginVerifier::VerifyProfileTokensImpl(Profile* profile) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 88 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 89 | 89 |
| 90 gaia_token_.clear(); | 90 gaia_token_.clear(); |
| 91 if (access_token_.empty()) { | 91 if (access_token_.empty()) { |
| 92 // Fetch /OAuthLogin scoped access token. | 92 // Fetch /OAuthLogin scoped access token. |
| 93 StartFetchingOAuthLoginAccessToken(profile); | 93 StartFetchingOAuthLoginAccessToken(profile); |
| 94 } else { | 94 } else { |
| 95 // If OAuthLogin-scoped access token already exists (if it's generated | 95 // If OAuthLogin-scoped access token already exists (if it's generated |
| 96 // together with freshly minted refresh token), then fetch GAIA uber token. | 96 // together with freshly minted refresh token), then fetch GAIA uber token. |
| 97 StartOAuthLoginForUberToken(); | 97 StartOAuthLoginForUberToken(); |
| 98 } | 98 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 125 void OAuth2LoginVerifier::OnUberAuthTokenSuccess( | 125 void OAuth2LoginVerifier::OnUberAuthTokenSuccess( |
| 126 const std::string& uber_token) { | 126 const std::string& uber_token) { |
| 127 VLOG(1) << "OAuthLogin(uber_token) successful!"; | 127 VLOG(1) << "OAuthLogin(uber_token) successful!"; |
| 128 retry_count_ = 0; | 128 retry_count_ = 0; |
| 129 gaia_token_ = uber_token; | 129 gaia_token_ = uber_token; |
| 130 StartMergeSession(); | 130 StartMergeSession(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void OAuth2LoginVerifier::OnUberAuthTokenFailure( | 133 void OAuth2LoginVerifier::OnUberAuthTokenFailure( |
| 134 const GoogleServiceAuthError& error) { | 134 const GoogleServiceAuthError& error) { |
| 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 135 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 136 LOG(WARNING) << "OAuthLogin(uber_token) failed," | 136 LOG(WARNING) << "OAuthLogin(uber_token) failed," |
| 137 << " error: " << error.state(); | 137 << " error: " << error.state(); |
| 138 RetryOnError("OAuthLoginUberToken", error, | 138 RetryOnError("OAuthLoginUberToken", error, |
| 139 base::Bind(&OAuth2LoginVerifier::StartOAuthLoginForUberToken, | 139 base::Bind(&OAuth2LoginVerifier::StartOAuthLoginForUberToken, |
| 140 AsWeakPtr()), | 140 AsWeakPtr()), |
| 141 base::Bind(&Delegate::OnSessionMergeFailure, | 141 base::Bind(&Delegate::OnSessionMergeFailure, |
| 142 base::Unretained(delegate_))); | 142 base::Unretained(delegate_))); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void OAuth2LoginVerifier::StartMergeSession() { | 145 void OAuth2LoginVerifier::StartMergeSession() { |
| 146 DCHECK(!gaia_token_.empty()); | 146 DCHECK(!gaia_token_.empty()); |
| 147 gaia_fetcher_.reset( | 147 gaia_fetcher_.reset( |
| 148 new GaiaAuthFetcher(this, | 148 new GaiaAuthFetcher(this, |
| 149 std::string(GaiaConstants::kChromeOSSource), | 149 std::string(GaiaConstants::kChromeOSSource), |
| 150 user_request_context_.get())); | 150 user_request_context_.get())); |
| 151 gaia_fetcher_->StartMergeSession(gaia_token_, std::string()); | 151 gaia_fetcher_->StartMergeSession(gaia_token_, std::string()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void OAuth2LoginVerifier::OnMergeSessionSuccess(const std::string& data) { | 154 void OAuth2LoginVerifier::OnMergeSessionSuccess(const std::string& data) { |
| 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 156 VLOG(1) << "MergeSession successful."; | 156 VLOG(1) << "MergeSession successful."; |
| 157 delegate_->OnSessionMergeSuccess(); | 157 delegate_->OnSessionMergeSuccess(); |
| 158 // Schedule post-merge verification to analyze how many LSID/SID overruns | 158 // Schedule post-merge verification to analyze how many LSID/SID overruns |
| 159 // were created by the session restore. | 159 // were created by the session restore. |
| 160 SchedulePostMergeVerification(); | 160 SchedulePostMergeVerification(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void OAuth2LoginVerifier::SchedulePostMergeVerification() { | 163 void OAuth2LoginVerifier::SchedulePostMergeVerification() { |
| 164 BrowserThread::PostDelayedTask( | 164 BrowserThread::PostDelayedTask( |
| 165 BrowserThread::UI, | 165 BrowserThread::UI, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 VLOG(1) << "Got OAuth2 access token!"; | 201 VLOG(1) << "Got OAuth2 access token!"; |
| 202 retry_count_ = 0; | 202 retry_count_ = 0; |
| 203 access_token_ = access_token; | 203 access_token_ = access_token; |
| 204 StartOAuthLoginForUberToken(); | 204 StartOAuthLoginForUberToken(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void OAuth2LoginVerifier::OnGetTokenFailure( | 207 void OAuth2LoginVerifier::OnGetTokenFailure( |
| 208 const OAuth2TokenService::Request* request, | 208 const OAuth2TokenService::Request* request, |
| 209 const GoogleServiceAuthError& error) { | 209 const GoogleServiceAuthError& error) { |
| 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 210 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 211 DCHECK_EQ(login_token_request_.get(), request); | 211 DCHECK_EQ(login_token_request_.get(), request); |
| 212 login_token_request_.reset(); | 212 login_token_request_.reset(); |
| 213 | 213 |
| 214 LOG(WARNING) << "Failed to get OAuth2 access token, " | 214 LOG(WARNING) << "Failed to get OAuth2 access token, " |
| 215 << " error: " << error.state(); | 215 << " error: " << error.state(); |
| 216 UMA_HISTOGRAM_ENUMERATION( | 216 UMA_HISTOGRAM_ENUMERATION( |
| 217 base::StringPrintf("OAuth2Login.%sFailure", "GetOAuth2AccessToken"), | 217 base::StringPrintf("OAuth2Login.%sFailure", "GetOAuth2AccessToken"), |
| 218 error.state(), | 218 error.state(), |
| 219 GoogleServiceAuthError::NUM_STATES); | 219 GoogleServiceAuthError::NUM_STATES); |
| 220 delegate_->OnSessionMergeFailure(IsConnectionOrServiceError(error)); | 220 delegate_->OnSessionMergeFailure(IsConnectionOrServiceError(error)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void OAuth2LoginVerifier::OnListAccountsSuccess( | 223 void OAuth2LoginVerifier::OnListAccountsSuccess( |
| 224 const std::string& data) { | 224 const std::string& data) { |
| 225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 225 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 226 VLOG(1) << "ListAccounts successful."; | 226 VLOG(1) << "ListAccounts successful."; |
| 227 delegate_->OnListAccountsSuccess(data); | 227 delegate_->OnListAccountsSuccess(data); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void OAuth2LoginVerifier::OnListAccountsFailure( | 230 void OAuth2LoginVerifier::OnListAccountsFailure( |
| 231 const GoogleServiceAuthError& error) { | 231 const GoogleServiceAuthError& error) { |
| 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 233 LOG(WARNING) << "Failed to get list of session accounts, " | 233 LOG(WARNING) << "Failed to get list of session accounts, " |
| 234 << " error: " << error.state(); | 234 << " error: " << error.state(); |
| 235 RetryOnError( | 235 RetryOnError( |
| 236 "ListAccounts", | 236 "ListAccounts", |
| 237 error, | 237 error, |
| 238 base::Bind(&OAuth2LoginVerifier::StartAuthCookiesVerification, | 238 base::Bind(&OAuth2LoginVerifier::StartAuthCookiesVerification, |
| 239 AsWeakPtr()), | 239 AsWeakPtr()), |
| 240 base::Bind(&Delegate::OnListAccountsFailure, | 240 base::Bind(&Delegate::OnListAccountsFailure, |
| 241 base::Unretained(delegate_))); | 241 base::Unretained(delegate_))); |
| 242 } | 242 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 262 << operation_id; | 262 << operation_id; |
| 263 UMA_HISTOGRAM_ENUMERATION( | 263 UMA_HISTOGRAM_ENUMERATION( |
| 264 base::StringPrintf("OAuth2Login.%sFailure", operation_id), | 264 base::StringPrintf("OAuth2Login.%sFailure", operation_id), |
| 265 error.state(), | 265 error.state(), |
| 266 GoogleServiceAuthError::NUM_STATES); | 266 GoogleServiceAuthError::NUM_STATES); |
| 267 | 267 |
| 268 error_handler.Run(IsConnectionOrServiceError(error)); | 268 error_handler.Run(IsConnectionOrServiceError(error)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 } // namespace chromeos | 271 } // namespace chromeos |
| OLD | NEW |