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 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 virtual void OnNewSuggestions(Category category) = 0; | 43 virtual void OnNewSuggestions(Category category) = 0; |
44 | 44 |
45 // Fired when the status of a suggestions category changed. When the status | 45 // Fired when the status of a suggestions category changed. When the status |
46 // changes to an unavailable status, the suggestions of the respective | 46 // changes to an unavailable status, the suggestions of the respective |
47 // category have been invalidated, which means that they must no longer be | 47 // category have been invalidated, which means that they must no longer be |
48 // displayed to the user. The UI must immediately clear any suggestions of | 48 // displayed to the user. The UI must immediately clear any suggestions of |
49 // that category. | 49 // that category. |
50 virtual void OnCategoryStatusChanged(Category category, | 50 virtual void OnCategoryStatusChanged(Category category, |
51 CategoryStatus new_status) = 0; | 51 CategoryStatus new_status) = 0; |
52 | 52 |
53 // Fired when a suggestion has been invalidated. The UI must immediately | |
54 // clear the suggestion even from open NTPs. Invalidation happens, for | |
55 // example, when the content that the suggestion refers to is gone. | |
56 // Note that this event may be fired even if the corresponding |category| is | |
57 // not currently AVAILABLE, because open UIs may still be showing the | |
58 // suggestion that is to be removed. | |
59 virtual void OnSuggestionInvalidated(Category category, | |
60 const std::string& suggestion_id) = 0; | |
61 | |
53 // Sent when the service is shutting down. After the service has shut down, | 62 // Sent when the service is shutting down. After the service has shut down, |
54 // it will not provide any data anymore, though calling the getters is still | 63 // it will not provide any data anymore, though calling the getters is still |
55 // safe. | 64 // safe. |
56 virtual void ContentSuggestionsServiceShutdown() = 0; | 65 virtual void ContentSuggestionsServiceShutdown() = 0; |
57 | 66 |
58 protected: | 67 protected: |
59 virtual ~Observer() {} | 68 virtual ~Observer() {} |
60 }; | 69 }; |
61 | 70 |
62 enum State { | 71 enum State { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 bool operator()(const Category& left, const Category& right) const; | 163 bool operator()(const Category& left, const Category& right) const; |
155 }; | 164 }; |
156 | 165 |
157 // Implementation of ContentSuggestionsProvider::Observer. | 166 // Implementation of ContentSuggestionsProvider::Observer. |
158 void OnNewSuggestions(ContentSuggestionsProvider* provider, | 167 void OnNewSuggestions(ContentSuggestionsProvider* provider, |
159 Category category, | 168 Category category, |
160 std::vector<ContentSuggestion> suggestions) override; | 169 std::vector<ContentSuggestion> suggestions) override; |
161 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 170 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
162 Category category, | 171 Category category, |
163 CategoryStatus new_status) override; | 172 CategoryStatus new_status) override; |
173 void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, | |
174 Category category, | |
175 const std::string& suggestion_id) override; | |
164 | 176 |
165 // Registers the given |provider| for the given |category|, unless it is | 177 // Registers the given |provider| for the given |category|, unless it is |
166 // already registered. Returns true if the category was newly registered or | 178 // already registered. Returns true if the category was newly registered or |
167 // false if it was present before. | 179 // false if it was present before. |
168 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, | 180 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, |
169 Category category); | 181 Category category); |
170 | 182 |
183 // Removes a suggestion from the local stores |id_category_map_| and | |
184 // |suggestions_by_category_|, if it exists. Returns true if the suggestion | |
185 // still existed. | |
Marc Treib
2016/08/16 09:03:54
Returns true if a suggestion was removed? (I find
Philipp Keck
2016/08/16 10:54:40
Done.
| |
186 bool RemoveSuggestionByID(Category category, | |
187 const std::string& suggestion_id); | |
188 | |
171 // Fires the OnCategoryStatusChanged event for the given |category|. | 189 // Fires the OnCategoryStatusChanged event for the given |category|. |
172 void NotifyCategoryStatusChanged(Category category); | 190 void NotifyCategoryStatusChanged(Category category); |
173 | 191 |
174 // Whether the content suggestions feature is enabled. | 192 // Whether the content suggestions feature is enabled. |
175 State state_; | 193 State state_; |
176 | 194 |
177 // Provides new and existing categories and an order for them. | 195 // Provides new and existing categories and an order for them. |
178 CategoryFactory category_factory_; | 196 CategoryFactory category_factory_; |
179 | 197 |
180 // All registered providers, owned by the service. | 198 // All registered providers, owned by the service. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 // background fetching and debugging calls to it. If the NTPSnippetsService is | 230 // background fetching and debugging calls to it. If the NTPSnippetsService is |
213 // loaded, it is also present in |providers_|, otherwise this is a nullptr. | 231 // loaded, it is also present in |providers_|, otherwise this is a nullptr. |
214 NTPSnippetsService* ntp_snippets_service_; | 232 NTPSnippetsService* ntp_snippets_service_; |
215 | 233 |
216 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 234 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
217 }; | 235 }; |
218 | 236 |
219 } // namespace ntp_snippets | 237 } // namespace ntp_snippets |
220 | 238 |
221 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 239 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |