| 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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // Private methods | 180 // Private methods |
| 181 | 181 |
| 182 void ContentSuggestionsService::OnNewSuggestions( | 182 void ContentSuggestionsService::OnNewSuggestions( |
| 183 ContentSuggestionsProvider* provider, | 183 ContentSuggestionsProvider* provider, |
| 184 Category category, | 184 Category category, |
| 185 std::vector<ContentSuggestion> new_suggestions) { | 185 std::vector<ContentSuggestion> new_suggestions) { |
| 186 if (RegisterCategoryIfRequired(provider, category)) { | 186 if (RegisterCategoryIfRequired(provider, category)) { |
| 187 NotifyCategoryStatusChanged(category); | 187 NotifyCategoryStatusChanged(category); |
| 188 } | 188 } |
| 189 | 189 |
| 190 if (!IsCategoryStatusAvailable(provider->GetCategoryStatus(category))) { |
| 191 return; |
| 192 } |
| 193 |
| 190 for (const ContentSuggestion& suggestion : | 194 for (const ContentSuggestion& suggestion : |
| 191 suggestions_by_category_[category]) { | 195 suggestions_by_category_[category]) { |
| 192 id_category_map_.erase(suggestion.id()); | 196 id_category_map_.erase(suggestion.id()); |
| 193 } | 197 } |
| 194 | 198 |
| 195 for (const ContentSuggestion& suggestion : new_suggestions) { | 199 for (const ContentSuggestion& suggestion : new_suggestions) { |
| 196 id_category_map_.insert(std::make_pair(suggestion.id(), category)); | 200 id_category_map_.insert(std::make_pair(suggestion.id(), category)); |
| 197 } | 201 } |
| 198 | 202 |
| 199 suggestions_by_category_[category] = std::move(new_suggestions); | 203 suggestions_by_category_[category] = std::move(new_suggestions); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 return true; | 252 return true; |
| 249 } | 253 } |
| 250 | 254 |
| 251 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { | 255 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { |
| 252 FOR_EACH_OBSERVER( | 256 FOR_EACH_OBSERVER( |
| 253 Observer, observers_, | 257 Observer, observers_, |
| 254 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 258 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
| 255 } | 259 } |
| 256 | 260 |
| 257 } // namespace ntp_snippets | 261 } // namespace ntp_snippets |
| OLD | NEW |