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 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves | 38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
39 // them grouped into categories. There can be at most one provider per category. | 39 // them grouped into categories. There can be at most one provider per category. |
40 class ContentSuggestionsService : public KeyedService, | 40 class ContentSuggestionsService : public KeyedService, |
41 public ContentSuggestionsProvider::Observer, | 41 public ContentSuggestionsProvider::Observer, |
42 public history::HistoryServiceObserver { | 42 public history::HistoryServiceObserver { |
43 public: | 43 public: |
44 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; | 44 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; |
45 using DismissedSuggestionsCallback = base::Callback<void( | 45 using DismissedSuggestionsCallback = base::Callback<void( |
46 std::vector<ContentSuggestion> dismissed_suggestions)>; | 46 std::vector<ContentSuggestion> dismissed_suggestions)>; |
47 using FetchedMoreCallback = | |
48 base::Callback<void(std::vector<ContentSuggestion> suggestions)>; | |
47 | 49 |
48 class Observer { | 50 class Observer { |
49 public: | 51 public: |
50 // Fired every time the service receives a new set of data for the given | 52 // Fired every time the service receives a new set of data for the given |
51 // |category|, replacing any previously available data (though in most cases | 53 // |category|, replacing any previously available data (though in most cases |
52 // there will be an overlap and only a few changes within the data). The new | 54 // there will be an overlap and only a few changes within the data). The new |
53 // data is then available through |GetSuggestionsForCategory(category)|. | 55 // data is then available through |GetSuggestionsForCategory(category)|. |
54 virtual void OnNewSuggestions(Category category) = 0; | 56 virtual void OnNewSuggestions(Category category) = 0; |
55 | 57 |
56 // Fired when the status of a suggestions category changed. When the status | 58 // Fired when the status of a suggestions category changed. When the status |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // This will not trigger an update through the observers. | 130 // This will not trigger an update through the observers. |
129 void DismissCategory(Category category); | 131 void DismissCategory(Category category); |
130 | 132 |
131 // Restores all dismissed categories. | 133 // Restores all dismissed categories. |
132 // This will not trigger an update through the observers. | 134 // This will not trigger an update through the observers. |
133 void RestoreDismissedCategories(); | 135 void RestoreDismissedCategories(); |
134 | 136 |
135 // Returns whether |category| is dismissed. | 137 // Returns whether |category| is dismissed. |
136 bool IsCategoryDismissed(Category category) const; | 138 bool IsCategoryDismissed(Category category) const; |
137 | 139 |
140 // Fetches additional contents for the given |category|. If the fetch was | |
141 // completed, the given |callback| is called with the updated content. | |
vitaliii
2016/11/01 23:29:57
s/completed/successful?
fhorschig
2016/11/02 05:05:27
It's also called if the call was not successful (e
| |
142 // This includes new and old data. | |
143 void FetchMore(const Category& category, const FetchedMoreCallback& callback); | |
144 | |
138 // Observer accessors. | 145 // Observer accessors. |
139 void AddObserver(Observer* observer); | 146 void AddObserver(Observer* observer); |
140 void RemoveObserver(Observer* observer); | 147 void RemoveObserver(Observer* observer); |
141 | 148 |
142 // Registers a new ContentSuggestionsProvider. It must be ensured that at most | 149 // Registers a new ContentSuggestionsProvider. It must be ensured that at most |
143 // one provider is registered for every category and that this method is | 150 // one provider is registered for every category and that this method is |
144 // called only once per provider. | 151 // called only once per provider. |
145 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider); | 152 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider); |
146 | 153 |
147 // Removes history from the specified time range where the URL matches the | 154 // Removes history from the specified time range where the URL matches the |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 PrefService* pref_service_; | 300 PrefService* pref_service_; |
294 | 301 |
295 UserClassifier user_classifier_; | 302 UserClassifier user_classifier_; |
296 | 303 |
297 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 304 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
298 }; | 305 }; |
299 | 306 |
300 } // namespace ntp_snippets | 307 } // namespace ntp_snippets |
301 | 308 |
302 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 309 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |