Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2367)

Unified Diff: components/policy/core/common/cloud/user_info_fetcher.cc

Issue 257773002: Use new people.get api instead of oauth2/v1/userinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix user image manager tests Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/policy/core/common/cloud/user_info_fetcher.cc
diff --git a/components/policy/core/common/cloud/user_info_fetcher.cc b/components/policy/core/common/cloud/user_info_fetcher.cc
index b8f9f74df1828dd54975b6e71820b24fbb4146ca..978e4c81a0f1330cd1e9d8a846042c0c9e6c9aaf 100644
--- a/components/policy/core/common/cloud/user_info_fetcher.cc
+++ b/components/policy/core/common/cloud/user_info_fetcher.cc
@@ -16,23 +16,11 @@
#include "net/url_request/url_request_status.h"
#include "url/gurl.h"
-namespace {
-
-static const char kAuthorizationHeaderFormat[] =
- "Authorization: Bearer %s";
-
-static std::string MakeAuthorizationHeader(const std::string& auth_token) {
- return base::StringPrintf(kAuthorizationHeaderFormat, auth_token.c_str());
-}
-
-} // namespace
-
namespace policy {
UserInfoFetcher::UserInfoFetcher(Delegate* delegate,
net::URLRequestContextGetter* context)
- : delegate_(delegate),
- context_(context) {
+ : delegate_(delegate), gaia_client_(context) {
DCHECK(delegate);
}
@@ -41,49 +29,28 @@ UserInfoFetcher::~UserInfoFetcher() {
void UserInfoFetcher::Start(const std::string& access_token) {
// Create a URLFetcher and start it.
- url_fetcher_.reset(net::URLFetcher::Create(
- 0, GaiaUrls::GetInstance()->oauth_user_info_url(),
- net::URLFetcher::GET, this));
- url_fetcher_->SetRequestContext(context_);
- url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
- net::LOAD_DO_NOT_SAVE_COOKIES);
- url_fetcher_->AddExtraRequestHeader(MakeAuthorizationHeader(access_token));
- url_fetcher_->Start(); // Results in a call to OnURLFetchComplete().
+ gaia_client_.GetUserInfo(access_token, 0, &delegate_);
}
-void UserInfoFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
- net::URLRequestStatus status = source->GetStatus();
- GoogleServiceAuthError error = GoogleServiceAuthError::AuthErrorNone();
- if (!status.is_success()) {
- if (status.status() == net::URLRequestStatus::CANCELED)
- error = GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED);
- else
- error = GoogleServiceAuthError::FromConnectionError(status.error());
- } else if (source->GetResponseCode() != net::HTTP_OK) {
- DLOG(WARNING) << "UserInfo request failed with HTTP code: "
- << source->GetResponseCode();
- error = GoogleServiceAuthError(
- GoogleServiceAuthError::CONNECTION_FAILED);
- }
- if (error.state() != GoogleServiceAuthError::NONE) {
- delegate_->OnGetUserInfoFailure(error);
- return;
- }
+UserInfoFetcher::GaiaDelegate::GaiaDelegate(UserInfoFetcher::Delegate* delegate)
+ : delegate_(delegate) {
+}
+
+void UserInfoFetcher::GaiaDelegate::OnGetUserInfoResponse(
+ scoped_ptr<base::DictionaryValue> user_info) {
+ delegate_->OnGetUserInfoSuccess(user_info.get());
+}
+
+void UserInfoFetcher::GaiaDelegate::OnOAuthError() {
+ GoogleServiceAuthError error =
+ GoogleServiceAuthError(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
+ delegate_->OnGetUserInfoFailure(error);
+}
- // Successfully fetched userinfo from the server - parse it and hand it off
- // to the delegate.
- std::string unparsed_data;
- source->GetResponseAsString(&unparsed_data);
- DVLOG(1) << "Received UserInfo response: " << unparsed_data;
- scoped_ptr<base::Value> parsed_value(base::JSONReader::Read(unparsed_data));
- base::DictionaryValue* dict;
- if (parsed_value.get() && parsed_value->GetAsDictionary(&dict)) {
- delegate_->OnGetUserInfoSuccess(dict);
- } else {
- NOTREACHED() << "Could not parse userinfo response from server";
- delegate_->OnGetUserInfoFailure(GoogleServiceAuthError(
- GoogleServiceAuthError::CONNECTION_FAILED));
- }
+void UserInfoFetcher::GaiaDelegate::OnNetworkError(int response_code) {
+ GoogleServiceAuthError error =
+ GoogleServiceAuthError::FromConnectionError(response_code);
+ delegate_->OnGetUserInfoFailure(error);
}
}; // namespace policy

Powered by Google App Engine
This is Rietveld 408576698