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

Unified Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2244793002: Remove deleted offline page suggestions from opened NTPs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust MockContentSuggestionsProvider Created 4 years, 4 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 c71c8caa4c1b7978c092f956f0a9dbc2193e1b37..f9631e3115176f6361e628bb40c364a1c6d28394 100644
--- a/components/ntp_snippets/content_suggestions_service.cc
+++ b/components/ntp_snippets/content_suggestions_service.cc
@@ -135,19 +135,10 @@ void ContentSuggestionsService::DismissSuggestion(
providers_by_category_[category]->DismissSuggestion(suggestion_id);
// Remove the suggestion locally.
- id_category_map_.erase(suggestion_id);
- std::vector<ContentSuggestion>* suggestions =
- &suggestions_by_category_[category];
- auto position =
- std::find_if(suggestions->begin(), suggestions->end(),
- [&suggestion_id](const ContentSuggestion& suggestion) {
- return suggestion_id == suggestion.id();
- });
- DCHECK(position != suggestions->end())
- << "The dismissed suggestion " << suggestion_id
- << " has already been removed. Providers must not call OnNewSuggestions"
- " in response to DismissSuggestion.";
- suggestions->erase(position);
+ bool removed = RemoveSuggestionByID(category, suggestion_id);
+ DCHECK(removed) << "The dismissed suggestion " << suggestion_id
+ << " has already been removed. Providers must not call"
+ << " OnNewSuggestions in response to DismissSuggestion.";
}
void ContentSuggestionsService::AddObserver(Observer* observer) {
@@ -221,6 +212,15 @@ void ContentSuggestionsService::OnCategoryStatusChanged(
NotifyCategoryStatusChanged(category);
}
+void ContentSuggestionsService::OnSuggestionInvalidated(
+ ContentSuggestionsProvider* provider,
+ Category category,
+ const std::string& suggestion_id) {
+ RemoveSuggestionByID(category, suggestion_id);
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnSuggestionInvalidated(category, suggestion_id));
+}
+
bool ContentSuggestionsService::RegisterCategoryIfRequired(
ContentSuggestionsProvider* provider,
Category category) {
@@ -243,6 +243,23 @@ bool ContentSuggestionsService::RegisterCategoryIfRequired(
return true;
}
+bool ContentSuggestionsService::RemoveSuggestionByID(
+ Category category,
+ const std::string& suggestion_id) {
+ id_category_map_.erase(suggestion_id);
+ std::vector<ContentSuggestion>* suggestions =
+ &suggestions_by_category_[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 false;
+ suggestions->erase(position);
+ return true;
+}
+
void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) {
FOR_EACH_OBSERVER(
Observer, observers_,
« no previous file with comments | « components/ntp_snippets/content_suggestions_service.h ('k') | components/ntp_snippets/content_suggestions_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698