Index: chrome/common/net/gaia/gaia_auth_fetcher.cc |
diff --git a/chrome/common/net/gaia/gaia_auth_fetcher.cc b/chrome/common/net/gaia/gaia_auth_fetcher.cc |
index 522c7d96c4ef94dc0c8519bc024009d05d5b12da..3c277f21229dfb602a3225e65be7a59b2122d4c9 100644 |
--- a/chrome/common/net/gaia/gaia_auth_fetcher.cc |
+++ b/chrome/common/net/gaia/gaia_auth_fetcher.cc |
@@ -94,27 +94,15 @@ const char GaiaAuthFetcher::kGetUserInfoUrl[] = |
"https://www.google.com/accounts/GetUserInfo"; |
GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer, |
- const std::string& source, |
- net::URLRequestContextGetter* getter) |
- : consumer_(consumer), |
- getter_(getter), |
- source_(source), |
+ const std::string& source, |
+ net::URLRequestContextGetter* getter) |
+ : AuthenticationFetcher(consumer, source, getter), |
client_login_gurl_(kClientLoginUrl), |
issue_auth_token_gurl_(kIssueAuthTokenUrl), |
- get_user_info_gurl_(kGetUserInfoUrl), |
- fetch_pending_(false) {} |
+ get_user_info_gurl_(kGetUserInfoUrl) {} |
GaiaAuthFetcher::~GaiaAuthFetcher() {} |
-bool GaiaAuthFetcher::HasPendingFetch() { |
- return fetch_pending_; |
-} |
- |
-void GaiaAuthFetcher::CancelRequest() { |
- fetcher_.reset(); |
- fetch_pending_ = false; |
-} |
- |
// static |
URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( |
net::URLRequestContextGetter* getter, |
@@ -175,11 +163,12 @@ std::string GaiaAuthFetcher::MakeClientLoginBody( |
// static |
std::string GaiaAuthFetcher::MakeIssueAuthTokenBody( |
- const std::string& sid, |
- const std::string& lsid, |
+ const AuthenticationConsumer::AuthenticationResult& credentials, |
const char* const service) { |
- std::string encoded_sid = UrlEncodeString(sid); |
- std::string encoded_lsid = UrlEncodeString(lsid); |
+ const GaiaAuthConsumer::ClientLoginResult& cred = |
+ static_cast<const GaiaAuthConsumer::ClientLoginResult&>(credentials); |
+ std::string encoded_sid = UrlEncodeString(cred.sid); |
+ std::string encoded_lsid = UrlEncodeString(cred.lsid); |
// All tokens should be session tokens except the gaia auth token. |
bool session = true; |
@@ -249,6 +238,18 @@ void GaiaAuthFetcher::ParseClientLoginFailure(const std::string& data, |
} |
} |
+// virtual |
+void GaiaAuthFetcher::StartAuthentication( |
+ const std::string& username, |
+ const std::string& password, |
+ const char* const service, |
+ const std::string& login_token, |
+ const std::string& login_captcha, |
+ HostedAccountsSetting allow_hosted_accounts) { |
+ StartClientLogin(username, password, service, login_token, login_captcha, |
+ allow_hosted_accounts); |
+} |
+ |
void GaiaAuthFetcher::StartClientLogin( |
const std::string& username, |
const std::string& password, |
@@ -257,7 +258,7 @@ void GaiaAuthFetcher::StartClientLogin( |
const std::string& login_captcha, |
HostedAccountsSetting allow_hosted_accounts) { |
- DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
+ DCHECK(!HasPendingFetch()) << "Tried to fetch two things at once!"; |
// This class is thread agnostic, so be sure to call this only on the |
// same thread each time. |
@@ -275,30 +276,30 @@ void GaiaAuthFetcher::StartClientLogin( |
request_body_, |
client_login_gurl_, |
this)); |
- fetch_pending_ = true; |
+ SetPending(); |
fetcher_->Start(); |
} |
-void GaiaAuthFetcher::StartIssueAuthToken(const std::string& sid, |
- const std::string& lsid, |
- const char* const service) { |
+void GaiaAuthFetcher::StartIssueAuthToken( |
+ const AuthenticationConsumer::AuthenticationResult& credentials, |
+ const char* const service) { |
- DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
+ DCHECK(!HasPendingFetch()) << "Tried to fetch two things at once!"; |
VLOG(1) << "Starting IssueAuthToken for: " << service; |
requested_service_ = service; |
- request_body_ = MakeIssueAuthTokenBody(sid, lsid, service); |
+ request_body_ = MakeIssueAuthTokenBody(credentials, service); |
fetcher_.reset(CreateGaiaFetcher(getter_, |
request_body_, |
issue_auth_token_gurl_, |
this)); |
- fetch_pending_ = true; |
+ SetPending(); |
fetcher_->Start(); |
} |
void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid, |
const std::string& info_key) { |
- DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
+ DCHECK(!HasPendingFetch()) << "Tried to fetch two things at once!"; |
VLOG(1) << "Starting GetUserInfo for lsid=" << lsid; |
request_body_ = MakeGetUserInfoBody(lsid); |
@@ -306,7 +307,7 @@ void GaiaAuthFetcher::StartGetUserInfo(const std::string& lsid, |
request_body_, |
get_user_info_gurl_, |
this)); |
- fetch_pending_ = true; |
+ SetPending(); |
requested_info_key_ = info_key; |
fetcher_->Start(); |
} |
@@ -364,6 +365,13 @@ GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError( |
return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
} |
+void GaiaAuthFetcher::OnAuthenticationFetched( |
+ const std::string& data, |
+ const net::URLRequestStatus& status, |
+ int response_code) { |
+ OnClientLoginFetched(data, status, response_code); |
+} |
+ |
void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data, |
const net::URLRequestStatus& status, |
int response_code) { |
@@ -374,10 +382,11 @@ void GaiaAuthFetcher::OnClientLoginFetched(const std::string& data, |
std::string lsid; |
std::string token; |
ParseClientLoginResponse(data, &sid, &lsid, &token); |
- consumer_->OnClientLoginSuccess( |
+ consumer_->OnAuthenticationSuccess( |
GaiaAuthConsumer::ClientLoginResult(sid, lsid, token, data)); |
} else { |
- consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); |
+ // consumer_->OnClientLoginFailure(GenerateAuthError(data, status)); |
+ consumer_->OnAuthenticationFailure(GenerateAuthError(data, status)); |
} |
} |
@@ -388,13 +397,20 @@ void GaiaAuthFetcher::OnIssueAuthTokenFetched( |
if (status.is_success() && response_code == RC_REQUEST_OK) { |
// Only the bare token is returned in the body of this Gaia call |
// without any padding. |
- consumer_->OnIssueAuthTokenSuccess(requested_service_, data); |
+ consumer_->OnIssueTokenSuccess(requested_service_, data); |
} else { |
- consumer_->OnIssueAuthTokenFailure(requested_service_, |
+ consumer_->OnIssueTokenFailure(requested_service_, |
GenerateAuthError(data, status)); |
} |
} |
+// virtual |
+void GaiaAuthFetcher::OnIssueTokenFetched(const std::string& data, |
+ const net::URLRequestStatus& status, |
+ int response_code) { |
+ OnIssueAuthTokenFetched(data, status, response_code); |
+} |
+ |
void GaiaAuthFetcher::OnGetUserInfoFetched( |
const std::string& data, |
const net::URLRequestStatus& status, |
@@ -425,7 +441,7 @@ void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source, |
int response_code, |
const ResponseCookies& cookies, |
const std::string& data) { |
- fetch_pending_ = false; |
+ ClearPending(); |
if (url == client_login_gurl_) { |
OnClientLoginFetched(data, status, response_code); |
} else if (url == issue_auth_token_gurl_) { |