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 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 void ContentSuggestionsService::DismissSuggestion( | 160 void ContentSuggestionsService::DismissSuggestion( |
161 const ContentSuggestion::ID& suggestion_id) { | 161 const ContentSuggestion::ID& suggestion_id) { |
162 if (!providers_by_category_.count(suggestion_id.category())) { | 162 if (!providers_by_category_.count(suggestion_id.category())) { |
163 LOG(WARNING) << "Dismissed suggestion " << suggestion_id | 163 LOG(WARNING) << "Dismissed suggestion " << suggestion_id |
164 << " for unavailable category " << suggestion_id.category(); | 164 << " for unavailable category " << suggestion_id.category(); |
165 return; | 165 return; |
166 } | 166 } |
167 providers_by_category_[suggestion_id.category()]->DismissSuggestion( | 167 providers_by_category_[suggestion_id.category()]->DismissSuggestion( |
168 suggestion_id); | 168 suggestion_id); |
169 | 169 |
170 // Remove the suggestion locally. | 170 // Remove the suggestion locally if it is present. A suggestion may be missing |
171 bool removed = RemoveSuggestionByID(suggestion_id); | 171 // localy e.g. if it was sent to UI through |Fetch| or it has been dismissed |
172 DCHECK(removed) << "The dismissed suggestion " << suggestion_id | 172 // from a different NTP. |
173 << " has already been removed. Providers must not call" | 173 RemoveSuggestionByID(suggestion_id); |
174 << " OnNewSuggestions in response to DismissSuggestion."; | |
175 } | 174 } |
176 | 175 |
177 void ContentSuggestionsService::DismissCategory(Category category) { | 176 void ContentSuggestionsService::DismissCategory(Category category) { |
178 auto providers_it = providers_by_category_.find(category); | 177 auto providers_it = providers_by_category_.find(category); |
179 if (providers_it == providers_by_category_.end()) { | 178 if (providers_it == providers_by_category_.end()) { |
180 return; | 179 return; |
181 } | 180 } |
182 | 181 |
183 ContentSuggestionsProvider* provider = providers_it->second; | 182 ContentSuggestionsProvider* provider = providers_it->second; |
184 UnregisterCategory(category, provider); | 183 UnregisterCategory(category, provider); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 494 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
496 base::ListValue list; | 495 base::ListValue list; |
497 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 496 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
498 list.AppendInteger(category_provider_pair.first.id()); | 497 list.AppendInteger(category_provider_pair.first.id()); |
499 } | 498 } |
500 | 499 |
501 pref_service_->Set(prefs::kDismissedCategories, list); | 500 pref_service_->Set(prefs::kDismissedCategories, list); |
502 } | 501 } |
503 | 502 |
504 } // namespace ntp_snippets | 503 } // namespace ntp_snippets |
OLD | NEW |