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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 providers_.push_back(std::move(provider)); | 195 providers_.push_back(std::move(provider)); |
196 } | 196 } |
197 | 197 |
198 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
199 // Private methods | 199 // Private methods |
200 | 200 |
201 void ContentSuggestionsService::OnNewSuggestions( | 201 void ContentSuggestionsService::OnNewSuggestions( |
202 ContentSuggestionsProvider* provider, | 202 ContentSuggestionsProvider* provider, |
203 Category category, | 203 Category category, |
204 std::vector<ContentSuggestion> suggestions) { | 204 std::vector<ContentSuggestion> suggestions) { |
| 205 // Providers shouldn't call this when they're in a non-available state. |
| 206 DCHECK( |
| 207 IsCategoryStatusInitOrAvailable(provider->GetCategoryStatus(category))); |
| 208 |
205 if (TryRegisterProviderForCategory(provider, category)) { | 209 if (TryRegisterProviderForCategory(provider, category)) { |
206 NotifyCategoryStatusChanged(category); | 210 NotifyCategoryStatusChanged(category); |
207 } else if (IsCategoryDismissed(category)) { | 211 } else if (IsCategoryDismissed(category)) { |
208 // The category has been registered as a dismissed one. We need to | 212 // The category has been registered as a dismissed one. We need to |
209 // check if the dismissal can be cleared now that we received new data. | 213 // check if the dismissal can be cleared now that we received new data. |
210 if (suggestions.empty()) | 214 if (suggestions.empty()) |
211 return; | 215 return; |
212 | 216 |
213 RestoreDismissedCategory(category); | 217 RestoreDismissedCategory(category); |
214 StoreDismissedCategoriesToPrefs(); | 218 StoreDismissedCategoriesToPrefs(); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { | 428 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { |
425 base::ListValue list; | 429 base::ListValue list; |
426 for (const auto& category_provider_pair : dismissed_providers_by_category_) { | 430 for (const auto& category_provider_pair : dismissed_providers_by_category_) { |
427 list.AppendInteger(category_provider_pair.first.id()); | 431 list.AppendInteger(category_provider_pair.first.id()); |
428 } | 432 } |
429 | 433 |
430 pref_service_->Set(prefs::kDismissedCategories, list); | 434 pref_service_->Set(prefs::kDismissedCategories, list); |
431 } | 435 } |
432 | 436 |
433 } // namespace ntp_snippets | 437 } // namespace ntp_snippets |
OLD | NEW |