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. This event may also be fired for |
| 59 // |suggestion_id|s that never existed and should be ignored in that case. |
| 60 virtual void OnSuggestionInvalidated(Category category, |
| 61 const std::string& suggestion_id) = 0; |
| 62 |
53 // Sent when the service is shutting down. After the service has shut down, | 63 // 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 | 64 // it will not provide any data anymore, though calling the getters is still |
55 // safe. | 65 // safe. |
56 virtual void ContentSuggestionsServiceShutdown() = 0; | 66 virtual void ContentSuggestionsServiceShutdown() = 0; |
57 | 67 |
58 protected: | 68 protected: |
59 virtual ~Observer() {} | 69 virtual ~Observer() {} |
60 }; | 70 }; |
61 | 71 |
62 enum State { | 72 enum State { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 private: | 158 private: |
149 friend class ContentSuggestionsServiceTest; | 159 friend class ContentSuggestionsServiceTest; |
150 | 160 |
151 // Implementation of ContentSuggestionsProvider::Observer. | 161 // Implementation of ContentSuggestionsProvider::Observer. |
152 void OnNewSuggestions(ContentSuggestionsProvider* provider, | 162 void OnNewSuggestions(ContentSuggestionsProvider* provider, |
153 Category category, | 163 Category category, |
154 std::vector<ContentSuggestion> suggestions) override; | 164 std::vector<ContentSuggestion> suggestions) override; |
155 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 165 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
156 Category category, | 166 Category category, |
157 CategoryStatus new_status) override; | 167 CategoryStatus new_status) override; |
| 168 void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, |
| 169 Category category, |
| 170 const std::string& suggestion_id) override; |
158 | 171 |
159 // Registers the given |provider| for the given |category|, unless it is | 172 // Registers the given |provider| for the given |category|, unless it is |
160 // already registered. Returns true if the category was newly registered or | 173 // already registered. Returns true if the category was newly registered or |
161 // false if it was present before. | 174 // false if it was present before. |
162 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, | 175 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, |
163 Category category); | 176 Category category); |
164 | 177 |
| 178 // Removes a suggestion from the local stores |id_category_map_| and |
| 179 // |suggestions_by_category_|, if it exists. Returns true if a suggestion was |
| 180 // removed. |
| 181 bool RemoveSuggestionByID(Category category, |
| 182 const std::string& suggestion_id); |
| 183 |
165 // Fires the OnCategoryStatusChanged event for the given |category|. | 184 // Fires the OnCategoryStatusChanged event for the given |category|. |
166 void NotifyCategoryStatusChanged(Category category); | 185 void NotifyCategoryStatusChanged(Category category); |
167 | 186 |
168 // Whether the content suggestions feature is enabled. | 187 // Whether the content suggestions feature is enabled. |
169 State state_; | 188 State state_; |
170 | 189 |
171 // Provides new and existing categories and an order for them. | 190 // Provides new and existing categories and an order for them. |
172 CategoryFactory category_factory_; | 191 CategoryFactory category_factory_; |
173 | 192 |
174 // All registered providers, owned by the service. | 193 // All registered providers, owned by the service. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // background fetching and debugging calls to it. If the NTPSnippetsService is | 225 // background fetching and debugging calls to it. If the NTPSnippetsService is |
207 // loaded, it is also present in |providers_|, otherwise this is a nullptr. | 226 // loaded, it is also present in |providers_|, otherwise this is a nullptr. |
208 NTPSnippetsService* ntp_snippets_service_; | 227 NTPSnippetsService* ntp_snippets_service_; |
209 | 228 |
210 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 229 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
211 }; | 230 }; |
212 | 231 |
213 } // namespace ntp_snippets | 232 } // namespace ntp_snippets |
214 | 233 |
215 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 234 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |