| Index: components/ntp_tiles/icon_cacher_impl.cc
|
| diff --git a/components/ntp_tiles/icon_cacher_impl.cc b/components/ntp_tiles/icon_cacher_impl.cc
|
| index cb957ea010e58bcd9e70444e6dc578aed426c45e..39346e902ec7f2630a6e139cb0f5e0eb03d2296e 100644
|
| --- a/components/ntp_tiles/icon_cacher_impl.cc
|
| +++ b/components/ntp_tiles/icon_cacher_impl.cc
|
| @@ -8,6 +8,8 @@
|
|
|
| #include "components/favicon/core/favicon_service.h"
|
| #include "components/favicon/core/favicon_util.h"
|
| +#include "components/favicon/core/large_icon_service.h"
|
| +#include "components/favicon_base/fallback_icon_style.h"
|
| #include "components/favicon_base/favicon_types.h"
|
| #include "components/favicon_base/favicon_util.h"
|
| #include "components/image_fetcher/image_fetcher.h"
|
| @@ -28,12 +30,23 @@ const GURL& IconURL(const PopularSites::Site& site) {
|
| : site.favicon_url;
|
| }
|
|
|
| +bool LargeIconResultEmpty(const favicon_base::LargeIconResult& result) {
|
| + // We should not fetch anything if the cache already contains a favicon of any
|
| + // size and type. Any icon results either in a bitmap or in a non-default
|
| + // fallback color.
|
| + return (!result.bitmap.is_valid() &&
|
| + (!result.fallback_icon_style ||
|
| + result.fallback_icon_style->is_default_background_color));
|
| +}
|
| +
|
| } // namespace
|
|
|
| IconCacherImpl::IconCacherImpl(
|
| favicon::FaviconService* favicon_service,
|
| + favicon::LargeIconService* large_icon_service,
|
| std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher)
|
| : favicon_service_(favicon_service),
|
| + large_icon_service_(large_icon_service),
|
| image_fetcher_(std::move(image_fetcher)) {
|
| image_fetcher_->SetDataUseServiceName(
|
| data_use_measurement::DataUseUserData::NTP_TILES);
|
| @@ -41,8 +54,9 @@ IconCacherImpl::IconCacherImpl(
|
|
|
| IconCacherImpl::~IconCacherImpl() = default;
|
|
|
| -void IconCacherImpl::StartFetch(PopularSites::Site site,
|
| - const base::Callback<void(bool)>& done) {
|
| +void IconCacherImpl::StartFetchPopularSites(
|
| + PopularSites::Site site,
|
| + const base::Callback<void(bool)>& done) {
|
| favicon::GetFaviconImageForPageURL(
|
| favicon_service_, site.url, IconType(site),
|
| base::Bind(&IconCacherImpl::OnGetFaviconImageForPageURLFinished,
|
| @@ -61,14 +75,15 @@ void IconCacherImpl::OnGetFaviconImageForPageURLFinished(
|
|
|
| image_fetcher_->StartOrQueueNetworkRequest(
|
| std::string(), IconURL(site),
|
| - base::Bind(&IconCacherImpl::OnFaviconDownloaded, base::Unretained(this),
|
| - site, done));
|
| + base::Bind(&IconCacherImpl::OnPopularSitesFaviconDownloaded,
|
| + base::Unretained(this), site, done));
|
| }
|
|
|
| -void IconCacherImpl::OnFaviconDownloaded(PopularSites::Site site,
|
| - const base::Callback<void(bool)>& done,
|
| - const std::string& id,
|
| - const gfx::Image& fetched_image) {
|
| +void IconCacherImpl::OnPopularSitesFaviconDownloaded(
|
| + PopularSites::Site site,
|
| + const base::Callback<void(bool)>& done,
|
| + const std::string& id,
|
| + const gfx::Image& fetched_image) {
|
| if (fetched_image.IsEmpty()) {
|
| done.Run(false);
|
| return;
|
| @@ -80,4 +95,49 @@ void IconCacherImpl::OnFaviconDownloaded(PopularSites::Site site,
|
| done.Run(true);
|
| }
|
|
|
| +void IconCacherImpl::StartFetchMostLikely(
|
| + const GURL& page_url,
|
| + const base::Callback<void(bool)>& done) {
|
| + large_icon_service_->GetLargeIconOrFallbackStyle(
|
| + page_url, 48, 0,
|
| + base::Bind(&IconCacherImpl::OnGetLargeIconOrFallbackStyleFinished,
|
| + base::Unretained(this), page_url, done),
|
| + &tracker_);
|
| +}
|
| +
|
| +void IconCacherImpl::OnGetLargeIconOrFallbackStyleFinished(
|
| + const GURL& page_url,
|
| + const base::Callback<void(bool)>& done,
|
| + const favicon_base::LargeIconResult& result) {
|
| + if (!LargeIconResultEmpty(result)) {
|
| + DLOG(WARNING) << "large cache HIT for " << page_url.spec();
|
| + done.Run(false);
|
| + return;
|
| + }
|
| +
|
| + DLOG(WARNING) << "large cache MISS for " << page_url.spec();
|
| +
|
| + large_icon_service_
|
| + ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
|
| + page_url, 48, 0,
|
| + base::Bind(&IconCacherImpl::OnMostLikelyFaviconDownloaded,
|
| + base::Unretained(this), page_url, done),
|
| + &tracker_);
|
| +}
|
| +
|
| +void IconCacherImpl::OnMostLikelyFaviconDownloaded(
|
| + const GURL& page_url,
|
| + const base::Callback<void(bool)>& done,
|
| + const favicon_base::LargeIconResult& result) {
|
| + if (LargeIconResultEmpty(result)) {
|
| + DLOG(WARNING) << "large Google MISS for " << page_url.spec();
|
| + done.Run(false);
|
| + return;
|
| + }
|
| +
|
| + DLOG(WARNING) << "large Google HIT for " << page_url.spec();
|
| +
|
| + done.Run(true);
|
| +}
|
| +
|
| } // namespace ntp_tiles
|
|
|