Chromium Code Reviews| 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..580f0854ee800bb3b3ed7e0491ad5cab4abd9b8a 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); |
| + 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,29 @@ void ContentSuggestionsService::FetchSuggestionFavicon( |
| &favicons_task_tracker_); |
| } |
| +GURL ContentSuggestionsService::GetFaviconDomain( |
| + const ContentSuggestion::ID& suggestion_id) { |
| + const 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()) { |
| + return position->url_with_favicon(); |
| + } |
| + |
| + // Look up the URL in the archive of |remote_suggestions_provider_|. |
| + // TODO(jkrcal): Fix how Fetch more works or find other ways to remove this |
| + // hack. crbug.com/714031 |
| + if (providers_by_category_[suggestion_id.category()] == |
| + static_cast<ContentSuggestionsProvider*>(remote_suggestions_provider_)) { |
|
tschumann
2017/04/24 09:29:56
thinking of my comment from Friday, I don't think
jkrcal
2017/04/24 11:16:16
Good point, I slightly prefer the version without
|
| + return remote_suggestions_provider_->GetUrlWithFavicon(suggestion_id); |
| + } |
| + return GURL(); |
| +} |
| + |
| void ContentSuggestionsService::OnGetFaviconFromCacheFinished( |
| const GURL& publisher_url, |
| int minimum_size_in_pixel, |