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

Unified Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2400783003: Ntp: show AllDismissedItem when all sections have been dismissed. (Closed)
Patch Set: Address comments from treib, add tests. Created 4 years, 2 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 f52a9809d09dcae42dbad4cd9a62ff9598870423..fb33daa6170d963e215bf9b3f9cdb3af23cdf74f 100644
--- a/components/ntp_snippets/content_suggestions_service.cc
+++ b/components/ntp_snippets/content_suggestions_service.cc
@@ -150,11 +150,25 @@ void ContentSuggestionsService::DismissCategory(Category category) {
if (providers_it == providers_by_category_.end())
return;
+ suggestions_by_category_[category].clear();
+ dismissed_providers_by_category_[providers_it->first] = providers_it->second;
providers_by_category_.erase(providers_it);
categories_.erase(
std::find(categories_.begin(), categories_.end(), category));
}
+void ContentSuggestionsService::RestoreDismissedCategories() {
+ // Make a copy as the original will be modified during iteration.
+ auto dismissed_providers_by_category_copy = dismissed_providers_by_category_;
+ for (const auto& category_provider_pair :
+ dismissed_providers_by_category_copy) {
+ RegisterCategoryIfRequired(category_provider_pair.second,
+ category_provider_pair.first);
+ }
+ DCHECK(dismissed_providers_by_category_.empty());
+ dismissed_providers_by_category_.clear();
Marc Treib 2016/10/11 15:29:24 nit: No need for this - we don't handle DCHECK fai
Michael van Ouwerkerk 2016/10/11 15:37:43 Done.
+}
+
void ContentSuggestionsService::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
@@ -274,6 +288,12 @@ bool ContentSuggestionsService::RegisterCategoryIfRequired(
return false;
}
+ auto dismissed_it = dismissed_providers_by_category_.find(category);
+ if (dismissed_it != dismissed_providers_by_category_.end()) {
+ DCHECK_EQ(dismissed_it->second, provider);
+ dismissed_providers_by_category_.erase(dismissed_it);
+ }
+
providers_by_category_[category] = provider;
categories_.push_back(category);
SortCategories();

Powered by Google App Engine
This is Rietveld 408576698