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 7b23609c6a01f0babb79428bd55cb676c26393ac..3059437c9e3479ccd30d8294bfd17ab3dc177297 100644 |
--- a/components/ntp_snippets/content_suggestions_service.cc |
+++ b/components/ntp_snippets/content_suggestions_service.cc |
@@ -141,19 +141,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) { |
@@ -227,6 +218,16 @@ void ContentSuggestionsService::OnCategoryStatusChanged( |
NotifyCategoryStatusChanged(category); |
} |
+void ContentSuggestionsService::OnSuggestionInvalidated( |
+ ContentSuggestionsProvider* provider, |
+ Category category, |
+ const std::string& suggestion_id) { |
+ if (RemoveSuggestionByID(category, suggestion_id)) { |
+ FOR_EACH_OBSERVER(Observer, observers_, |
Marc Treib
2016/08/16 09:03:53
Wouldn't we want to send the invalidation anyway?
Philipp Keck
2016/08/16 10:54:40
Yes, right. Done.
|
+ OnSuggestionInvalidated(category, suggestion_id)); |
+ } |
+} |
+ |
bool ContentSuggestionsService::RegisterCategoryIfRequired( |
ContentSuggestionsProvider* provider, |
Category category) { |
@@ -249,6 +250,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_, |