| 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..a15bf07d4df044b27acf62a0859c99f5e91a3bc6 100644
|
| --- a/components/ntp_tiles/icon_cacher_impl.cc
|
| +++ b/components/ntp_tiles/icon_cacher_impl.cc
|
| @@ -11,6 +11,7 @@
|
| #include "components/favicon_base/favicon_types.h"
|
| #include "components/favicon_base/favicon_util.h"
|
| #include "components/image_fetcher/image_fetcher.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/image/image.h"
|
| #include "url/gurl.h"
|
|
|
| @@ -41,43 +42,63 @@ IconCacherImpl::IconCacherImpl(
|
|
|
| IconCacherImpl::~IconCacherImpl() = default;
|
|
|
| -void IconCacherImpl::StartFetch(PopularSites::Site site,
|
| - const base::Callback<void(bool)>& done) {
|
| +void IconCacherImpl::StartFetch(
|
| + PopularSites::Site site,
|
| + const base::Callback<void(bool)>& icon_available) {
|
| favicon::GetFaviconImageForPageURL(
|
| favicon_service_, site.url, IconType(site),
|
| base::Bind(&IconCacherImpl::OnGetFaviconImageForPageURLFinished,
|
| - base::Unretained(this), std::move(site), done),
|
| + base::Unretained(this), std::move(site), icon_available),
|
| &tracker_);
|
| }
|
|
|
| void IconCacherImpl::OnGetFaviconImageForPageURLFinished(
|
| PopularSites::Site site,
|
| - const base::Callback<void(bool)>& done,
|
| + const base::Callback<void(bool)>& icon_available,
|
| const favicon_base::FaviconImageResult& result) {
|
| if (!result.image.IsEmpty()) {
|
| - done.Run(false);
|
| + icon_available.Run(false);
|
| return;
|
| }
|
|
|
| + if (ProvideDefaultIcon(site)) {
|
| + icon_available.Run(true);
|
| + // Don't return. We want to fetch to update possibly stale images.
|
| + }
|
| +
|
| image_fetcher_->StartOrQueueNetworkRequest(
|
| std::string(), IconURL(site),
|
| base::Bind(&IconCacherImpl::OnFaviconDownloaded, base::Unretained(this),
|
| - site, done));
|
| + site, icon_available));
|
| }
|
|
|
| -void IconCacherImpl::OnFaviconDownloaded(PopularSites::Site site,
|
| - const base::Callback<void(bool)>& done,
|
| - const std::string& id,
|
| - const gfx::Image& fetched_image) {
|
| +void IconCacherImpl::OnFaviconDownloaded(
|
| + PopularSites::Site site,
|
| + const base::Callback<void(bool)>& icon_available,
|
| + const std::string& id,
|
| + const gfx::Image& fetched_image) {
|
| if (fetched_image.IsEmpty()) {
|
| - done.Run(false);
|
| + icon_available.Run(false);
|
| return;
|
| }
|
|
|
| - gfx::Image image = fetched_image;
|
| + SaveIconForSite(site, fetched_image);
|
| + icon_available.Run(true);
|
| +}
|
| +
|
| +void IconCacherImpl::SaveIconForSite(const PopularSites::Site& site,
|
| + gfx::Image image) {
|
| favicon_base::SetFaviconColorSpace(&image);
|
| favicon_service_->SetFavicons(site.url, IconURL(site), IconType(site), image);
|
| - done.Run(true);
|
| +}
|
| +
|
| +bool IconCacherImpl::ProvideDefaultIcon(const PopularSites::Site& site) {
|
| + if (site.default_resource_id < 0) {
|
| + return false;
|
| + }
|
| + SaveIconForSite(site, ResourceBundle::GetSharedInstance().GetNativeImageNamed(
|
| + site.default_resource_id));
|
| + return true;
|
| }
|
|
|
| } // namespace ntp_tiles
|
|
|