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

Side by Side Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2560783002: [NTP::PhysicalWeb] Implement suggestion dismissal. (Closed)
Patch Set: bauerb@ comment. Created 4 years 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 unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698