| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 providers_by_category_[category]->FetchSuggestionImage(suggestion_id, | 86 providers_by_category_[category]->FetchSuggestionImage(suggestion_id, |
| 87 callback); | 87 callback); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void ContentSuggestionsService::ClearAllCachedSuggestionsForDebugging() { | 90 void ContentSuggestionsService::ClearAllCachedSuggestionsForDebugging() { |
| 91 suggestions_by_category_.clear(); | 91 suggestions_by_category_.clear(); |
| 92 id_category_map_.clear(); | 92 id_category_map_.clear(); |
| 93 for (const auto& category_provider_pair : providers_by_category_) { | 93 for (const auto& category_provider_pair : providers_by_category_) { |
| 94 category_provider_pair.second->ClearCachedSuggestionsForDebugging( | 94 category_provider_pair.second->ClearCachedSuggestionsForDebugging( |
| 95 category_provider_pair.first); | 95 category_provider_pair.first); |
| 96 FOR_EACH_OBSERVER(Observer, observers_, |
| 97 OnNewSuggestions(category_provider_pair.first)); |
| 96 } | 98 } |
| 97 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); | |
| 98 } | 99 } |
| 99 | 100 |
| 100 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging( | 101 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging( |
| 101 Category category) { | 102 Category category) { |
| 102 for (const ContentSuggestion& suggestion : | 103 for (const ContentSuggestion& suggestion : |
| 103 suggestions_by_category_[category]) { | 104 suggestions_by_category_[category]) { |
| 104 id_category_map_.erase(suggestion.id()); | 105 id_category_map_.erase(suggestion.id()); |
| 105 } | 106 } |
| 106 suggestions_by_category_[category].clear(); | 107 suggestions_by_category_[category].clear(); |
| 107 auto iterator = providers_by_category_.find(category); | 108 auto iterator = providers_by_category_.find(category); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 suggestions_by_category_[category]) { | 191 suggestions_by_category_[category]) { |
| 191 id_category_map_.erase(suggestion.id()); | 192 id_category_map_.erase(suggestion.id()); |
| 192 } | 193 } |
| 193 | 194 |
| 194 for (const ContentSuggestion& suggestion : new_suggestions) { | 195 for (const ContentSuggestion& suggestion : new_suggestions) { |
| 195 id_category_map_.insert(std::make_pair(suggestion.id(), category)); | 196 id_category_map_.insert(std::make_pair(suggestion.id(), category)); |
| 196 } | 197 } |
| 197 | 198 |
| 198 suggestions_by_category_[category] = std::move(new_suggestions); | 199 suggestions_by_category_[category] = std::move(new_suggestions); |
| 199 | 200 |
| 200 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); | 201 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category)); |
| 201 } | 202 } |
| 202 | 203 |
| 203 void ContentSuggestionsService::OnCategoryStatusChanged( | 204 void ContentSuggestionsService::OnCategoryStatusChanged( |
| 204 ContentSuggestionsProvider* provider, | 205 ContentSuggestionsProvider* provider, |
| 205 Category category, | 206 Category category, |
| 206 CategoryStatus new_status) { | 207 CategoryStatus new_status) { |
| 207 if (!IsCategoryStatusAvailable(new_status)) { | 208 if (!IsCategoryStatusAvailable(new_status)) { |
| 208 for (const ContentSuggestion& suggestion : | 209 for (const ContentSuggestion& suggestion : |
| 209 suggestions_by_category_[category]) { | 210 suggestions_by_category_[category]) { |
| 210 id_category_map_.erase(suggestion.id()); | 211 id_category_map_.erase(suggestion.id()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 return true; | 248 return true; |
| 248 } | 249 } |
| 249 | 250 |
| 250 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { | 251 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { |
| 251 FOR_EACH_OBSERVER( | 252 FOR_EACH_OBSERVER( |
| 252 Observer, observers_, | 253 Observer, observers_, |
| 253 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 254 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
| 254 } | 255 } |
| 255 | 256 |
| 256 } // namespace ntp_snippets | 257 } // namespace ntp_snippets |
| OLD | NEW |