Chromium Code Reviews| Index: components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc |
| diff --git a/components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc b/components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc |
| index 0cafdb352d7a83bbcc835a0ad6e3032f433c6a0c..4cf9c601e927921dcb84d7c7db1d81d4adcb2d24 100644 |
| --- a/components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc |
| +++ b/components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc |
| @@ -7,6 +7,7 @@ |
| #include <vector> |
| #include "base/bind.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "components/ntp_snippets/category.h" |
| @@ -146,17 +147,7 @@ void ReadingListSuggestionsProvider::FetchReadingListInternal() { |
| std::vector<ContentSuggestion> suggestions; |
| for (const ReadingListEntry* entry : entries) { |
| - ContentSuggestion suggestion(provided_category_, entry->URL().spec(), |
| - entry->URL()); |
| - |
| - if (entry->Title().size() > 0) { |
| - suggestion.set_title(base::UTF8ToUTF16(entry->Title())); |
| - } else { |
| - suggestion.set_title(url_formatter::FormatUrl(entry->URL())); |
| - } |
| - suggestion.set_snippet_text( |
| - url_formatter::FormatUrl(entry->URL().GetOrigin())); |
| - suggestions.emplace_back(std::move(suggestion)); |
| + ConvertEntry(entry, &suggestions); |
| } |
| NotifyStatusChanged(CategoryStatus::AVAILABLE); |
| @@ -164,6 +155,37 @@ void ReadingListSuggestionsProvider::FetchReadingListInternal() { |
| std::move(suggestions)); |
| } |
| +void ReadingListSuggestionsProvider::ConvertEntry( |
| + const ReadingListEntry* entry, |
| + std::vector<ContentSuggestion>* suggestions) { |
|
Marc Treib
2017/03/28 13:38:20
I don't like out params, and IMO converting has li
gambard
2017/03/29 06:51:24
That was my first idea, but I followed the pattern
|
| + ContentSuggestion suggestion(provided_category_, entry->URL().spec(), |
| + entry->URL()); |
| + if (entry->Title().size() > 0) { |
| + suggestion.set_title(base::UTF8ToUTF16(entry->Title())); |
| + } else { |
| + suggestion.set_title(url_formatter::FormatUrl(entry->URL())); |
| + } |
| + suggestion.set_snippet_text( |
| + url_formatter::FormatUrl(entry->URL().GetOrigin())); |
| + |
| + auto extra = base::MakeUnique<ReadingListSuggestionExtra>(); |
| + if (entry->DistilledState() == ReadingListEntry::PROCESSED) { |
|
Marc Treib
2017/03/28 13:38:20
switch?
Wrap this in a global helper method?
Olivier
2017/03/28 13:43:45
switch?
gambard
2017/03/29 06:51:24
Done.
gambard
2017/03/29 06:51:24
Done.
|
| + extra->distilled_state = ReadingListSuggestionExtra:: |
| + ReadingListSuggestionDistilledState::SUCCESS; |
| + } else if (entry->DistilledState() == ReadingListEntry::DISTILLATION_ERROR) { |
| + extra->distilled_state = ReadingListSuggestionExtra:: |
| + ReadingListSuggestionDistilledState::FAILURE; |
| + } else { |
| + extra->distilled_state = ReadingListSuggestionExtra:: |
| + ReadingListSuggestionDistilledState::PROCESSING; |
| + } |
| + extra->favicon_page_url = |
| + entry->DistilledURL().is_valid() ? entry->DistilledURL() : entry->URL(); |
| + suggestion.set_reading_list_suggestion_extra(std::move(extra)); |
| + |
| + suggestions->emplace_back(std::move(suggestion)); |
| +} |
| + |
| void ReadingListSuggestionsProvider::NotifyStatusChanged( |
| CategoryStatus new_status) { |
| if (category_status_ == new_status) { |