| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 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::ClearCachedSuggestionsForDebugging() { | 90 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging() { |
| 91 suggestions_by_category_.clear(); | 91 suggestions_by_category_.clear(); |
| 92 id_category_map_.clear(); | 92 id_category_map_.clear(); |
| 93 for (auto& category_provider_pair : providers_by_category_) { | 93 for (auto& category_provider_pair : providers_by_category_) { |
| 94 category_provider_pair.second->ClearCachedSuggestionsForDebugging(); | 94 category_provider_pair.second->ClearCachedSuggestionsForDebugging(); |
| 95 FOR_EACH_OBSERVER(Observer, observers_, |
| 96 OnNewSuggestions(category_provider_pair.first)); |
| 95 } | 97 } |
| 96 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); | |
| 97 } | 98 } |
| 98 | 99 |
| 99 void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging() { | 100 void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging() { |
| 100 for (auto& category_provider_pair : providers_by_category_) { | 101 for (auto& category_provider_pair : providers_by_category_) { |
| 101 category_provider_pair.second->ClearDismissedSuggestionsForDebugging(); | 102 category_provider_pair.second->ClearDismissedSuggestionsForDebugging(); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 void ContentSuggestionsService::DismissSuggestion( | 106 void ContentSuggestionsService::DismissSuggestion( |
| 106 const std::string& suggestion_id) { | 107 const std::string& suggestion_id) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 suggestions_by_category_[category]) { | 168 suggestions_by_category_[category]) { |
| 168 id_category_map_.erase(suggestion.id()); | 169 id_category_map_.erase(suggestion.id()); |
| 169 } | 170 } |
| 170 | 171 |
| 171 for (const ContentSuggestion& suggestion : new_suggestions) { | 172 for (const ContentSuggestion& suggestion : new_suggestions) { |
| 172 id_category_map_.insert(std::make_pair(suggestion.id(), category)); | 173 id_category_map_.insert(std::make_pair(suggestion.id(), category)); |
| 173 } | 174 } |
| 174 | 175 |
| 175 suggestions_by_category_[category] = std::move(new_suggestions); | 176 suggestions_by_category_[category] = std::move(new_suggestions); |
| 176 | 177 |
| 177 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); | 178 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions(category)); |
| 178 } | 179 } |
| 179 | 180 |
| 180 void ContentSuggestionsService::OnCategoryStatusChanged( | 181 void ContentSuggestionsService::OnCategoryStatusChanged( |
| 181 ContentSuggestionsProvider* provider, | 182 ContentSuggestionsProvider* provider, |
| 182 Category category, | 183 Category category, |
| 183 CategoryStatus new_status) { | 184 CategoryStatus new_status) { |
| 184 if (!IsCategoryStatusAvailable(new_status)) { | 185 if (!IsCategoryStatusAvailable(new_status)) { |
| 185 for (const ContentSuggestion& suggestion : | 186 for (const ContentSuggestion& suggestion : |
| 186 suggestions_by_category_[category]) { | 187 suggestions_by_category_[category]) { |
| 187 id_category_map_.erase(suggestion.id()); | 188 id_category_map_.erase(suggestion.id()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return true; | 225 return true; |
| 225 } | 226 } |
| 226 | 227 |
| 227 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { | 228 void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) { |
| 228 FOR_EACH_OBSERVER( | 229 FOR_EACH_OBSERVER( |
| 229 Observer, observers_, | 230 Observer, observers_, |
| 230 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 231 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
| 231 } | 232 } |
| 232 | 233 |
| 233 } // namespace ntp_snippets | 234 } // namespace ntp_snippets |
| OLD | NEW |