Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 165 |
| 166 // There are at least two pairs of (ID, version) for the default photo: | 166 // There are at least two pairs of (ID, version) for the default photo: |
| 167 // the default Google+ profile photo and the default Picasa profile photo. | 167 // the default Google+ profile photo and the default Picasa profile photo. |
| 168 return ((photo_id == kPicasaPhotoId && | 168 return ((photo_id == kPicasaPhotoId && |
| 169 photo_version == kDefaultPicasaPhotoVersion) || | 169 photo_version == kDefaultPicasaPhotoVersion) || |
| 170 (photo_id == kGooglePlusPhotoId && | 170 (photo_id == kGooglePlusPhotoId && |
| 171 photo_version == kDefaultGooglePlusPhotoVersion)); | 171 photo_version == kDefaultGooglePlusPhotoVersion)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) | 174 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) |
| 175 : delegate_(delegate) { | 175 : delegate_(delegate), |
| 176 picture_result_(PICTURE_FAILED) { | |
| 176 DCHECK(delegate_); | 177 DCHECK(delegate_); |
| 177 } | 178 } |
| 178 | 179 |
| 179 void ProfileDownloader::Start() { | 180 void ProfileDownloader::Start() { |
| 180 VLOG(1) << "Starting profile downloader..."; | 181 VLOG(1) << "Starting profile downloader..."; |
| 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 182 | 183 |
| 183 TokenService* service = delegate_->GetBrowserProfile()->GetTokenService(); | 184 TokenService* service = delegate_->GetBrowserProfile()->GetTokenService(); |
| 184 if (!service) { | 185 if (!service) { |
| 185 // This can happen in some test paths. | 186 // This can happen in some test paths. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 202 } | 203 } |
| 203 | 204 |
| 204 string16 ProfileDownloader::GetProfileFullName() const { | 205 string16 ProfileDownloader::GetProfileFullName() const { |
| 205 return profile_full_name_; | 206 return profile_full_name_; |
| 206 } | 207 } |
| 207 | 208 |
| 208 SkBitmap ProfileDownloader::GetProfilePicture() const { | 209 SkBitmap ProfileDownloader::GetProfilePicture() const { |
| 209 return profile_picture_; | 210 return profile_picture_; |
| 210 } | 211 } |
| 211 | 212 |
| 213 ProfileDownloader::PictureResult ProfileDownloader::GetProfilePictureResult() | |
| 214 const { | |
| 215 return picture_result_; | |
| 216 } | |
| 217 | |
| 218 std::string ProfileDownloader::GetProfilePictureURL() const { | |
| 219 return picture_url_; | |
| 220 } | |
| 221 | |
| 212 void ProfileDownloader::StartFetchingImage() { | 222 void ProfileDownloader::StartFetchingImage() { |
| 213 VLOG(1) << "Fetching user entry with token: " << auth_token_; | 223 VLOG(1) << "Fetching user entry with token: " << auth_token_; |
| 214 user_entry_fetcher_.reset(content::URLFetcher::Create( | 224 user_entry_fetcher_.reset(content::URLFetcher::Create( |
| 215 GURL(kUserEntryURL), content::URLFetcher::GET, this)); | 225 GURL(kUserEntryURL), content::URLFetcher::GET, this)); |
| 216 user_entry_fetcher_->SetRequestContext( | 226 user_entry_fetcher_->SetRequestContext( |
| 217 delegate_->GetBrowserProfile()->GetRequestContext()); | 227 delegate_->GetBrowserProfile()->GetRequestContext()); |
| 218 if (!auth_token_.empty()) { | 228 if (!auth_token_.empty()) { |
| 219 user_entry_fetcher_->SetExtraRequestHeaders( | 229 user_entry_fetcher_->SetExtraRequestHeaders( |
| 220 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 230 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 221 } | 231 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 236 return; | 246 return; |
| 237 } | 247 } |
| 238 | 248 |
| 239 if (source == user_entry_fetcher_.get()) { | 249 if (source == user_entry_fetcher_.get()) { |
| 240 std::string image_url; | 250 std::string image_url; |
| 241 if (!GetProfileNickNameAndImageURL(data, &profile_full_name_, &image_url)) { | 251 if (!GetProfileNickNameAndImageURL(data, &profile_full_name_, &image_url)) { |
| 242 delegate_->OnDownloadComplete(this, false); | 252 delegate_->OnDownloadComplete(this, false); |
| 243 return; | 253 return; |
| 244 } | 254 } |
| 245 if (IsDefaultProfileImageURL(image_url)) { | 255 if (IsDefaultProfileImageURL(image_url)) { |
| 256 picture_result_ = PICTURE_DEFAULT; | |
|
Ivan Korotkov
2011/11/30 14:35:44
Please add VLOG here and in the next if ()
sail
2011/11/30 19:00:23
Done.
| |
| 257 delegate_->OnDownloadComplete(this, true); | |
| 258 return; | |
| 259 } | |
| 260 if (image_url == delegate_->GetCachedPictureURL()) { | |
|
Ivan Korotkov
2011/11/30 14:35:44
Since GetCachedPictureURL() has to return somethin
sail
2011/11/30 19:00:23
Done.
| |
| 261 picture_result_ = PICTURE_CACHED; | |
| 246 delegate_->OnDownloadComplete(this, true); | 262 delegate_->OnDownloadComplete(this, true); |
| 247 return; | 263 return; |
| 248 } | 264 } |
| 249 VLOG(1) << "Fetching profile image from " << image_url; | 265 VLOG(1) << "Fetching profile image from " << image_url; |
| 266 picture_url_ = image_url; | |
| 250 profile_image_fetcher_.reset(content::URLFetcher::Create( | 267 profile_image_fetcher_.reset(content::URLFetcher::Create( |
| 251 GURL(image_url), content::URLFetcher::GET, this)); | 268 GURL(image_url), content::URLFetcher::GET, this)); |
| 252 profile_image_fetcher_->SetRequestContext( | 269 profile_image_fetcher_->SetRequestContext( |
| 253 delegate_->GetBrowserProfile()->GetRequestContext()); | 270 delegate_->GetBrowserProfile()->GetRequestContext()); |
| 254 if (!auth_token_.empty()) { | 271 if (!auth_token_.empty()) { |
| 255 profile_image_fetcher_->SetExtraRequestHeaders( | 272 profile_image_fetcher_->SetExtraRequestHeaders( |
| 256 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); | 273 base::StringPrintf(kAuthorizationHeader, auth_token_.c_str())); |
| 257 } | 274 } |
| 258 profile_image_fetcher_->Start(); | 275 profile_image_fetcher_->Start(); |
| 259 } else if (source == profile_image_fetcher_.get()) { | 276 } else if (source == profile_image_fetcher_.get()) { |
| 260 VLOG(1) << "Decoding the image..."; | 277 VLOG(1) << "Decoding the image..."; |
| 261 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( | 278 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( |
| 262 this, data); | 279 this, data); |
| 263 image_decoder->Start(); | 280 image_decoder->Start(); |
| 264 } | 281 } |
| 265 } | 282 } |
| 266 | 283 |
| 267 void ProfileDownloader::OnImageDecoded(const ImageDecoder* decoder, | 284 void ProfileDownloader::OnImageDecoded(const ImageDecoder* decoder, |
| 268 const SkBitmap& decoded_image) { | 285 const SkBitmap& decoded_image) { |
| 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 270 int image_size = delegate_->GetDesiredImageSideLength(); | 287 int image_size = delegate_->GetDesiredImageSideLength(); |
| 271 profile_picture_ = skia::ImageOperations::Resize( | 288 profile_picture_ = skia::ImageOperations::Resize( |
| 272 decoded_image, | 289 decoded_image, |
| 273 skia::ImageOperations::RESIZE_BEST, | 290 skia::ImageOperations::RESIZE_BEST, |
| 274 image_size, | 291 image_size, |
| 275 image_size); | 292 image_size); |
| 293 picture_result_ = PICTURE_SUCCESS; | |
| 276 delegate_->OnDownloadComplete(this, true); | 294 delegate_->OnDownloadComplete(this, true); |
| 277 } | 295 } |
| 278 | 296 |
| 279 void ProfileDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) { | 297 void ProfileDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) { |
| 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 281 delegate_->OnDownloadComplete(this, false); | 299 delegate_->OnDownloadComplete(this, false); |
| 282 } | 300 } |
| 283 | 301 |
| 284 void ProfileDownloader::Observe( | 302 void ProfileDownloader::Observe( |
| 285 int type, | 303 int type, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 296 auth_token_ = token_details->token(); | 314 auth_token_ = token_details->token(); |
| 297 StartFetchingImage(); | 315 StartFetchingImage(); |
| 298 } | 316 } |
| 299 } else { | 317 } else { |
| 300 if (token_details->service() == GaiaConstants::kPicasaService) { | 318 if (token_details->service() == GaiaConstants::kPicasaService) { |
| 301 LOG(WARNING) << "ProfileDownloader: token request failed"; | 319 LOG(WARNING) << "ProfileDownloader: token request failed"; |
| 302 delegate_->OnDownloadComplete(this, false); | 320 delegate_->OnDownloadComplete(this, false); |
| 303 } | 321 } |
| 304 } | 322 } |
| 305 } | 323 } |
| OLD | NEW |