| Index: components/ntp_tiles/most_visited_sites.cc
|
| diff --git a/components/ntp_tiles/most_visited_sites.cc b/components/ntp_tiles/most_visited_sites.cc
|
| index 4396851b671f055f47d1c05808daeb6a5a511a51..bb552952958a7c837b3830e1dbe7dd0087acdfdc 100644
|
| --- a/components/ntp_tiles/most_visited_sites.cc
|
| +++ b/components/ntp_tiles/most_visited_sites.cc
|
| @@ -63,17 +63,6 @@ enum MostVisitedTileType {
|
| NUM_TILE_TYPES,
|
| };
|
|
|
| -// May only be called from blocking thread pool.
|
| -std::unique_ptr<SkBitmap> TryFetchLocalThumbnail(
|
| - const GURL& url,
|
| - const scoped_refptr<TopSites>& top_sites) {
|
| - scoped_refptr<base::RefCountedMemory> image;
|
| - std::unique_ptr<SkBitmap> bitmap;
|
| - if (top_sites->GetPageThumbnail(url, false, &image))
|
| - bitmap = gfx::JPEGCodec::Decode(image->front(), image->size());
|
| - return bitmap;
|
| -}
|
| -
|
| // Log an event for a given |histogram| at a given element |position|. This
|
| // routine exists because regular histogram macros are cached thus can't be used
|
| // if the name of the histogram will change at a given call site.
|
| @@ -177,7 +166,8 @@ MostVisitedSites::MostVisitedSites(
|
| const base::FilePath& popular_sites_directory,
|
| scoped_refptr<history::TopSites> top_sites,
|
| SuggestionsService* suggestions,
|
| - MostVisitedSitesSupervisor* supervisor)
|
| + MostVisitedSitesSupervisor* supervisor,
|
| + image_fetcher::ImageDecoder* image_decoder)
|
| : prefs_(prefs),
|
| template_url_service_(template_url_service),
|
| variations_service_(variations_service),
|
| @@ -186,6 +176,7 @@ MostVisitedSites::MostVisitedSites(
|
| top_sites_(top_sites),
|
| suggestions_service_(suggestions),
|
| supervisor_(supervisor),
|
| + image_decoder_(image_decoder),
|
| observer_(nullptr),
|
| num_sites_(0),
|
| received_most_visited_sites_(false),
|
| @@ -243,59 +234,13 @@ void MostVisitedSites::SetMostVisitedURLsObserver(Observer* observer,
|
| suggestions_service_->FetchSuggestionsData();
|
| }
|
|
|
| -void MostVisitedSites::GetURLThumbnail(const GURL& url,
|
| - const ThumbnailCallback& callback) {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| -
|
| - base::PostTaskAndReplyWithResult(
|
| - blocking_runner_.get(), FROM_HERE,
|
| - base::Bind(&TryFetchLocalThumbnail, url, top_sites_),
|
| - base::Bind(&MostVisitedSites::OnLocalThumbnailFetched,
|
| - weak_ptr_factory_.GetWeakPtr(), url, callback));
|
| -}
|
| -
|
| -void MostVisitedSites::OnLocalThumbnailFetched(
|
| - const GURL& url,
|
| - const ThumbnailCallback& callback,
|
| - std::unique_ptr<SkBitmap> bitmap) {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| - if (bitmap.get()) {
|
| - callback.Run(true /* is_local_thumbnail */, bitmap.get());
|
| - return;
|
| - }
|
| -
|
| - // A thumbnail is not locally available for |url|. Make sure it is put in
|
| - // the list to be fetched at the next visit to this site.
|
| - top_sites_->AddForcedURL(url, base::Time::Now());
|
| - // Also fetch a remote thumbnail if possible. PopularSites or the
|
| - // SuggestionsService can supply a thumbnail download URL.
|
| - if (popular_sites_) {
|
| - const std::vector<PopularSites::Site>& sites = popular_sites_->sites();
|
| - auto it = std::find_if(
|
| - sites.begin(), sites.end(),
|
| - [&url](const PopularSites::Site& site) { return site.url == url; });
|
| - if (it != sites.end() && it->thumbnail_url.is_valid()) {
|
| - return suggestions_service_->GetPageThumbnailWithURL(
|
| - url, it->thumbnail_url,
|
| - base::Bind(&MostVisitedSites::OnObtainedThumbnail,
|
| - weak_ptr_factory_.GetWeakPtr(), false, callback));
|
| - }
|
| - }
|
| - if (mv_source_ == SUGGESTIONS_SERVICE) {
|
| - return suggestions_service_->GetPageThumbnail(
|
| - url, base::Bind(&MostVisitedSites::OnObtainedThumbnail,
|
| - weak_ptr_factory_.GetWeakPtr(), false, callback));
|
| - }
|
| - // If no bitmap could be fetched and neither PopularSites nor the
|
| - // SuggestionsService is available then a nullptr is passed to the callback.
|
| - callback.Run(true /* is_local_thumbnail */, nullptr);
|
| -}
|
| -
|
| void MostVisitedSites::OnObtainedThumbnail(bool is_local_thumbnail,
|
| const ThumbnailCallback& callback,
|
| const GURL& url,
|
| const gfx::Image& image) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| + // TODO(markusheintz): Move the code for converting to SkBitmap to the
|
| + // callback.
|
| const SkBitmap* bitmap = nullptr;
|
| if (!image.IsEmpty())
|
| bitmap = image.ToSkBitmap();
|
|
|