| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const std::string& suggestion_id, | 54 const std::string& suggestion_id, |
| 55 const ImageFetchedCallback& callback) { | 55 const ImageFetchedCallback& callback) { |
| 56 if (!id_category_map_.count(suggestion_id)) { | 56 if (!id_category_map_.count(suggestion_id)) { |
| 57 LOG(WARNING) << "Requested image for unknown suggestion " << suggestion_id; | 57 LOG(WARNING) << "Requested image for unknown suggestion " << suggestion_id; |
| 58 callback.Run(suggestion_id, gfx::Image()); | 58 callback.Run(suggestion_id, gfx::Image()); |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 ContentSuggestionsCategory category = id_category_map_[suggestion_id]; | 61 ContentSuggestionsCategory category = id_category_map_[suggestion_id]; |
| 62 if (!providers_.count(category)) { | 62 if (!providers_.count(category)) { |
| 63 LOG(WARNING) << "Requested image for suggestion " << suggestion_id | 63 LOG(WARNING) << "Requested image for suggestion " << suggestion_id |
| 64 << " for unavailable category " << int(category); | 64 << " for unavailable category " << static_cast<int>(category); |
| 65 callback.Run(suggestion_id, gfx::Image()); | 65 callback.Run(suggestion_id, gfx::Image()); |
| 66 return; | 66 return; |
| 67 } | 67 } |
| 68 providers_[category]->FetchSuggestionImage(suggestion_id, callback); | 68 providers_[category]->FetchSuggestionImage(suggestion_id, callback); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging() { | 71 void ContentSuggestionsService::ClearCachedSuggestionsForDebugging() { |
| 72 suggestions_by_category_.clear(); | 72 suggestions_by_category_.clear(); |
| 73 id_category_map_.clear(); | 73 id_category_map_.clear(); |
| 74 for (auto& category_provider_pair : providers_) { | 74 for (auto& category_provider_pair : providers_) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 | 85 |
| 86 void ContentSuggestionsService::DiscardSuggestion( | 86 void ContentSuggestionsService::DiscardSuggestion( |
| 87 const std::string& suggestion_id) { | 87 const std::string& suggestion_id) { |
| 88 if (!id_category_map_.count(suggestion_id)) { | 88 if (!id_category_map_.count(suggestion_id)) { |
| 89 LOG(WARNING) << "Discarded unknown suggestion " << suggestion_id; | 89 LOG(WARNING) << "Discarded unknown suggestion " << suggestion_id; |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 ContentSuggestionsCategory category = id_category_map_[suggestion_id]; | 92 ContentSuggestionsCategory category = id_category_map_[suggestion_id]; |
| 93 if (!providers_.count(category)) { | 93 if (!providers_.count(category)) { |
| 94 LOG(WARNING) << "Discarded suggestion " << suggestion_id | 94 LOG(WARNING) << "Discarded suggestion " << suggestion_id |
| 95 << " for unavailable category " << int(category); | 95 << " for unavailable category " << static_cast<int>(category); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 providers_[category]->DiscardSuggestion(suggestion_id); | 98 providers_[category]->DiscardSuggestion(suggestion_id); |
| 99 | 99 |
| 100 // Remove the suggestion locally. | 100 // Remove the suggestion locally. |
| 101 id_category_map_.erase(suggestion_id); | 101 id_category_map_.erase(suggestion_id); |
| 102 std::vector<ContentSuggestion>* suggestions = | 102 std::vector<ContentSuggestion>* suggestions = |
| 103 &suggestions_by_category_[category]; | 103 &suggestions_by_category_[category]; |
| 104 auto position = | 104 auto position = |
| 105 std::find_if(suggestions->begin(), suggestions->end(), | 105 std::find_if(suggestions->begin(), suggestions->end(), |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 198 } |
| 199 | 199 |
| 200 void ContentSuggestionsService::NotifyCategoryStatusChanged( | 200 void ContentSuggestionsService::NotifyCategoryStatusChanged( |
| 201 ContentSuggestionsCategory category) { | 201 ContentSuggestionsCategory category) { |
| 202 FOR_EACH_OBSERVER( | 202 FOR_EACH_OBSERVER( |
| 203 Observer, observers_, | 203 Observer, observers_, |
| 204 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 204 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace ntp_snippets | 207 } // namespace ntp_snippets |
| OLD | NEW |