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

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

Issue 2400783003: Ntp: show AllDismissedItem when all sections have been dismissed. (Closed)
Patch Set: Address review comments. Created 4 years, 2 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 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 DCHECK(removed) << "The dismissed suggestion " << suggestion_id 143 DCHECK(removed) << "The dismissed suggestion " << suggestion_id
144 << " has already been removed. Providers must not call" 144 << " has already been removed. Providers must not call"
145 << " OnNewSuggestions in response to DismissSuggestion."; 145 << " OnNewSuggestions in response to DismissSuggestion.";
146 } 146 }
147 147
148 void ContentSuggestionsService::DismissCategory(Category category) { 148 void ContentSuggestionsService::DismissCategory(Category category) {
149 auto providers_it = providers_by_category_.find(category); 149 auto providers_it = providers_by_category_.find(category);
150 if (providers_it == providers_by_category_.end()) 150 if (providers_it == providers_by_category_.end())
151 return; 151 return;
152 152
153 dismissed_providers_by_category_[providers_it->first] = providers_it->second;
153 providers_by_category_.erase(providers_it); 154 providers_by_category_.erase(providers_it);
154 categories_.erase( 155 categories_.erase(
155 std::find(categories_.begin(), categories_.end(), category)); 156 std::find(categories_.begin(), categories_.end(), category));
Marc Treib 2016/10/11 12:18:14 I think we agreed to also clear suggestions_by_cat
Michael van Ouwerkerk 2016/10/11 15:21:31 Done.
156 } 157 }
157 158
159 void ContentSuggestionsService::RestoreDismissedCategories() {
160 auto dismissed_providers_by_category_copy = dismissed_providers_by_category_;
Marc Treib 2016/10/11 12:18:14 nit: Add a comment on why the copy is needed?
Michael van Ouwerkerk 2016/10/11 15:21:31 Done.
161 for (const auto& category_provider_pair :
162 dismissed_providers_by_category_copy) {
163 RegisterCategoryIfRequired(category_provider_pair.second,
164 category_provider_pair.first);
165 }
166 dismissed_providers_by_category_.clear();
Marc Treib 2016/10/11 12:18:15 Now it should already be empty at this point, righ
Michael van Ouwerkerk 2016/10/11 15:21:31 Done.
167 }
168
158 void ContentSuggestionsService::AddObserver(Observer* observer) { 169 void ContentSuggestionsService::AddObserver(Observer* observer) {
159 observers_.AddObserver(observer); 170 observers_.AddObserver(observer);
160 } 171 }
161 172
162 void ContentSuggestionsService::RemoveObserver(Observer* observer) { 173 void ContentSuggestionsService::RemoveObserver(Observer* observer) {
163 observers_.RemoveObserver(observer); 174 observers_.RemoveObserver(observer);
164 } 175 }
165 176
166 void ContentSuggestionsService::RegisterProvider( 177 void ContentSuggestionsService::RegisterProvider(
167 std::unique_ptr<ContentSuggestionsProvider> provider) { 178 std::unique_ptr<ContentSuggestionsProvider> provider) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 278
268 bool ContentSuggestionsService::RegisterCategoryIfRequired( 279 bool ContentSuggestionsService::RegisterCategoryIfRequired(
269 ContentSuggestionsProvider* provider, 280 ContentSuggestionsProvider* provider,
270 Category category) { 281 Category category) {
271 auto it = providers_by_category_.find(category); 282 auto it = providers_by_category_.find(category);
272 if (it != providers_by_category_.end()) { 283 if (it != providers_by_category_.end()) {
273 DCHECK_EQ(it->second, provider); 284 DCHECK_EQ(it->second, provider);
274 return false; 285 return false;
275 } 286 }
276 287
288 auto dismissed_it = dismissed_providers_by_category_.find(category);
289 if (dismissed_it != dismissed_providers_by_category_.end()) {
290 DCHECK_EQ(dismissed_it->second, provider);
291 dismissed_providers_by_category_.erase(dismissed_it);
292 }
293
277 providers_by_category_[category] = provider; 294 providers_by_category_[category] = provider;
278 categories_.push_back(category); 295 categories_.push_back(category);
279 SortCategories(); 296 SortCategories();
280 if (IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) { 297 if (IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) {
281 suggestions_by_category_.insert( 298 suggestions_by_category_.insert(
282 std::make_pair(category, std::vector<ContentSuggestion>())); 299 std::make_pair(category, std::vector<ContentSuggestion>()));
283 } 300 }
284 return true; 301 return true;
285 } 302 }
286 303
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if (left.IsKnownCategory(KnownCategories::BOOKMARKS)) 342 if (left.IsKnownCategory(KnownCategories::BOOKMARKS))
326 return false; 343 return false;
327 if (right.IsKnownCategory(KnownCategories::BOOKMARKS)) 344 if (right.IsKnownCategory(KnownCategories::BOOKMARKS))
328 return true; 345 return true;
329 } 346 }
330 return category_factory_.CompareCategories(left, right); 347 return category_factory_.CompareCategories(left, right);
331 }); 348 });
332 } 349 }
333 350
334 } // namespace ntp_snippets 351 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698