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

Side by Side Diff: chrome/browser/profiles/profile_downloader.cc

Issue 8742009: Cache GAIA profile picture URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // There are at least two pairs of (ID, version) for the default photo: 178 // There are at least two pairs of (ID, version) for the default photo:
179 // the default Google+ profile photo and the default Picasa profile photo. 179 // the default Google+ profile photo and the default Picasa profile photo.
180 return ((photo_id == kPicasaPhotoId && 180 return ((photo_id == kPicasaPhotoId &&
181 photo_version == kDefaultPicasaPhotoVersion) || 181 photo_version == kDefaultPicasaPhotoVersion) ||
182 (photo_id == kGooglePlusPhotoId && 182 (photo_id == kGooglePlusPhotoId &&
183 photo_version == kDefaultGooglePlusPhotoVersion)); 183 photo_version == kDefaultGooglePlusPhotoVersion));
184 } 184 }
185 185
186 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) 186 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate)
187 : delegate_(delegate) { 187 : delegate_(delegate),
188 picture_status_(PICTURE_FAILED) {
188 DCHECK(delegate_); 189 DCHECK(delegate_);
189 } 190 }
190 191
191 void ProfileDownloader::Start() { 192 void ProfileDownloader::Start() {
192 VLOG(1) << "Starting profile downloader..."; 193 VLOG(1) << "Starting profile downloader...";
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 195
195 TokenService* service = delegate_->GetBrowserProfile()->GetTokenService(); 196 TokenService* service = delegate_->GetBrowserProfile()->GetTokenService();
196 if (!service) { 197 if (!service) {
197 // This can happen in some test paths. 198 // This can happen in some test paths.
(...skipping 21 matching lines...) Expand all
219 } 220 }
220 221
221 string16 ProfileDownloader::GetProfileFullName() const { 222 string16 ProfileDownloader::GetProfileFullName() const {
222 return profile_full_name_; 223 return profile_full_name_;
223 } 224 }
224 225
225 SkBitmap ProfileDownloader::GetProfilePicture() const { 226 SkBitmap ProfileDownloader::GetProfilePicture() const {
226 return profile_picture_; 227 return profile_picture_;
227 } 228 }
228 229
230 ProfileDownloader::PictureStatus ProfileDownloader::GetProfilePictureStatus()
231 const {
232 return picture_status_;
233 }
234
235 std::string ProfileDownloader::GetProfilePictureURL() const {
236 return picture_url_;
237 }
238
229 void ProfileDownloader::StartFetchingImage() { 239 void ProfileDownloader::StartFetchingImage() {
230 VLOG(1) << "Fetching user entry with token: " << auth_token_; 240 VLOG(1) << "Fetching user entry with token: " << auth_token_;
231 user_entry_fetcher_.reset(content::URLFetcher::Create( 241 user_entry_fetcher_.reset(content::URLFetcher::Create(
232 GURL(kUserEntryURL), content::URLFetcher::GET, this)); 242 GURL(kUserEntryURL), content::URLFetcher::GET, this));
233 user_entry_fetcher_->SetRequestContext( 243 user_entry_fetcher_->SetRequestContext(
234 delegate_->GetBrowserProfile()->GetRequestContext()); 244 delegate_->GetBrowserProfile()->GetRequestContext());
235 if (!auth_token_.empty()) { 245 if (!auth_token_.empty()) {
236 user_entry_fetcher_->SetExtraRequestHeaders( 246 user_entry_fetcher_->SetExtraRequestHeaders(
237 base::StringPrintf(GetAuthorizationHeader(), auth_token_.c_str())); 247 base::StringPrintf(GetAuthorizationHeader(), auth_token_.c_str()));
238 } 248 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return; 283 return;
274 } 284 }
275 285
276 if (source == user_entry_fetcher_.get()) { 286 if (source == user_entry_fetcher_.get()) {
277 std::string image_url; 287 std::string image_url;
278 if (!GetProfileNickNameAndImageURL(data, &profile_full_name_, &image_url)) { 288 if (!GetProfileNickNameAndImageURL(data, &profile_full_name_, &image_url)) {
279 delegate_->OnDownloadComplete(this, false); 289 delegate_->OnDownloadComplete(this, false);
280 return; 290 return;
281 } 291 }
282 if (IsDefaultProfileImageURL(image_url)) { 292 if (IsDefaultProfileImageURL(image_url)) {
293 VLOG(1) << "User has default profile picture";
294 picture_status_ = PICTURE_DEFAULT;
295 delegate_->OnDownloadComplete(this, true);
296 return;
297 }
298 if (!image_url.empty() && image_url == delegate_->GetCachedPictureURL()) {
299 VLOG(1) << "Picture URL matches cached picture URL";
300 picture_status_ = PICTURE_CACHED;
283 delegate_->OnDownloadComplete(this, true); 301 delegate_->OnDownloadComplete(this, true);
284 return; 302 return;
285 } 303 }
286 VLOG(1) << "Fetching profile image from " << image_url; 304 VLOG(1) << "Fetching profile image from " << image_url;
305 picture_url_ = image_url;
287 profile_image_fetcher_.reset(content::URLFetcher::Create( 306 profile_image_fetcher_.reset(content::URLFetcher::Create(
288 GURL(image_url), content::URLFetcher::GET, this)); 307 GURL(image_url), content::URLFetcher::GET, this));
289 profile_image_fetcher_->SetRequestContext( 308 profile_image_fetcher_->SetRequestContext(
290 delegate_->GetBrowserProfile()->GetRequestContext()); 309 delegate_->GetBrowserProfile()->GetRequestContext());
291 if (!auth_token_.empty()) { 310 if (!auth_token_.empty()) {
292 profile_image_fetcher_->SetExtraRequestHeaders( 311 profile_image_fetcher_->SetExtraRequestHeaders(
293 base::StringPrintf(GetAuthorizationHeader(), auth_token_.c_str())); 312 base::StringPrintf(GetAuthorizationHeader(), auth_token_.c_str()));
294 } 313 }
295 profile_image_fetcher_->Start(); 314 profile_image_fetcher_->Start();
296 } else if (source == profile_image_fetcher_.get()) { 315 } else if (source == profile_image_fetcher_.get()) {
297 VLOG(1) << "Decoding the image..."; 316 VLOG(1) << "Decoding the image...";
298 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( 317 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(
299 this, data); 318 this, data);
300 image_decoder->Start(); 319 image_decoder->Start();
301 } 320 }
302 } 321 }
303 322
304 void ProfileDownloader::OnImageDecoded(const ImageDecoder* decoder, 323 void ProfileDownloader::OnImageDecoded(const ImageDecoder* decoder,
305 const SkBitmap& decoded_image) { 324 const SkBitmap& decoded_image) {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
307 int image_size = delegate_->GetDesiredImageSideLength(); 326 int image_size = delegate_->GetDesiredImageSideLength();
308 profile_picture_ = skia::ImageOperations::Resize( 327 profile_picture_ = skia::ImageOperations::Resize(
309 decoded_image, 328 decoded_image,
310 skia::ImageOperations::RESIZE_BEST, 329 skia::ImageOperations::RESIZE_BEST,
311 image_size, 330 image_size,
312 image_size); 331 image_size);
332 picture_status_ = PICTURE_SUCCESS;
313 delegate_->OnDownloadComplete(this, true); 333 delegate_->OnDownloadComplete(this, true);
314 } 334 }
315 335
316 void ProfileDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) { 336 void ProfileDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) {
317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
318 delegate_->OnDownloadComplete(this, false); 338 delegate_->OnDownloadComplete(this, false);
319 } 339 }
320 340
321 void ProfileDownloader::Observe( 341 void ProfileDownloader::Observe(
322 int type, 342 int type,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) { 374 void ProfileDownloader::OnGetTokenSuccess(const std::string& access_token) {
355 auth_token_ = access_token; 375 auth_token_ = access_token;
356 StartFetchingImage(); 376 StartFetchingImage();
357 } 377 }
358 378
359 // Callback for OAuth2AccessTokenFetcher on failure. 379 // Callback for OAuth2AccessTokenFetcher on failure.
360 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) { 380 void ProfileDownloader::OnGetTokenFailure(const GoogleServiceAuthError& error) {
361 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed"; 381 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed";
362 delegate_->OnDownloadComplete(this, false); 382 delegate_->OnDownloadComplete(this, false);
363 } 383 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_downloader.h ('k') | chrome/browser/profiles/profile_downloader_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698