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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/optional.h" | 15 #include "base/optional.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "components/history/core/browser/history_service_observer.h" |
17 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
18 #include "components/ntp_snippets/category_factory.h" | 19 #include "components/ntp_snippets/category_factory.h" |
19 #include "components/ntp_snippets/category_status.h" | 20 #include "components/ntp_snippets/category_status.h" |
20 #include "components/ntp_snippets/content_suggestions_provider.h" | 21 #include "components/ntp_snippets/content_suggestions_provider.h" |
21 | 22 |
22 namespace gfx { | 23 namespace gfx { |
23 class Image; | 24 class Image; |
24 } | 25 } |
25 | 26 |
26 namespace ntp_snippets { | 27 namespace ntp_snippets { |
27 | 28 |
28 class NTPSnippetsService; | 29 class NTPSnippetsService; |
29 | 30 |
30 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves | 31 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
31 // them grouped into categories. There can be at most one provider per category. | 32 // them grouped into categories. There can be at most one provider per category. |
32 class ContentSuggestionsService : public KeyedService, | 33 class ContentSuggestionsService : public KeyedService, |
33 public ContentSuggestionsProvider::Observer { | 34 public ContentSuggestionsProvider::Observer, |
| 35 public history::HistoryServiceObserver { |
34 public: | 36 public: |
35 using ImageFetchedCallback = | 37 using ImageFetchedCallback = |
36 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; | 38 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; |
37 using DismissedSuggestionsCallback = base::Callback<void( | 39 using DismissedSuggestionsCallback = base::Callback<void( |
38 std::vector<ContentSuggestion> dismissed_suggestions)>; | 40 std::vector<ContentSuggestion> dismissed_suggestions)>; |
39 | 41 |
40 class Observer { | 42 class Observer { |
41 public: | 43 public: |
42 // Fired every time the service receives a new set of data for the given | 44 // Fired every time the service receives a new set of data for the given |
43 // |category|, replacing any previously available data (though in most cases | 45 // |category|, replacing any previously available data (though in most cases |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 void OnNewSuggestions(ContentSuggestionsProvider* provider, | 175 void OnNewSuggestions(ContentSuggestionsProvider* provider, |
174 Category category, | 176 Category category, |
175 std::vector<ContentSuggestion> suggestions) override; | 177 std::vector<ContentSuggestion> suggestions) override; |
176 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 178 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
177 Category category, | 179 Category category, |
178 CategoryStatus new_status) override; | 180 CategoryStatus new_status) override; |
179 void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, | 181 void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, |
180 Category category, | 182 Category category, |
181 const std::string& suggestion_id) override; | 183 const std::string& suggestion_id) override; |
182 | 184 |
| 185 // history::HistoryServiceObserver implementation. |
| 186 void OnURLsDeleted(history::HistoryService* history_service, |
| 187 bool all_history, |
| 188 bool expired, |
| 189 const history::URLRows& deleted_rows, |
| 190 const std::set<GURL>& favicon_urls) override; |
| 191 |
183 // Registers the given |provider| for the given |category|, unless it is | 192 // Registers the given |provider| for the given |category|, unless it is |
184 // already registered. Returns true if the category was newly registered or | 193 // already registered. Returns true if the category was newly registered or |
185 // false if it was present before. | 194 // false if it was present before. |
186 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, | 195 bool RegisterCategoryIfRequired(ContentSuggestionsProvider* provider, |
187 Category category); | 196 Category category); |
188 | 197 |
189 // Removes a suggestion from the local stores |id_category_map_| and | 198 // Removes a suggestion from the local stores |id_category_map_| and |
190 // |suggestions_by_category_|, if it exists. Returns true if a suggestion was | 199 // |suggestions_by_category_|, if it exists. Returns true if a suggestion was |
191 // removed. | 200 // removed. |
192 bool RemoveSuggestionByID(Category category, | 201 bool RemoveSuggestionByID(Category category, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // background fetching and debugging calls to it. If the NTPSnippetsService is | 247 // background fetching and debugging calls to it. If the NTPSnippetsService is |
239 // loaded, it is also present in |providers_|, otherwise this is a nullptr. | 248 // loaded, it is also present in |providers_|, otherwise this is a nullptr. |
240 NTPSnippetsService* ntp_snippets_service_; | 249 NTPSnippetsService* ntp_snippets_service_; |
241 | 250 |
242 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 251 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
243 }; | 252 }; |
244 | 253 |
245 } // namespace ntp_snippets | 254 } // namespace ntp_snippets |
246 | 255 |
247 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 256 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |