Chromium Code Reviews| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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)); |
| 156 } | 157 } |
| 157 | 158 |
| 159 void ContentSuggestionsService::RestoreDismissedCategories() { | |
| 160 for (const auto& category_provider_pair : dismissed_providers_by_category_) | |
|
Marc Treib
2016/10/11 07:35:58
Braces if the body doesn't fit on one line.
Michael van Ouwerkerk
2016/10/11 12:04:16
Done.
| |
| 161 RegisterCategoryIfRequired(category_provider_pair.second, | |
| 162 category_provider_pair.first); | |
| 163 dismissed_providers_by_category_.clear(); | |
|
Marc Treib
2016/10/11 07:35:58
Should RegisterCategoryIfRequired remove the entry
Michael van Ouwerkerk
2016/10/11 12:04:16
Done.
| |
| 164 } | |
| 165 | |
| 158 void ContentSuggestionsService::AddObserver(Observer* observer) { | 166 void ContentSuggestionsService::AddObserver(Observer* observer) { |
| 159 observers_.AddObserver(observer); | 167 observers_.AddObserver(observer); |
| 160 } | 168 } |
| 161 | 169 |
| 162 void ContentSuggestionsService::RemoveObserver(Observer* observer) { | 170 void ContentSuggestionsService::RemoveObserver(Observer* observer) { |
| 163 observers_.RemoveObserver(observer); | 171 observers_.RemoveObserver(observer); |
| 164 } | 172 } |
| 165 | 173 |
| 166 void ContentSuggestionsService::RegisterProvider( | 174 void ContentSuggestionsService::RegisterProvider( |
| 167 std::unique_ptr<ContentSuggestionsProvider> provider) { | 175 std::unique_ptr<ContentSuggestionsProvider> provider) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 if (left.IsKnownCategory(KnownCategories::BOOKMARKS)) | 333 if (left.IsKnownCategory(KnownCategories::BOOKMARKS)) |
| 326 return false; | 334 return false; |
| 327 if (right.IsKnownCategory(KnownCategories::BOOKMARKS)) | 335 if (right.IsKnownCategory(KnownCategories::BOOKMARKS)) |
| 328 return true; | 336 return true; |
| 329 } | 337 } |
| 330 return category_factory_.CompareCategories(left, right); | 338 return category_factory_.CompareCategories(left, right); |
| 331 }); | 339 }); |
| 332 } | 340 } |
| 333 | 341 |
| 334 } // namespace ntp_snippets | 342 } // namespace ntp_snippets |
| OLD | NEW |