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

Unified Diff: components/ntp_snippets/reading_list/reading_list_suggestions_provider.cc

Issue 2815623002: ReadingListProvider handles dismissal (Closed)
Patch Set: Address 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/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..ed11ed83fda216959320eacb6d952f6d8d206de4 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,13 @@ CategoryInfo ReadingListSuggestionsProvider::GetCategoryInfo(
void ReadingListSuggestionsProvider::DismissSuggestion(
const ContentSuggestion::ID& suggestion_id) {
- // TODO(crbug.com/702241): Implement this method.
+ if (!reading_list_model_) {
+ return;
+ }
+
+ DCHECK(reading_list_model_->loaded());
+ GURL url(suggestion_id.id_within_category());
+ SetDismissedState(url, true);
}
void ReadingListSuggestionsProvider::FetchSuggestionImage(
@@ -98,7 +104,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 +115,35 @@ 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()) {
+ callback.Run(std::vector<ContentSuggestion>());
+ return;
+ }
+
+ 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::move(suggestions));
}
+
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 +182,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 +238,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

Powered by Google App Engine
This is Rietveld 408576698