| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/profiles/profile_downloader.h" | 5 #include "chrome/browser/profiles/profile_downloader.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_downloader_delegate.h" | 19 #include "chrome/browser/profiles/profile_downloader_delegate.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 22 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 24 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 25 #include "components/signin/core/browser/signin_client.h" |
| 23 #include "components/signin/core/browser/signin_manager.h" | 26 #include "components/signin/core/browser/signin_manager.h" |
| 24 #include "components/signin/core/common/profile_management_switches.h" | 27 #include "components/signin/core/common/profile_management_switches.h" |
| 25 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 26 #include "google_apis/gaia/gaia_constants.h" | 29 #include "google_apis/gaia/gaia_constants.h" |
| 27 #include "google_apis/gaia/gaia_urls.h" | |
| 28 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
| 29 #include "net/url_request/url_fetcher.h" | 31 #include "net/url_request/url_fetcher.h" |
| 30 #include "net/url_request/url_request_status.h" | 32 #include "net/url_request/url_request_status.h" |
| 31 #include "skia/ext/image_operations.h" | 33 #include "skia/ext/image_operations.h" |
| 32 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 33 | 35 |
| 34 using content::BrowserThread; | 36 using content::BrowserThread; |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 // Template for optional authorization header when using an OAuth access token. | 40 // Template for optional authorization header when using an OAuth access token. |
| 39 const char kAuthorizationHeader[] = | 41 const char kAuthorizationHeader[] = |
| 40 "Authorization: Bearer %s"; | 42 "Authorization: Bearer %s"; |
| 41 | 43 |
| 42 // Path in JSON dictionary to user's photo thumbnail URL. | |
| 43 const char kPhotoThumbnailURLPath[] = "picture"; | |
| 44 | |
| 45 // Path in JSON dictionary to user's hosted domain. | |
| 46 const char kHostedDomainPath[] = "hd"; | |
| 47 | |
| 48 // From the user info API, this field corresponds to the full name of the user. | |
| 49 const char kFullNamePath[] = "name"; | |
| 50 | |
| 51 const char kGivenNamePath[] = "given_name"; | |
| 52 | |
| 53 // Path in JSON dictionary to user's preferred locale. | |
| 54 const char kLocalePath[] = "locale"; | |
| 55 | |
| 56 // Path format for specifying thumbnail's size. | 44 // Path format for specifying thumbnail's size. |
| 57 const char kThumbnailSizeFormat[] = "s%d-c"; | 45 const char kThumbnailSizeFormat[] = "s%d-c"; |
| 58 // Default thumbnail size. | 46 // Default thumbnail size. |
| 59 const int kDefaultThumbnailSize = 64; | 47 const int kDefaultThumbnailSize = 64; |
| 60 | 48 |
| 61 // Separator of URL path components. | 49 // Separator of URL path components. |
| 62 const char kURLPathSeparator = '/'; | 50 const char kURLPathSeparator = '/'; |
| 63 | 51 |
| 64 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). | 52 // Photo ID of the Picasa Web Albums profile picture (base64 of 0). |
| 65 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; | 53 const char kPicasaPhotoId[] = "AAAAAAAAAAA"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 return new_url->is_valid(); | 107 return new_url->is_valid(); |
| 120 } | 108 } |
| 121 | 109 |
| 122 // We can't set the image size, just use the default size. | 110 // We can't set the image size, just use the default size. |
| 123 *new_url = old_url; | 111 *new_url = old_url; |
| 124 return true; | 112 return true; |
| 125 } | 113 } |
| 126 | 114 |
| 127 } // namespace | 115 } // namespace |
| 128 | 116 |
| 129 // Parses the entry response and gets the name and profile image URL. | |
| 130 // |data| should be the JSON formatted data return by the response. | |
| 131 // Returns false to indicate a parsing error. | |
| 132 bool ProfileDownloader::ParseProfileJSON(base::DictionaryValue* root_dictionary, | |
| 133 base::string16* full_name, | |
| 134 base::string16* given_name, | |
| 135 std::string* url, | |
| 136 int image_size, | |
| 137 std::string* profile_locale, | |
| 138 base::string16* hosted_domain) { | |
| 139 DCHECK(full_name); | |
| 140 DCHECK(given_name); | |
| 141 DCHECK(url); | |
| 142 DCHECK(profile_locale); | |
| 143 DCHECK(hosted_domain); | |
| 144 | |
| 145 *full_name = base::string16(); | |
| 146 *given_name = base::string16(); | |
| 147 *url = std::string(); | |
| 148 *profile_locale = std::string(); | |
| 149 *hosted_domain = base::string16(); | |
| 150 | |
| 151 root_dictionary->GetString(kFullNamePath, full_name); | |
| 152 root_dictionary->GetString(kGivenNamePath, given_name); | |
| 153 root_dictionary->GetString(kLocalePath, profile_locale); | |
| 154 root_dictionary->GetString(kHostedDomainPath, hosted_domain); | |
| 155 | |
| 156 std::string url_string; | |
| 157 if (root_dictionary->GetString(kPhotoThumbnailURLPath, &url_string)) { | |
| 158 GURL new_url; | |
| 159 if (!GetImageURLWithSize(GURL(url_string), image_size, &new_url)) { | |
| 160 LOG(ERROR) << "GetImageURLWithSize failed for url: " << url_string; | |
| 161 return false; | |
| 162 } | |
| 163 *url = new_url.spec(); | |
| 164 } | |
| 165 | |
| 166 // The profile data is considered valid as long as it has a name or a picture. | |
| 167 return !full_name->empty() || !url->empty(); | |
| 168 } | |
| 169 | |
| 170 // static | 117 // static |
| 171 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { | 118 bool ProfileDownloader::IsDefaultProfileImageURL(const std::string& url) { |
| 172 if (url.empty()) | 119 if (url.empty()) |
| 173 return true; | 120 return true; |
| 174 | 121 |
| 175 GURL image_url_object(url); | 122 GURL image_url_object(url); |
| 176 DCHECK(image_url_object.is_valid()); | 123 DCHECK(image_url_object.is_valid()); |
| 177 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); | 124 VLOG(1) << "URL to check for default image: " << image_url_object.spec(); |
| 178 std::vector<std::string> path_components; | 125 std::vector<std::string> path_components; |
| 179 base::SplitString(image_url_object.path(), | 126 base::SplitString(image_url_object.path(), |
| 180 kURLPathSeparator, | 127 kURLPathSeparator, |
| 181 &path_components); | 128 &path_components); |
| 182 | 129 |
| 183 if (path_components.size() < kProfileImageURLPathComponentsCount) | 130 if (path_components.size() < kProfileImageURLPathComponentsCount) |
| 184 return false; | 131 return false; |
| 185 | 132 |
| 186 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; | 133 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; |
| 187 const std::string& photo_version = | 134 const std::string& photo_version = |
| 188 path_components[kPhotoVersionPathComponentIndex]; | 135 path_components[kPhotoVersionPathComponentIndex]; |
| 189 | 136 |
| 190 // Check that the ID and version match the default Picasa profile photo. | 137 // Check that the ID and version match the default Picasa profile photo. |
| 191 return photo_id == kPicasaPhotoId && | 138 return photo_id == kPicasaPhotoId && |
| 192 photo_version == kDefaultPicasaPhotoVersion; | 139 photo_version == kDefaultPicasaPhotoVersion; |
| 193 } | 140 } |
| 194 | 141 |
| 195 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) | 142 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate, |
| 143 SigninClient* signin_client) |
| 196 : OAuth2TokenService::Consumer("profile_downloader"), | 144 : OAuth2TokenService::Consumer("profile_downloader"), |
| 197 delegate_(delegate), | 145 delegate_(delegate), |
| 198 picture_status_(PICTURE_FAILED) { | 146 picture_status_(PICTURE_FAILED), |
| 147 account_tracker_service_( |
| 148 AccountTrackerServiceFactory::GetForProfile( |
| 149 delegate_->GetBrowserProfile())), |
| 150 waiting_for_account_info_(false), |
| 151 signin_client_(signin_client) { |
| 199 DCHECK(delegate_); | 152 DCHECK(delegate_); |
| 153 account_tracker_service_->AddObserver(this); |
| 200 } | 154 } |
| 201 | 155 |
| 202 void ProfileDownloader::Start() { | 156 void ProfileDownloader::Start() { |
| 203 StartForAccount(std::string()); | 157 StartForAccount(std::string()); |
| 204 } | 158 } |
| 205 | 159 |
| 206 void ProfileDownloader::StartForAccount(const std::string& account_id) { | 160 void ProfileDownloader::StartForAccount(const std::string& account_id) { |
| 207 VLOG(1) << "Starting profile downloader..."; | 161 VLOG(1) << "Starting profile downloader..."; |
| 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 209 | 163 |
| 210 ProfileOAuth2TokenService* service = | 164 ProfileOAuth2TokenService* service = |
| 211 ProfileOAuth2TokenServiceFactory::GetForProfile( | 165 ProfileOAuth2TokenServiceFactory::GetForProfile( |
| 212 delegate_->GetBrowserProfile()); | 166 delegate_->GetBrowserProfile()); |
| 213 if (!service) { | 167 if (!service) { |
| 214 // This can happen in some test paths. | 168 // This can happen in some test paths. |
| 215 LOG(WARNING) << "User has no token service"; | 169 LOG(WARNING) << "User has no token service"; |
| 216 delegate_->OnProfileDownloadFailure( | 170 delegate_->OnProfileDownloadFailure( |
| 217 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 171 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
| 218 return; | 172 return; |
| 219 } | 173 } |
| 220 | 174 |
| 221 SigninManagerBase* signin_manager = | 175 SigninManagerBase* signin_manager = |
| 222 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile()); | 176 SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile()); |
| 223 account_id_ = | 177 account_id_ = |
| 224 account_id.empty() ? | 178 account_id.empty() ? |
| 225 signin_manager->GetAuthenticatedAccountId() : account_id; | 179 signin_manager->GetAuthenticatedAccountId() : account_id; |
| 226 if (service->RefreshTokenIsAvailable(account_id_)) { | 180 if (service->RefreshTokenIsAvailable(account_id_)) |
| 227 StartFetchingOAuth2AccessToken(); | 181 StartFetchingOAuth2AccessToken(); |
| 228 } else { | 182 else |
| 229 service->AddObserver(this); | 183 service->AddObserver(this); |
| 230 } | |
| 231 } | 184 } |
| 232 | 185 |
| 233 base::string16 ProfileDownloader::GetProfileHostedDomain() const { | 186 base::string16 ProfileDownloader::GetProfileHostedDomain() const { |
| 234 return profile_hosted_domain_; | 187 return base::UTF8ToUTF16(account_info_.hosted_domain); |
| 235 } | 188 } |
| 236 | 189 |
| 237 base::string16 ProfileDownloader::GetProfileFullName() const { | 190 base::string16 ProfileDownloader::GetProfileFullName() const { |
| 238 return profile_full_name_; | 191 return base::UTF8ToUTF16(account_info_.full_name); |
| 239 } | 192 } |
| 240 | 193 |
| 241 base::string16 ProfileDownloader::GetProfileGivenName() const { | 194 base::string16 ProfileDownloader::GetProfileGivenName() const { |
| 242 return profile_given_name_; | 195 return base::UTF8ToUTF16(account_info_.given_name); |
| 243 } | 196 } |
| 244 | 197 |
| 245 std::string ProfileDownloader::GetProfileLocale() const { | 198 std::string ProfileDownloader::GetProfileLocale() const { |
| 246 return profile_locale_; | 199 return account_info_.locale; |
| 247 } | 200 } |
| 248 | 201 |
| 249 SkBitmap ProfileDownloader::GetProfilePicture() const { | 202 SkBitmap ProfileDownloader::GetProfilePicture() const { |
| 250 return profile_picture_; | 203 return profile_picture_; |
| 251 } | 204 } |
| 252 | 205 |
| 253 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus() | 206 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus() |
| 254 const { | 207 const { |
| 255 return picture_status_; | 208 return picture_status_; |
| 256 } | 209 } |
| 257 | 210 |
| 258 std::string ProfileDownloader::GetProfilePictureURL() const { | 211 std::string ProfileDownloader::GetProfilePictureURL() const { |
| 259 return picture_url_; | 212 GURL url; |
| 213 if (GetImageURLWithSize(GURL(account_info_.picture_url), |
| 214 delegate_->GetDesiredImageSideLength(), |
| 215 &url)) { |
| 216 return url.spec(); |
| 217 } |
| 218 return account_info_.picture_url; |
| 260 } | 219 } |
| 261 | 220 |
| 262 void ProfileDownloader::StartFetchingImage() { | 221 void ProfileDownloader::StartFetchingImage() { |
| 263 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 222 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
| 264 gaia_client_.reset(new gaia::GaiaOAuthClient( | 223 account_info_ = account_tracker_service_->GetAccountInfo(account_id_); |
| 265 delegate_->GetBrowserProfile()->GetRequestContext())); | 224 |
| 266 gaia_client_->GetUserInfo(auth_token_, 0, this); | 225 if (account_info_.IsValid()) |
| 226 FetchImageData(); |
| 227 else |
| 228 waiting_for_account_info_ = true; |
| 267 } | 229 } |
| 268 | 230 |
| 269 void ProfileDownloader::StartFetchingOAuth2AccessToken() { | 231 void ProfileDownloader::StartFetchingOAuth2AccessToken() { |
| 270 Profile* profile = delegate_->GetBrowserProfile(); | 232 Profile* profile = delegate_->GetBrowserProfile(); |
| 271 OAuth2TokenService::ScopeSet scopes; | 233 OAuth2TokenService::ScopeSet scopes; |
| 272 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); | 234 scopes.insert(GaiaConstants::kGoogleUserInfoProfile); |
| 273 // Increase scope to get hd attribute to determine if lock should be enabled. | 235 // Increase scope to get hd attribute to determine if lock should be enabled. |
| 274 if (switches::IsNewProfileManagement()) | 236 if (switches::IsNewProfileManagement()) |
| 275 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); | 237 scopes.insert(GaiaConstants::kGoogleUserInfoEmail); |
| 276 ProfileOAuth2TokenService* token_service = | 238 ProfileOAuth2TokenService* token_service = |
| 277 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 239 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 278 oauth2_access_token_request_ = token_service->StartRequest( | 240 oauth2_access_token_request_ = token_service->StartRequest( |
| 279 account_id_, scopes, this); | 241 account_id_, scopes, this); |
| 280 } | 242 } |
| 281 | 243 |
| 282 ProfileDownloader::~ProfileDownloader() { | 244 ProfileDownloader::~ProfileDownloader() { |
| 283 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed | 245 // Ensures PO2TS observation is cleared when ProfileDownloader is destructed |
| 284 // before refresh token is available. | 246 // before refresh token is available. |
| 285 ProfileOAuth2TokenService* service = | 247 ProfileOAuth2TokenService* service = |
| 286 ProfileOAuth2TokenServiceFactory::GetForProfile( | 248 ProfileOAuth2TokenServiceFactory::GetForProfile( |
| 287 delegate_->GetBrowserProfile()); | 249 delegate_->GetBrowserProfile()); |
| 288 if (service) | 250 if (service) |
| 289 service->RemoveObserver(this); | 251 service->RemoveObserver(this); |
| 252 |
| 253 account_tracker_service_->RemoveObserver(this); |
| 290 } | 254 } |
| 291 | 255 |
| 292 void ProfileDownloader::OnGetUserInfoResponse( | 256 void ProfileDownloader::FetchImageData() { |
| 293 scoped_ptr<base::DictionaryValue> user_info) { | 257 DCHECK(account_info_.IsValid()); |
| 294 std::string image_url; | 258 std::string image_url_with_size = GetProfilePictureURL(); |
| 295 if (!ParseProfileJSON(user_info.get(), | 259 |
| 296 &profile_full_name_, | |
| 297 &profile_given_name_, | |
| 298 &image_url, | |
| 299 delegate_->GetDesiredImageSideLength(), | |
| 300 &profile_locale_, | |
| 301 &profile_hosted_domain_)) { | |
| 302 delegate_->OnProfileDownloadFailure( | |
| 303 this, ProfileDownloaderDelegate::SERVICE_ERROR); | |
| 304 return; | |
| 305 } | |
| 306 if (!delegate_->NeedsProfilePicture()) { | 260 if (!delegate_->NeedsProfilePicture()) { |
| 307 VLOG(1) << "Skipping profile picture download"; | 261 VLOG(1) << "Skipping profile picture download"; |
| 308 delegate_->OnProfileDownloadSuccess(this); | 262 delegate_->OnProfileDownloadSuccess(this); |
| 309 return; | 263 return; |
| 310 } | 264 } |
| 311 if (IsDefaultProfileImageURL(image_url)) { | 265 if (IsDefaultProfileImageURL(image_url_with_size)) { |
| 312 VLOG(1) << "User has default profile picture"; | 266 VLOG(1) << "User has default profile picture"; |
| 313 picture_status_ = PICTURE_DEFAULT; | 267 picture_status_ = PICTURE_DEFAULT; |
| 314 delegate_->OnProfileDownloadSuccess(this); | 268 delegate_->OnProfileDownloadSuccess(this); |
| 315 return; | 269 return; |
| 316 } | 270 } |
| 317 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) { | 271 if (!image_url_with_size.empty() && |
| 272 image_url_with_size == delegate_->GetCachedPictureURL()) { |
| 318 VLOG(1) << "Picture URL matches cached picture URL"; | 273 VLOG(1) << "Picture URL matches cached picture URL"; |
| 319 picture_status_ = PICTURE_CACHED; | 274 picture_status_ = PICTURE_CACHED; |
| 320 delegate_->OnProfileDownloadSuccess(this); | 275 delegate_->OnProfileDownloadSuccess(this); |
| 321 return; | 276 return; |
| 322 } | 277 } |
| 323 VLOG(1) << "Fetching profile image from " << image_url; | 278 VLOG(1) << "Fetching profile image from " << image_url_with_size; |
| 324 picture_url_ = image_url; | 279 |
| 325 profile_image_fetcher_.reset(net::URLFetcher::Create( | 280 net::URLFetcher* new_fetcher = net::URLFetcher::Create( |
| 326 GURL(image_url), net::URLFetcher::GET, this)); | 281 GURL(image_url_with_size), net::URLFetcher::GET, this); |
| 282 |
| 283 profile_image_fetcher_.reset(new_fetcher); |
| 327 profile_image_fetcher_->SetRequestContext( | 284 profile_image_fetcher_->SetRequestContext( |
| 328 delegate_->GetBrowserProfile()->GetRequestContext()); | 285 signin_client_->GetURLRequestContext()); |
| 329 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 286 profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 330 net::LOAD_DO_NOT_SAVE_COOKIES); | 287 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 288 |
| 331 if (!auth_token_.empty()) { | 289 if (!auth_token_.empty()) { |
| 332 profile_image_fetcher_->SetExtraRequestHeaders( | 290 profile_image_fetcher_->SetExtraRequestHeaders( |
| 333 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 291 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 334 } | 292 } |
| 335 profile_image_fetcher_->Start(); | 293 profile_image_fetcher_->Start(); |
| 336 } | 294 } |
| 337 | 295 |
| 338 void ProfileDownloader::OnOAuthError() { | |
| 339 LOG(WARNING) << "OnOAuthError: Fetching profile data failed"; | |
| 340 delegate_->OnProfileDownloadFailure( | |
| 341 this, ProfileDownloaderDelegate::SERVICE_ERROR); | |
| 342 } | |
| 343 | |
| 344 void ProfileDownloader::OnNetworkError(int response_code) { | |
| 345 LOG(WARNING) << "OnNetworkError: Fetching profile data failed"; | |
| 346 DVLOG(1) << " Response code: " << response_code; | |
| 347 delegate_->OnProfileDownloadFailure( | |
| 348 this, ProfileDownloaderDelegate::NETWORK_ERROR); | |
| 349 } | |
| 350 | |
| 351 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { | 296 void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 353 std::string data; | 298 std::string data; |
| 354 source->GetResponseAsString(&data); | 299 source->GetResponseAsString(&data); |
| 355 bool network_error = | 300 bool network_error = |
| 356 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; | 301 source->GetStatus().status() != net::URLRequestStatus::SUCCESS; |
| 357 if (network_error || source->GetResponseCode() != 200) { | 302 if (network_error || source->GetResponseCode() != 200) { |
| 358 LOG(WARNING) << "Fetching profile data failed"; | 303 LOG(WARNING) << "Fetching profile data failed"; |
| 359 DVLOG(1) << " Status: " << source->GetStatus().status(); | 304 DVLOG(1) << " Status: " << source->GetStatus().status(); |
| 360 DVLOG(1) << " Error: " << source->GetStatus().error(); | 305 DVLOG(1) << " Error: " << source->GetStatus().error(); |
| 361 DVLOG(1) << " Response code: " << source->GetResponseCode(); | 306 DVLOG(1) << " Response code: " << source->GetResponseCode(); |
| 362 DVLOG(1) << " Url: " << source->GetURL().spec(); | 307 DVLOG(1) << " Url: " << source->GetURL().spec(); |
| 308 profile_image_fetcher_.reset(); |
| 363 delegate_->OnProfileDownloadFailure(this, network_error ? | 309 delegate_->OnProfileDownloadFailure(this, network_error ? |
| 364 ProfileDownloaderDelegate::NETWORK_ERROR : | 310 ProfileDownloaderDelegate::NETWORK_ERROR : |
| 365 ProfileDownloaderDelegate::SERVICE_ERROR); | 311 ProfileDownloaderDelegate::SERVICE_ERROR); |
| 366 return; | 312 } else { |
| 313 profile_image_fetcher_.reset(); |
| 314 VLOG(1) << "Decoding the image..."; |
| 315 ImageDecoder::Start(this, data); |
| 367 } | 316 } |
| 368 | |
| 369 VLOG(1) << "Decoding the image..."; | |
| 370 ImageDecoder::Start(this, data); | |
| 371 } | 317 } |
| 372 | 318 |
| 373 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { | 319 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) { |
| 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 375 int image_size = delegate_->GetDesiredImageSideLength(); | 321 int image_size = delegate_->GetDesiredImageSideLength(); |
| 376 profile_picture_ = skia::ImageOperations::Resize( | 322 profile_picture_ = skia::ImageOperations::Resize( |
| 377 decoded_image, | 323 decoded_image, |
| 378 skia::ImageOperations::RESIZE_BEST, | 324 skia::ImageOperations::RESIZE_BEST, |
| 379 image_size, | 325 image_size, |
| 380 image_size); | 326 image_size); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 void ProfileDownloader::OnGetTokenFailure( | 361 void ProfileDownloader::OnGetTokenFailure( |
| 416 const OAuth2TokenService::Request* request, | 362 const OAuth2TokenService::Request* request, |
| 417 const GoogleServiceAuthError& error) { | 363 const GoogleServiceAuthError& error) { |
| 418 DCHECK_EQ(request, oauth2_access_token_request_.get()); | 364 DCHECK_EQ(request, oauth2_access_token_request_.get()); |
| 419 oauth2_access_token_request_.reset(); | 365 oauth2_access_token_request_.reset(); |
| 420 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" | 366 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" |
| 421 << error.ToString(); | 367 << error.ToString(); |
| 422 delegate_->OnProfileDownloadFailure( | 368 delegate_->OnProfileDownloadFailure( |
| 423 this, ProfileDownloaderDelegate::TOKEN_ERROR); | 369 this, ProfileDownloaderDelegate::TOKEN_ERROR); |
| 424 } | 370 } |
| 371 |
| 372 void ProfileDownloader::OnAccountUpdated( |
| 373 const AccountTrackerService::AccountInfo& info) { |
| 374 if (info.account_id == account_id_ && info.IsValid()) { |
| 375 account_info_ = info; |
| 376 |
| 377 // If the StartFetchingImage was called before we had valid info, the |
| 378 // downloader has been waiting so we need to fetch the image data now. |
| 379 if (waiting_for_account_info_) { |
| 380 FetchImageData(); |
| 381 waiting_for_account_info_ = false; |
| 382 } |
| 383 } |
| 384 } |
| OLD | NEW |