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

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

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a few comments Created 5 years, 9 months 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
OLDNEW
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"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex]; 186 const std::string& photo_id = path_components[kPhotoIdPathComponentIndex];
187 const std::string& photo_version = 187 const std::string& photo_version =
188 path_components[kPhotoVersionPathComponentIndex]; 188 path_components[kPhotoVersionPathComponentIndex];
189 189
190 // Check that the ID and version match the default Picasa profile photo. 190 // Check that the ID and version match the default Picasa profile photo.
191 return photo_id == kPicasaPhotoId && 191 return photo_id == kPicasaPhotoId &&
192 photo_version == kDefaultPicasaPhotoVersion; 192 photo_version == kDefaultPicasaPhotoVersion;
193 } 193 }
194 194
195 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate) 195 ProfileDownloader::ProfileDownloader(ProfileDownloaderDelegate* delegate)
196 : OAuth2TokenService::Consumer("profile_downloader"), 196 : ImageRequest(
197 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)),
198 OAuth2TokenService::Consumer("profile_downloader"),
197 delegate_(delegate), 199 delegate_(delegate),
198 picture_status_(PICTURE_FAILED) { 200 picture_status_(PICTURE_FAILED) {
199 DCHECK(delegate_); 201 DCHECK(delegate_);
200 } 202 }
201 203
202 void ProfileDownloader::Start() { 204 void ProfileDownloader::Start() {
203 StartForAccount(std::string()); 205 StartForAccount(std::string());
204 } 206 }
205 207
206 void ProfileDownloader::StartForAccount(const std::string& account_id) { 208 void ProfileDownloader::StartForAccount(const std::string& account_id) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 DVLOG(1) << " Error: " << source->GetStatus().error(); 362 DVLOG(1) << " Error: " << source->GetStatus().error();
361 DVLOG(1) << " Response code: " << source->GetResponseCode(); 363 DVLOG(1) << " Response code: " << source->GetResponseCode();
362 DVLOG(1) << " Url: " << source->GetURL().spec(); 364 DVLOG(1) << " Url: " << source->GetURL().spec();
363 delegate_->OnProfileDownloadFailure(this, network_error ? 365 delegate_->OnProfileDownloadFailure(this, network_error ?
364 ProfileDownloaderDelegate::NETWORK_ERROR : 366 ProfileDownloaderDelegate::NETWORK_ERROR :
365 ProfileDownloaderDelegate::SERVICE_ERROR); 367 ProfileDownloaderDelegate::SERVICE_ERROR);
366 return; 368 return;
367 } 369 }
368 370
369 VLOG(1) << "Decoding the image..."; 371 VLOG(1) << "Decoding the image...";
370 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder( 372 ImageDecoder::Start(this, data);
371 this, data, ImageDecoder::DEFAULT_CODEC);
372 scoped_refptr<base::MessageLoopProxy> task_runner =
373 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
374 image_decoder->Start(task_runner);
375 } 373 }
376 374
377 void ProfileDownloader::OnImageDecoded(const ImageDecoder* decoder, 375 void ProfileDownloader::OnImageDecoded(const SkBitmap& decoded_image) {
378 const SkBitmap& decoded_image) {
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
380 int image_size = delegate_->GetDesiredImageSideLength(); 377 int image_size = delegate_->GetDesiredImageSideLength();
381 profile_picture_ = skia::ImageOperations::Resize( 378 profile_picture_ = skia::ImageOperations::Resize(
382 decoded_image, 379 decoded_image,
383 skia::ImageOperations::RESIZE_BEST, 380 skia::ImageOperations::RESIZE_BEST,
384 image_size, 381 image_size,
385 image_size); 382 image_size);
386 picture_status_ = PICTURE_SUCCESS; 383 picture_status_ = PICTURE_SUCCESS;
387 delegate_->OnProfileDownloadSuccess(this); 384 delegate_->OnProfileDownloadSuccess(this);
388 } 385 }
389 386
390 void ProfileDownloader::OnDecodeImageFailed(const ImageDecoder* decoder) { 387 void ProfileDownloader::OnDecodeImageFailed() {
391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
392 delegate_->OnProfileDownloadFailure( 389 delegate_->OnProfileDownloadFailure(
393 this, ProfileDownloaderDelegate::IMAGE_DECODE_FAILED); 390 this, ProfileDownloaderDelegate::IMAGE_DECODE_FAILED);
394 } 391 }
395 392
396 void ProfileDownloader::OnRefreshTokenAvailable(const std::string& account_id) { 393 void ProfileDownloader::OnRefreshTokenAvailable(const std::string& account_id) {
397 ProfileOAuth2TokenService* service = 394 ProfileOAuth2TokenService* service =
398 ProfileOAuth2TokenServiceFactory::GetForProfile( 395 ProfileOAuth2TokenServiceFactory::GetForProfile(
399 delegate_->GetBrowserProfile()); 396 delegate_->GetBrowserProfile());
400 if (account_id != account_id_) 397 if (account_id != account_id_)
(...skipping 19 matching lines...) Expand all
420 void ProfileDownloader::OnGetTokenFailure( 417 void ProfileDownloader::OnGetTokenFailure(
421 const OAuth2TokenService::Request* request, 418 const OAuth2TokenService::Request* request,
422 const GoogleServiceAuthError& error) { 419 const GoogleServiceAuthError& error) {
423 DCHECK_EQ(request, oauth2_access_token_request_.get()); 420 DCHECK_EQ(request, oauth2_access_token_request_.get());
424 oauth2_access_token_request_.reset(); 421 oauth2_access_token_request_.reset();
425 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:" 422 LOG(WARNING) << "ProfileDownloader: token request using refresh token failed:"
426 << error.ToString(); 423 << error.ToString();
427 delegate_->OnProfileDownloadFailure( 424 delegate_->OnProfileDownloadFailure(
428 this, ProfileDownloaderDelegate::TOKEN_ERROR); 425 this, ProfileDownloaderDelegate::TOKEN_ERROR);
429 } 426 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_downloader.h ('k') | chrome/browser/ui/app_list/search/common/url_icon_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698