Chromium Code Reviews| Index: chrome/browser/profiles/profile_downloader.cc |
| diff --git a/chrome/browser/profiles/profile_downloader.cc b/chrome/browser/profiles/profile_downloader.cc |
| index 15e8ceef496f45cb3a092c4c16b27a61c899b0d7..d4685fe50d7689b0b90818c98c7bc015af4acaeb 100644 |
| --- a/chrome/browser/profiles/profile_downloader.cc |
| +++ b/chrome/browser/profiles/profile_downloader.cc |
| @@ -47,15 +47,15 @@ const char kUserEntryURL[] = |
| const char kAPIScope[] = "https://www.googleapis.com/auth/userinfo.profile"; |
| // Path in JSON dictionary to user's photo thumbnail URL. |
| -const char kPhotoThumbnailURLPath[] = "picture"; |
| +const char kPhotoThumbnailURLPath[] = "image.url"; |
| // From the user info API, this field corresponds to the full name of the user. |
| -const char kFullNamePath[] = "name"; |
| +const char kFullNamePath[] = "displayName"; |
| -const char kGivenNamePath[] = "given_name"; |
| +const char kGivenNamePath[] = "name.givenName"; |
| // Path in JSON dictionary to user's preferred locale. |
| -const char kLocalePath[] = "locale"; |
| +const char kLocalePath[] = "language"; |
| // Path format for specifying thumbnail's size. |
| const char kThumbnailSizeFormat[] = "s%d-c"; |
| @@ -133,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(const std::string& data, |
| +bool ProfileDownloader::ParseProfileJSON(base::DictionaryValue* root_dictionary, |
| base::string16* full_name, |
| base::string16* given_name, |
| std::string* url, |
| @@ -149,23 +149,6 @@ bool ProfileDownloader::ParseProfileJSON(const std::string& data, |
| *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); |
| @@ -274,17 +257,9 @@ std::string ProfileDownloader::GetProfilePictureURL() const { |
| void ProfileDownloader::StartFetchingImage() { |
| VLOG(1) << "Fetching user entry with token: " << auth_token_; |
| - 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())); |
|
noms (inactive)
2014/04/25 17:07:40
So here we check whether the token is empty, and a
Roger Tawa OOO till Jul 10th
2014/04/28 20:44:12
Yup. In fact, this can't work with an empty token
|
| - } |
| - user_entry_fetcher_->Start(); |
| + gaia_client_.reset(new gaia::GaiaOAuthClient( |
| + delegate_->GetBrowserProfile()->GetRequestContext())); |
| + gaia_client_->GetUserInfo(auth_token_, 0, this); |
| } |
| void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
| @@ -307,27 +282,10 @@ ProfileDownloader::~ProfileDownloader() { |
| service->RemoveObserver(this); |
| } |
| -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()) { |
| +void ProfileDownloader::OnGetUserInfoResponse( |
| + scoped_ptr<base::DictionaryValue> user_info) { |
| std::string image_url; |
| - if (!ParseProfileJSON(data, |
| + if (!ParseProfileJSON(user_info.get(), |
| &profile_full_name_, |
| &profile_given_name_, |
| &image_url, |
| @@ -367,14 +325,45 @@ void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
| base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| } |
| profile_image_fetcher_->Start(); |
| - } 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); |
| +} |
| + |
| +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; |
| } |
| + |
| + 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, |