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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_) { |
75 category_provider_pair.second->ClearCachedSuggestionsForDebugging(); | 75 category_provider_pair.second->ClearCachedSuggestionsForDebugging(); |
76 } | 76 } |
77 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); | 77 FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions()); |
78 } | 78 } |
79 | 79 |
80 void ContentSuggestionsService::ClearDiscardedSuggestionsForDebugging() { | 80 void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging() { |
81 for (auto& category_provider_pair : providers_) { | 81 for (auto& category_provider_pair : providers_) { |
82 category_provider_pair.second->ClearDiscardedSuggestionsForDebugging(); | 82 category_provider_pair.second->ClearDismissedSuggestionsForDebugging(); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 void ContentSuggestionsService::DiscardSuggestion( | 86 void ContentSuggestionsService::DismissSuggestion( |
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) << "Dismissed 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) << "Dismissed suggestion " << suggestion_id |
95 << " for unavailable category " << static_cast<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]->DismissSuggestion(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(), |
106 [&suggestion_id](const ContentSuggestion& suggestion) { | 106 [&suggestion_id](const ContentSuggestion& suggestion) { |
107 return suggestion_id == suggestion.id(); | 107 return suggestion_id == suggestion.id(); |
108 }); | 108 }); |
109 DCHECK(position != suggestions->end()) | 109 DCHECK(position != suggestions->end()) |
110 << "The discarded suggestion " << suggestion_id | 110 << "The dismissed suggestion " << suggestion_id |
111 << " has already been removed. Providers must not call OnNewSuggestions" | 111 << " has already been removed. Providers must not call OnNewSuggestions" |
112 " in response to DiscardSuggestion."; | 112 " in response to DismissSuggestion."; |
113 suggestions->erase(position); | 113 suggestions->erase(position); |
114 } | 114 } |
115 | 115 |
116 void ContentSuggestionsService::AddObserver(Observer* observer) { | 116 void ContentSuggestionsService::AddObserver(Observer* observer) { |
117 observers_.AddObserver(observer); | 117 observers_.AddObserver(observer); |
118 } | 118 } |
119 | 119 |
120 void ContentSuggestionsService::RemoveObserver(Observer* observer) { | 120 void ContentSuggestionsService::RemoveObserver(Observer* observer) { |
121 observers_.RemoveObserver(observer); | 121 observers_.RemoveObserver(observer); |
122 } | 122 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 201 } |
202 | 202 |
203 void ContentSuggestionsService::NotifyCategoryStatusChanged( | 203 void ContentSuggestionsService::NotifyCategoryStatusChanged( |
204 ContentSuggestionsCategory category) { | 204 ContentSuggestionsCategory category) { |
205 FOR_EACH_OBSERVER( | 205 FOR_EACH_OBSERVER( |
206 Observer, observers_, | 206 Observer, observers_, |
207 OnCategoryStatusChanged(category, GetCategoryStatus(category))); | 207 OnCategoryStatusChanged(category, GetCategoryStatus(category))); |
208 } | 208 } |
209 | 209 |
210 } // namespace ntp_snippets | 210 } // namespace ntp_snippets |
OLD | NEW |