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

Unified Diff: components/ntp_tiles/icon_cacher_impl.cc

Issue 2695713004: Add baked-in favicons for default popular sites on NTP (Closed)
Patch Set: Fix iOS images and resize only if necessary. Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_tiles/icon_cacher_impl.h ('k') | components/ntp_tiles/icon_cacher_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « components/ntp_tiles/icon_cacher_impl.h ('k') | components/ntp_tiles/icon_cacher_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698