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 223257baf68b02284c7f859a6ecfbcec3e017ad0..12af0a423f6ffcd3828d2b7df2122d401f79a4ae 100644 |
| --- a/components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc |
| +++ b/components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc |
| @@ -70,7 +70,9 @@ CategoryInfo ReadingListSuggestionsProvider::GetCategoryInfo( |
| void ReadingListSuggestionsProvider::DismissSuggestion( |
| const ContentSuggestion::ID& suggestion_id) { |
| - // TODO(crbug.com/702241): Implement this method. |
| + DCHECK(reading_list_model_->loaded()); |
| + GURL url(suggestion_id.id_within_category()); |
| + SetDismissedState(url, true); |
| } |
| void ReadingListSuggestionsProvider::FetchSuggestionImage( |
| @@ -98,7 +100,7 @@ void ReadingListSuggestionsProvider::ClearHistory( |
| base::Time begin, |
| base::Time end, |
| const base::Callback<bool(const GURL& url)>& filter) { |
| - // TODO(crbug.com/702241): Implement this method. |
| + // Ignored, Reading List does not depend on history. |
| } |
| void ReadingListSuggestionsProvider::ClearCachedSuggestions(Category category) { |
| @@ -109,11 +111,34 @@ void ReadingListSuggestionsProvider::ClearCachedSuggestions(Category category) { |
| void ReadingListSuggestionsProvider::GetDismissedSuggestionsForDebugging( |
| Category category, |
| const DismissedSuggestionsCallback& callback) { |
| - // TODO(crbug.com/702241): Implement this method. |
| + if (!reading_list_model_ || reading_list_model_->IsPerformingBatchUpdates()) { |
|
Marc Treib
2017/04/11 13:41:09
Can reading_list_model_ be null?
gambard
2017/04/11 15:01:18
Yes. Looks at ReadingListSuggestionsProvider::Read
|
| + return; |
|
Marc Treib
2017/04/11 13:41:09
Should probably still call the callback with an em
gambard
2017/04/11 15:01:18
Done.
|
| + } |
| + |
| + DCHECK(reading_list_model_->loaded()); |
| + std::vector<const ReadingListEntry*> entries; |
| + for (const GURL& url : reading_list_model_->Keys()) { |
| + const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| + if (entry->ContentSuggestionsExtra()->dismissed) { |
| + entries.emplace_back(entry); |
| + } |
| + } |
| + |
| + std::sort(entries.begin(), entries.end(), CompareEntries); |
| + |
| + std::vector<ContentSuggestion> suggestions; |
| + for (const ReadingListEntry* entry : entries) { |
| + suggestions.emplace_back(ConvertEntry(entry)); |
| + } |
| + |
| + callback.Run(std::vector<ContentSuggestion>()); |
| } |
| + |
| void ReadingListSuggestionsProvider::ClearDismissedSuggestionsForDebugging( |
| Category category) { |
| - // TODO(crbug.com/702241): Implement this method. |
| + for (const auto& url : reading_list_model_->Keys()) { |
| + SetDismissedState(url, false); |
| + } |
| } |
| void ReadingListSuggestionsProvider::ReadingListModelLoaded( |
| @@ -152,7 +177,7 @@ void ReadingListSuggestionsProvider::FetchReadingListInternal() { |
| std::vector<const ReadingListEntry*> entries; |
| for (const GURL& url : reading_list_model_->Keys()) { |
| const ReadingListEntry* entry = reading_list_model_->GetEntryByURL(url); |
| - if (!entry->IsRead()) { |
| + if (!entry->IsRead() && !entry->ContentSuggestionsExtra()->dismissed) { |
| entries.emplace_back(entry); |
| } |
| } |
| @@ -208,4 +233,11 @@ void ReadingListSuggestionsProvider::NotifyStatusChanged( |
| observer()->OnCategoryStatusChanged(this, provided_category_, new_status); |
| } |
| +void ReadingListSuggestionsProvider::SetDismissedState(const GURL& url, |
| + bool dismissed) { |
| + reading_list::ContentSuggestionsExtra extra; |
| + extra.dismissed = dismissed; |
| + reading_list_model_->SetContentSuggestionsExtra(url, extra); |
| +} |
| + |
| } // namespace ntp_snippets |