Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Side by Side Diff: components/ntp_snippets/content_suggestions_service.h

Issue 2473483006: Adds a Fetch() method to the ContentSuggestionService which asks any provider to provide more conte… (Closed)
Patch Set: comments by Markus. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 class PrefService; 27 class PrefService;
28 class PrefRegistrySimple; 28 class PrefRegistrySimple;
29 29
30 namespace gfx { 30 namespace gfx {
31 class Image; 31 class Image;
32 } // namespace gfx 32 } // namespace gfx
33 33
34 namespace ntp_snippets { 34 namespace ntp_snippets {
35 35
36 class NTPSnippetsService; 36 class NTPSnippetsService;
37 class NTPSnippetsFetcher;
Marc Treib 2016/11/07 14:28:23 Not needed
tschumann 2016/11/08 16:57:35 Done.
37 38
38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves 39 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves
39 // them grouped into categories. There can be at most one provider per category. 40 // them grouped into categories. There can be at most one provider per category.
40 class ContentSuggestionsService : public KeyedService, 41 class ContentSuggestionsService : public KeyedService,
41 public ContentSuggestionsProvider::Observer, 42 public ContentSuggestionsProvider::Observer,
42 public history::HistoryServiceObserver { 43 public history::HistoryServiceObserver {
43 public: 44 public:
45 // TODO(treib): All these should probably be OnceCallback.
44 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; 46 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>;
45 using DismissedSuggestionsCallback = base::Callback<void( 47 using DismissedSuggestionsCallback = base::Callback<void(
46 std::vector<ContentSuggestion> dismissed_suggestions)>; 48 std::vector<ContentSuggestion> dismissed_suggestions)>;
49 using FetchingCallback =
50 base::Callback<void(std::vector<ContentSuggestion> suggestions)>;
47 51
48 class Observer { 52 class Observer {
49 public: 53 public:
50 // Fired every time the service receives a new set of data for the given 54 // 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 55 // |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 56 // there will be an overlap and only a few changes within the data). The new
53 // data is then available through |GetSuggestionsForCategory(category)|. 57 // data is then available through |GetSuggestionsForCategory(category)|.
54 virtual void OnNewSuggestions(Category category) = 0; 58 virtual void OnNewSuggestions(Category category) = 0;
55 59
56 // Fired when the status of a suggestions category changed. When the status 60 // Fired when the status of a suggestions category changed. When the status
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // This will not trigger an update through the observers. 132 // This will not trigger an update through the observers.
129 void DismissCategory(Category category); 133 void DismissCategory(Category category);
130 134
131 // Restores all dismissed categories. 135 // Restores all dismissed categories.
132 // This will not trigger an update through the observers. 136 // This will not trigger an update through the observers.
133 void RestoreDismissedCategories(); 137 void RestoreDismissedCategories();
134 138
135 // Returns whether |category| is dismissed. 139 // Returns whether |category| is dismissed.
136 bool IsCategoryDismissed(Category category) const; 140 bool IsCategoryDismissed(Category category) const;
137 141
142 // Fetches additional contents for the given |category|. If the fetch was
143 // completed, the given |callback| is called with the updated content.
144 // This includes new and old data.
145 void Fetch(const Category& category,
146 const std::set<std::string>& known_suggestion_ids,
147 const FetchingCallback& callback);
148
138 // Observer accessors. 149 // Observer accessors.
139 void AddObserver(Observer* observer); 150 void AddObserver(Observer* observer);
140 void RemoveObserver(Observer* observer); 151 void RemoveObserver(Observer* observer);
141 152
142 // Registers a new ContentSuggestionsProvider. It must be ensured that at most 153 // Registers a new ContentSuggestionsProvider. It must be ensured that at most
143 // one provider is registered for every category and that this method is 154 // one provider is registered for every category and that this method is
144 // called only once per provider. 155 // called only once per provider.
145 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider); 156 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider);
146 157
147 // Removes history from the specified time range where the URL matches the 158 // Removes history from the specified time range where the URL matches the
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 PrefService* pref_service_; 304 PrefService* pref_service_;
294 305
295 UserClassifier user_classifier_; 306 UserClassifier user_classifier_;
296 307
297 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); 308 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService);
298 }; 309 };
299 310
300 } // namespace ntp_snippets 311 } // namespace ntp_snippets
301 312
302 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ 313 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698