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 <set> | 10 #include <set> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // changes to an unavailable status, the suggestions of the respective | 56 // changes to an unavailable status, the suggestions of the respective |
57 // category have been invalidated, which means that they must no longer be | 57 // category have been invalidated, which means that they must no longer be |
58 // displayed to the user. The UI must immediately clear any suggestions of | 58 // displayed to the user. The UI must immediately clear any suggestions of |
59 // that category. | 59 // that category. |
60 virtual void OnCategoryStatusChanged(Category category, | 60 virtual void OnCategoryStatusChanged(Category category, |
61 CategoryStatus new_status) = 0; | 61 CategoryStatus new_status) = 0; |
62 | 62 |
63 // Fired when a suggestion has been invalidated. The UI must immediately | 63 // Fired when a suggestion has been invalidated. The UI must immediately |
64 // clear the suggestion even from open NTPs. Invalidation happens, for | 64 // clear the suggestion even from open NTPs. Invalidation happens, for |
65 // example, when the content that the suggestion refers to is gone. | 65 // example, when the content that the suggestion refers to is gone. |
66 // Note that this event may be fired even if the corresponding |category| is | 66 // Note that this event may be fired even if the corresponding category is |
67 // not currently AVAILABLE, because open UIs may still be showing the | 67 // not currently AVAILABLE, because open UIs may still be showing the |
68 // suggestion that is to be removed. This event may also be fired for | 68 // suggestion that is to be removed. This event may also be fired for |
69 // |suggestion_id|s that never existed and should be ignored in that case. | 69 // |suggestion_id|s that never existed and should be ignored in that case. |
70 virtual void OnSuggestionInvalidated(Category category, | 70 virtual void OnSuggestionInvalidated( |
71 const std::string& suggestion_id) = 0; | 71 const ContentSuggestion::ID& suggestion_id) = 0; |
72 | 72 |
73 // Sent when the service is shutting down. After the service has shut down, | 73 // Sent when the service is shutting down. After the service has shut down, |
74 // it will not provide any data anymore, though calling the getters is still | 74 // it will not provide any data anymore, though calling the getters is still |
75 // safe. | 75 // safe. |
76 virtual void ContentSuggestionsServiceShutdown() = 0; | 76 virtual void ContentSuggestionsServiceShutdown() = 0; |
77 | 77 |
78 protected: | 78 protected: |
79 virtual ~Observer() = default; | 79 virtual ~Observer() = default; |
80 }; | 80 }; |
81 | 81 |
(...skipping 25 matching lines...) Expand all Loading... |
107 // Gets the available suggestions for a category. The result is empty if the | 107 // Gets the available suggestions for a category. The result is empty if the |
108 // category is available and empty, but also if the category is unavailable | 108 // category is available and empty, but also if the category is unavailable |
109 // for any reason, see |GetCategoryStatus()|. | 109 // for any reason, see |GetCategoryStatus()|. |
110 const std::vector<ContentSuggestion>& GetSuggestionsForCategory( | 110 const std::vector<ContentSuggestion>& GetSuggestionsForCategory( |
111 Category category) const; | 111 Category category) const; |
112 | 112 |
113 // Fetches the image for the suggestion with the given |suggestion_id| and | 113 // Fetches the image for the suggestion with the given |suggestion_id| and |
114 // runs the |callback|. If that suggestion doesn't exist or the fetch fails, | 114 // runs the |callback|. If that suggestion doesn't exist or the fetch fails, |
115 // the callback gets an empty image. The callback will not be called | 115 // the callback gets an empty image. The callback will not be called |
116 // synchronously. | 116 // synchronously. |
117 void FetchSuggestionImage(const std::string& suggestion_id, | 117 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, |
118 const ImageFetchedCallback& callback); | 118 const ImageFetchedCallback& callback); |
119 | 119 |
120 // Dismisses the suggestion with the given |suggestion_id|, if it exists. | 120 // Dismisses the suggestion with the given |suggestion_id|, if it exists. |
121 // This will not trigger an update through the observers. | 121 // This will not trigger an update through the observers. |
122 void DismissSuggestion(const std::string& suggestion_id); | 122 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id); |
123 | 123 |
124 // Dismisses the given |category|, if it exists. | 124 // Dismisses the given |category|, if it exists. |
125 // This will not trigger an update through the observers. | 125 // This will not trigger an update through the observers. |
126 void DismissCategory(Category category); | 126 void DismissCategory(Category category); |
127 | 127 |
128 // Observer accessors. | 128 // Observer accessors. |
129 void AddObserver(Observer* observer); | 129 void AddObserver(Observer* observer); |
130 void RemoveObserver(Observer* observer); | 130 void RemoveObserver(Observer* observer); |
131 | 131 |
132 // Registers a new ContentSuggestionsProvider. It must be ensured that at most | 132 // Registers a new ContentSuggestionsProvider. It must be ensured that at most |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 private: | 186 private: |
187 friend class ContentSuggestionsServiceTest; | 187 friend class ContentSuggestionsServiceTest; |
188 | 188 |
189 // Implementation of ContentSuggestionsProvider::Observer. | 189 // Implementation of ContentSuggestionsProvider::Observer. |
190 void OnNewSuggestions(ContentSuggestionsProvider* provider, | 190 void OnNewSuggestions(ContentSuggestionsProvider* provider, |
191 Category category, | 191 Category category, |
192 std::vector<ContentSuggestion> suggestions) override; | 192 std::vector<ContentSuggestion> suggestions) override; |
193 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 193 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
194 Category category, | 194 Category category, |
195 CategoryStatus new_status) override; | 195 CategoryStatus new_status) override; |
196 void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, | 196 void OnSuggestionInvalidated( |
197 Category category, | 197 ContentSuggestionsProvider* provider, |
198 const std::string& suggestion_id) override; | 198 const ContentSuggestion::ID& suggestion_id) override; |
199 | 199 |
200 // history::HistoryServiceObserver implementation. | 200 // history::HistoryServiceObserver implementation. |
201 void OnURLsDeleted(history::HistoryService* history_service, | 201 void OnURLsDeleted(history::HistoryService* history_service, |
202 bool all_history, | 202 bool all_history, |
203 bool expired, | 203 bool expired, |
204 const history::URLRows& deleted_rows, | 204 const history::URLRows& deleted_rows, |
205 const std::set<GURL>& favicon_urls) override; | 205 const std::set<GURL>& favicon_urls) override; |
206 void HistoryServiceBeingDeleted( | 206 void HistoryServiceBeingDeleted( |
207 history::HistoryService* history_service) override; | 207 history::HistoryService* history_service) override; |
208 | 208 |
209 // Registers the given |provider| for the given |category|, unless it is | 209 // Registers the given |provider| for the given |category|, unless it is |
210 // already registered. Returns true if the category was newly registered or | 210 // already registered. Returns true if the category was newly registered or |
211 // false if it was present before. | 211 // false if it was present before. |
212 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, | 212 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, |
213 Category category); | 213 Category category); |
214 | 214 |
215 // Removes a suggestion from the local store |suggestions_by_category_|, if it | 215 // Removes a suggestion from the local store |suggestions_by_category_|, if it |
216 // exists. Returns true if a suggestion was removed. | 216 // exists. Returns true if a suggestion was removed. |
217 bool RemoveSuggestionByID(Category category, | 217 bool RemoveSuggestionByID(const ContentSuggestion::ID& suggestion_id); |
218 const std::string& suggestion_id); | |
219 | 218 |
220 // Fires the OnCategoryStatusChanged event for the given |category|. | 219 // Fires the OnCategoryStatusChanged event for the given |category|. |
221 void NotifyCategoryStatusChanged(Category category); | 220 void NotifyCategoryStatusChanged(Category category); |
222 | 221 |
223 void SortCategories(); | 222 void SortCategories(); |
224 | 223 |
225 // Whether the content suggestions feature is enabled. | 224 // Whether the content suggestions feature is enabled. |
226 State state_; | 225 State state_; |
227 | 226 |
228 // Provides new and existing categories and an order for them. | 227 // Provides new and existing categories and an order for them. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 NTPSnippetsService* ntp_snippets_service_; | 264 NTPSnippetsService* ntp_snippets_service_; |
266 | 265 |
267 UserClassifier user_classifier_; | 266 UserClassifier user_classifier_; |
268 | 267 |
269 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 268 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
270 }; | 269 }; |
271 | 270 |
272 } // namespace ntp_snippets | 271 } // namespace ntp_snippets |
273 | 272 |
274 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 273 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |