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

Unified Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2829963005: [Remote suggestions] Get favicon URLs from archive (Closed)
Patch Set: Tim's comments Created 3 years, 8 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
Index: components/ntp_snippets/content_suggestions_service.cc
diff --git a/components/ntp_snippets/content_suggestions_service.cc b/components/ntp_snippets/content_suggestions_service.cc
index 9a5f3fbbb36806f9f3701b724628905eeb88c0d2..4ffa67b71e73f248a6e9e94f94f1518ab6c09ef0 100644
--- a/components/ntp_snippets/content_suggestions_service.cc
+++ b/components/ntp_snippets/content_suggestions_service.cc
@@ -21,6 +21,7 @@
#include "components/favicon_base/fallback_icon_style.h"
#include "components/favicon_base/favicon_types.h"
#include "components/ntp_snippets/pref_names.h"
+#include "components/ntp_snippets/remote/remote_suggestions_provider.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "ui/gfx/image/image.h"
@@ -160,22 +161,14 @@ void ContentSuggestionsService::FetchSuggestionFavicon(
int minimum_size_in_pixel,
int desired_size_in_pixel,
const ImageFetchedCallback& callback) {
- std::vector<ContentSuggestion>* suggestions =
- &suggestions_by_category_[suggestion_id.category()];
- auto position =
- std::find_if(suggestions->begin(), suggestions->end(),
- [&suggestion_id](const ContentSuggestion& suggestion) {
- return suggestion_id == suggestion.id();
- });
- if (position == suggestions->end() || !large_icon_service_) {
+ const GURL& domain_with_favicon = GetFaviconDomain(suggestion_id);
vitaliii 2017/04/21 11:09:11 Since we started using "domain" in the naming, sho
tschumann 2017/04/21 11:23:58 please not in this CL ;-)
jkrcal 2017/04/21 13:30:54 Acknowledged.
+ if (!domain_with_favicon.is_valid() || !large_icon_service_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, gfx::Image()));
RecordFaviconFetchResult(FaviconFetchResult::FAILURE);
return;
}
- const GURL& domain_with_favicon = position->url_with_favicon();
-
// TODO(jkrcal): Create a general wrapper function in LargeIconService that
// does handle the get-from-cache-and-fallback-to-google-server functionality
// in one shot (for all clients that do not need to react in between).
@@ -188,6 +181,28 @@ void ContentSuggestionsService::FetchSuggestionFavicon(
&favicons_task_tracker_);
}
+GURL ContentSuggestionsService::GetFaviconDomain(
+ const ContentSuggestion::ID& suggestion_id) {
+ std::vector<ContentSuggestion>* suggestions =
tschumann 2017/04/21 11:23:58 nit: can we make this a const& instead?
jkrcal 2017/04/21 13:30:54 Done.
+ &suggestions_by_category_[suggestion_id.category()];
+ auto position =
+ std::find_if(suggestions->begin(), suggestions->end(),
+ [&suggestion_id](const ContentSuggestion& suggestion) {
+ return suggestion_id == suggestion.id();
+ });
+ if (position != suggestions->end()) {
+ return position->url_with_favicon();
+ }
+
+ if (remote_suggestions_provider_ &&
+ suggestion_id.category().IsKnownCategory(KnownCategories::ARTICLES)) {
+ // TODO(jkrcal): Fix how Fetch more works or find other ways to remove this
+ // hack. crbug.com/714031
+ return remote_suggestions_provider_->GetUrlWithFavicon(suggestion_id);
+ }
+ return GURL();
+}
+
void ContentSuggestionsService::OnGetFaviconFromCacheFinished(
const GURL& publisher_url,
int minimum_size_in_pixel,

Powered by Google App Engine
This is Rietveld 408576698