OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/ntp_snippets/content_suggestions_service.h" | 5 #include "components/ntp_snippets/content_suggestions_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 // Remove the suggestion locally. | 100 // Remove the suggestion locally. |
101 id_category_map_.erase(suggestion_id); | 101 id_category_map_.erase(suggestion_id); |
102 std::vector<ContentSuggestion>* suggestions = | 102 std::vector<ContentSuggestion>* suggestions = |
103 &suggestions_by_category_[category]; | 103 &suggestions_by_category_[category]; |
104 auto position = | 104 auto position = |
105 std::find_if(suggestions->begin(), suggestions->end(), | 105 std::find_if(suggestions->begin(), suggestions->end(), |
106 [&suggestion_id](const ContentSuggestion& suggestion) { | 106 [&suggestion_id](const ContentSuggestion& suggestion) { |
107 return suggestion_id == suggestion.id(); | 107 return suggestion_id == suggestion.id(); |
108 }); | 108 }); |
109 DCHECK(position != suggestions->end()); | 109 DCHECK(position != suggestions->end()) |
| 110 << "The discarded suggestion " << suggestion_id |
| 111 << " has already been removed. Providers must not call OnNewSuggestions" |
| 112 " in response to DiscardSuggestion."; |
110 suggestions->erase(position); | 113 suggestions->erase(position); |
111 } | 114 } |
112 | 115 |
113 void ContentSuggestionsService::AddObserver(Observer* observer) { | 116 void ContentSuggestionsService::AddObserver(Observer* observer) { |
114 observers_.AddObserver(observer); | 117 observers_.AddObserver(observer); |
115 } | 118 } |
116 | 119 |
117 void ContentSuggestionsService::RemoveObserver(Observer* observer) { | 120 void ContentSuggestionsService::RemoveObserver(Observer* observer) { |
118 observers_.RemoveObserver(observer); | 121 observers_.RemoveObserver(observer); |
119 } | 122 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } | 201 } |
199 | 202 |
200 void ContentSuggestionsService::NotifyCategoryStatusChanged( | 203 void ContentSuggestionsService::NotifyCategoryStatusChanged( |
201 ContentSuggestionsCategory category) { | 204 ContentSuggestionsCategory category) { |
202 FOR_EACH_OBSERVER( | 205 FOR_EACH_OBSERVER( |
203 Observer, observers_, | 206 Observer, observers_, |
204 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 207 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
205 } | 208 } |
206 | 209 |
207 } // namespace ntp_snippets | 210 } // namespace ntp_snippets |
OLD | NEW |