Chromium Code Reviews| Index: google_apis/gaia/gaia_oauth_client.cc |
| diff --git a/google_apis/gaia/gaia_oauth_client.cc b/google_apis/gaia/gaia_oauth_client.cc |
| index 1113ff6730921c86dd0a4255c9112b37d2837423..153e0cf0c0d152dfa2830b2cc6bbd82d49c24561 100644 |
| --- a/google_apis/gaia/gaia_oauth_client.cc |
| +++ b/google_apis/gaia/gaia_oauth_client.cc |
| @@ -56,6 +56,9 @@ class GaiaOAuthClient::Core |
| void GetUserId(const std::string& oauth_access_token, |
| int max_retries, |
| Delegate* delegate); |
| + void GetUserInfo(const std::string& oauth_access_token, |
| + int max_retries, |
| + Delegate* delegate); |
| void GetTokenInfo(const std::string& oauth_access_token, |
| int max_retries, |
| Delegate* delegate); |
| @@ -73,13 +76,14 @@ class GaiaOAuthClient::Core |
| TOKEN_INFO, |
| USER_EMAIL, |
| USER_ID, |
| + USER_INFO |
|
noms (inactive)
2014/04/25 17:07:40
nit: I think the last enum should end in a trailin
Roger Tawa OOO till Jul 10th
2014/04/28 20:44:12
Done.
|
| }; |
| virtual ~Core() {} |
| - void GetUserInfo(const std::string& oauth_access_token, |
| - int max_retries, |
| - Delegate* delegate); |
| + void PeopleGet(const std::string& oauth_access_token, |
| + int max_retries, |
| + Delegate* delegate); |
| void MakeGaiaRequest(const GURL& url, |
| const std::string& post_body, |
| int max_retries, |
| @@ -145,7 +149,7 @@ void GaiaOAuthClient::Core::GetUserEmail(const std::string& oauth_access_token, |
| DCHECK_EQ(request_type_, NO_PENDING_REQUEST); |
| DCHECK(!request_.get()); |
| request_type_ = USER_EMAIL; |
| - GetUserInfo(oauth_access_token, max_retries, delegate); |
| + PeopleGet(oauth_access_token, max_retries, delegate); |
| } |
| void GaiaOAuthClient::Core::GetUserId(const std::string& oauth_access_token, |
| @@ -154,16 +158,25 @@ void GaiaOAuthClient::Core::GetUserId(const std::string& oauth_access_token, |
| DCHECK_EQ(request_type_, NO_PENDING_REQUEST); |
| DCHECK(!request_.get()); |
| request_type_ = USER_ID; |
| - GetUserInfo(oauth_access_token, max_retries, delegate); |
| + PeopleGet(oauth_access_token, max_retries, delegate); |
| } |
| void GaiaOAuthClient::Core::GetUserInfo(const std::string& oauth_access_token, |
| int max_retries, |
| Delegate* delegate) { |
| + DCHECK_EQ(request_type_, NO_PENDING_REQUEST); |
| + DCHECK(!request_.get()); |
| + request_type_ = USER_INFO; |
| + PeopleGet(oauth_access_token, max_retries, delegate); |
| +} |
| + |
| +void GaiaOAuthClient::Core::PeopleGet(const std::string& oauth_access_token, |
| + int max_retries, |
| + Delegate* delegate) { |
| delegate_ = delegate; |
| num_retries_ = 0; |
| request_.reset(net::URLFetcher::Create( |
| - kUrlFetcherId, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()), |
| + kUrlFetcherId, GURL(GaiaUrls::GetInstance()->people_get_url()), |
| net::URLFetcher::GET, this)); |
| request_->SetRequestContext(request_context_getter_.get()); |
| request_->AddExtraRequestHeader("Authorization: OAuth " + oauth_access_token); |
| @@ -282,9 +295,22 @@ void GaiaOAuthClient::Core::HandleResponse( |
| switch (type) { |
| case USER_EMAIL: { |
| - std::string email; |
| - response_dict->GetString("email", &email); |
| - delegate_->OnGetUserEmailResponse(email); |
| + const base::ListValue* emails_list; |
| + if (response_dict->GetList("emails", &emails_list)) { |
|
noms (inactive)
2014/04/25 17:07:40
nit: please add a comment. this looks scary :)
Roger Tawa OOO till Jul 10th
2014/04/28 20:44:12
Added comment, but also forgotten error case.
|
| + for (size_t i = 0; i < emails_list->GetSize(); ++i) { |
| + const base::DictionaryValue* email_dict; |
| + if (emails_list->GetDictionary(i, &email_dict)) { |
| + std::string email; |
| + std::string type; |
| + if (email_dict->GetString("type", &type) && |
| + type == "account" && |
| + email_dict->GetString("value", &email)) { |
| + delegate_->OnGetUserEmailResponse(email); |
| + break; |
| + } |
| + } |
| + } |
| + } |
| break; |
| } |
| @@ -295,6 +321,11 @@ void GaiaOAuthClient::Core::HandleResponse( |
| break; |
| } |
| + case USER_INFO: { |
| + delegate_->OnGetUserInfoResponse(response_dict.Pass()); |
| + break; |
| + } |
| + |
| case TOKEN_INFO: { |
| delegate_->OnGetTokenInfoResponse(response_dict.Pass()); |
| break; |
| @@ -372,6 +403,12 @@ void GaiaOAuthClient::GetUserId(const std::string& access_token, |
| return core_->GetUserId(access_token, max_retries, delegate); |
| } |
| +void GaiaOAuthClient::GetUserInfo(const std::string& access_token, |
| + int max_retries, |
|
noms (inactive)
2014/04/25 17:07:40
nit: wrong indentation
Roger Tawa OOO till Jul 10th
2014/04/28 20:44:12
Done.
|
| + Delegate* delegate) { |
| + return core_->GetUserInfo(access_token, max_retries, delegate); |
| +} |
| + |
| void GaiaOAuthClient::GetTokenInfo(const std::string& access_token, |
| int max_retries, |
| Delegate* delegate) { |