diff options
author | machenbach@chromium.org <machenbach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 07:18:20 +0000 |
---|---|---|
committer | machenbach@chromium.org <machenbach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 07:18:20 +0000 |
commit | 31000efe5883fb405cdba88707ff3836424eb1ec (patch) | |
tree | 862775896475b60455cc5287cb19835f08fb5cf6 /chrome/browser/profiles/profile_downloader.cc | |
parent | 87e9992419dd6218e99fe22590bafb2a584d96f4 (diff) | |
download | chromium_src-31000efe5883fb405cdba88707ff3836424eb1ec.zip chromium_src-31000efe5883fb405cdba88707ff3836424eb1ec.tar.gz chromium_src-31000efe5883fb405cdba88707ff3836424eb1ec.tar.bz2 |
Revert of Use new people.get api instead of oauth2/v1/userinfo. (https://codereview.chromium.org/257773002/)
Reason for revert:
[Sheriff]Speculative revert for breaking CrOS:
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%282%29/builds/23489
Will reland if it doesn't help.
Original issue's description:
> Use new people.get api instead of oauth2/v1/userinfo.
> Consolidate all uses into main helper class.
>
> Details about new api: https://developers.google.com/+/api/latest/people/get
>
> Format of returned response: https://developers.google.com/+/api/latest/people#resource
>
> BUG=320354
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=267068
TBR=atwilson@chromium.org,noms@chromium.org,guohui@chromium.org,gene@chromium.org,rogerta@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=320354
Review URL: https://codereview.chromium.org/265563002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267114 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles/profile_downloader.cc')
-rw-r--r-- | chrome/browser/profiles/profile_downloader.cc | 120 |
1 files changed, 69 insertions, 51 deletions
diff --git a/chrome/browser/profiles/profile_downloader.cc b/chrome/browser/profiles/profile_downloader.cc index 5d08ffe..15e8cee 100644 --- a/chrome/browser/profiles/profile_downloader.cc +++ b/chrome/browser/profiles/profile_downloader.cc @@ -38,16 +38,24 @@ namespace { const char kAuthorizationHeader[] = "Authorization: Bearer %s"; +// URL requesting user info. +const char kUserEntryURL[] = + "https://www.googleapis.com/oauth2/v1/userinfo?alt=json"; + +// OAuth scope for the user info API. +// For more info, see https://developers.google.com/accounts/docs/OAuth2LoginV1. +const char kAPIScope[] = "https://www.googleapis.com/auth/userinfo.profile"; + // Path in JSON dictionary to user's photo thumbnail URL. -const char kPhotoThumbnailURLPath[] = "image.url"; +const char kPhotoThumbnailURLPath[] = "picture"; // From the user info API, this field corresponds to the full name of the user. -const char kFullNamePath[] = "displayName"; +const char kFullNamePath[] = "name"; -const char kGivenNamePath[] = "name.givenName"; +const char kGivenNamePath[] = "given_name"; // Path in JSON dictionary to user's preferred locale. -const char kLocalePath[] = "language"; +const char kLocalePath[] = "locale"; // Path format for specifying thumbnail's size. const char kThumbnailSizeFormat[] = "s%d-c"; @@ -125,7 +133,7 @@ bool GetImageURLWithSize(const GURL& old_url, int size, GURL* new_url) { // Parses the entry response and gets the name and profile image URL. // |data| should be the JSON formatted data return by the response. // Returns false to indicate a parsing error. -bool ProfileDownloader::ParseProfileJSON(base::DictionaryValue* root_dictionary, +bool ProfileDownloader::ParseProfileJSON(const std::string& data, base::string16* full_name, base::string16* given_name, std::string* url, @@ -141,6 +149,23 @@ bool ProfileDownloader::ParseProfileJSON(base::DictionaryValue* root_dictionary, *url = std::string(); *profile_locale = std::string(); + int error_code = -1; + std::string error_message; + scoped_ptr<base::Value> root_value(base::JSONReader::ReadAndReturnError( + data, base::JSON_PARSE_RFC, &error_code, &error_message)); + if (!root_value) { + LOG(ERROR) << "Error while parsing user entry response: " + << error_message; + return false; + } + if (!root_value->IsType(base::Value::TYPE_DICTIONARY)) { + LOG(ERROR) << "JSON root is not a dictionary: " + << root_value->GetType(); + return false; + } + base::DictionaryValue* root_dictionary = + static_cast<base::DictionaryValue*>(root_value.get()); + root_dictionary->GetString(kFullNamePath, full_name); root_dictionary->GetString(kGivenNamePath, given_name); root_dictionary->GetString(kLocalePath, profile_locale); @@ -248,17 +273,24 @@ std::string ProfileDownloader::GetProfilePictureURL() const { } void ProfileDownloader::StartFetchingImage() { - DCHECK(!auth_token_.empty()); VLOG(1) << "Fetching user entry with token: " << auth_token_; - gaia_client_.reset(new gaia::GaiaOAuthClient( - delegate_->GetBrowserProfile()->GetRequestContext())); - gaia_client_->GetUserInfo(auth_token_, 0, this); + user_entry_fetcher_.reset(net::URLFetcher::Create( + GURL(kUserEntryURL), net::URLFetcher::GET, this)); + user_entry_fetcher_->SetRequestContext( + delegate_->GetBrowserProfile()->GetRequestContext()); + user_entry_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | + net::LOAD_DO_NOT_SAVE_COOKIES); + if (!auth_token_.empty()) { + user_entry_fetcher_->SetExtraRequestHeaders( + base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); + } + user_entry_fetcher_->Start(); } void ProfileDownloader::StartFetchingOAuth2AccessToken() { Profile* profile = delegate_->GetBrowserProfile(); OAuth2TokenService::ScopeSet scopes; - scopes.insert(GaiaConstants::kGoogleUserInfoProfile); + scopes.insert(kAPIScope); ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile); oauth2_access_token_request_ = token_service->StartRequest( @@ -275,10 +307,27 @@ ProfileDownloader::~ProfileDownloader() { service->RemoveObserver(this); } -void ProfileDownloader::OnGetUserInfoResponse( - scoped_ptr<base::DictionaryValue> user_info) { +void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + std::string data; + source->GetResponseAsString(&data); + bool network_error = + source->GetStatus().status() != net::URLRequestStatus::SUCCESS; + if (network_error || source->GetResponseCode() != 200) { + LOG(WARNING) << "Fetching profile data failed"; + DVLOG(1) << " Status: " << source->GetStatus().status(); + DVLOG(1) << " Error: " << source->GetStatus().error(); + DVLOG(1) << " Response code: " << source->GetResponseCode(); + DVLOG(1) << " Url: " << source->GetURL().spec(); + delegate_->OnProfileDownloadFailure(this, network_error ? + ProfileDownloaderDelegate::NETWORK_ERROR : + ProfileDownloaderDelegate::SERVICE_ERROR); + return; + } + + if (source == user_entry_fetcher_.get()) { std::string image_url; - if (!ParseProfileJSON(user_info.get(), + if (!ParseProfileJSON(data, &profile_full_name_, &profile_given_name_, &image_url, @@ -318,45 +367,14 @@ void ProfileDownloader::OnGetUserInfoResponse( base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); } profile_image_fetcher_->Start(); -} - -void ProfileDownloader::OnOAuthError() { - LOG(WARNING) << "OnOAuthError: Fetching profile data failed"; - delegate_->OnProfileDownloadFailure( - this, ProfileDownloaderDelegate::SERVICE_ERROR); -} - -void ProfileDownloader::OnNetworkError(int response_code) { - LOG(WARNING) << "OnNetworkError: Fetching profile data failed"; - DVLOG(1) << " Response code: " << response_code; - delegate_->OnProfileDownloadFailure( - this, ProfileDownloaderDelegate::NETWORK_ERROR); -} - -void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::string data; - source->GetResponseAsString(&data); - bool network_error = - source->GetStatus().status() != net::URLRequestStatus::SUCCESS; - if (network_error || source->GetResponseCode() != 200) { - LOG(WARNING) << "Fetching profile data failed"; - DVLOG(1) << " Status: " << source->GetStatus().status(); - DVLOG(1) << " Error: " << source->GetStatus().error(); - DVLOG(1) << " Response code: " << source->GetResponseCode(); - DVLOG(1) << " Url: " << source->GetURL().spec(); - delegate_->OnProfileDownloadFailure(this, network_error ? - ProfileDownloaderDelegate::NETWORK_ERROR : - ProfileDownloaderDelegate::SERVICE_ERROR); - return; + } else if (source == profile_image_fetcher_.get()) { + VLOG(1) << "Decoding the image..."; + scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( + this, data, ImageDecoder::DEFAULT_CODEC); + scoped_refptr<base::MessageLoopProxy> task_runner = + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); + image_decoder->Start(task_runner); } - - VLOG(1) << "Decoding the image..."; - scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( - this, data, ImageDecoder::DEFAULT_CODEC); - scoped_refptr<base::MessageLoopProxy> task_runner = - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); - image_decoder->Start(task_runner); } void ProfileDownloader::OnImageDecoded(const ImageDecoder* decoder, |