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

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

Issue 2466863003: Finalize backend for fetching more NTPSnippets. (Closed)
Patch Set: Known suggestion are now a parameter for Fetch. 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 27 matching lines...) Expand all
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 // TODO(treib): All these should probably be OnceCallback. 44 // TODO(treib): All these should probably be OnceCallback.
45 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; 45 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>;
46 using DismissedSuggestionsCallback = base::Callback<void( 46 using DismissedSuggestionsCallback = base::Callback<void(
47 std::vector<ContentSuggestion> dismissed_suggestions)>; 47 std::vector<ContentSuggestion> dismissed_suggestions)>;
48 using FetchedMoreCallback = 48 using FetchingCallback =
49 base::Callback<void(std::vector<ContentSuggestion> suggestions)>; 49 base::Callback<void(std::vector<ContentSuggestion> suggestions)>;
50 50
51 class Observer { 51 class Observer {
52 public: 52 public:
53 // Fired every time the service receives a new set of data for the given 53 // Fired every time the service receives a new set of data for the given
54 // |category|, replacing any previously available data (though in most cases 54 // |category|, replacing any previously available data (though in most cases
55 // there will be an overlap and only a few changes within the data). The new 55 // there will be an overlap and only a few changes within the data). The new
56 // data is then available through |GetSuggestionsForCategory(category)|. 56 // data is then available through |GetSuggestionsForCategory(category)|.
57 virtual void OnNewSuggestions(Category category) = 0; 57 virtual void OnNewSuggestions(Category category) = 0;
58 58
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Restores all dismissed categories. 134 // Restores all dismissed categories.
135 // This will not trigger an update through the observers. 135 // This will not trigger an update through the observers.
136 void RestoreDismissedCategories(); 136 void RestoreDismissedCategories();
137 137
138 // Returns whether |category| is dismissed. 138 // Returns whether |category| is dismissed.
139 bool IsCategoryDismissed(Category category) const; 139 bool IsCategoryDismissed(Category category) const;
140 140
141 // Fetches additional contents for the given |category|. If the fetch was 141 // Fetches additional contents for the given |category|. If the fetch was
142 // completed, the given |callback| is called with the updated content. 142 // completed, the given |callback| is called with the updated content.
143 // This includes new and old data. 143 // This includes new and old data.
144 void FetchMore(const Category& category, const FetchedMoreCallback& callback); 144 void Fetch(const Category& category,
145 std::set<std::string> known_suggestion_ids,
146 const FetchingCallback& callback);
145 147
146 // Observer accessors. 148 // Observer accessors.
147 void AddObserver(Observer* observer); 149 void AddObserver(Observer* observer);
148 void RemoveObserver(Observer* observer); 150 void RemoveObserver(Observer* observer);
149 151
150 // Registers a new ContentSuggestionsProvider. It must be ensured that at most 152 // Registers a new ContentSuggestionsProvider. It must be ensured that at most
151 // one provider is registered for every category and that this method is 153 // one provider is registered for every category and that this method is
152 // called only once per provider. 154 // called only once per provider.
153 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider); 155 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider);
154 156
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 PrefService* pref_service_; 303 PrefService* pref_service_;
302 304
303 UserClassifier user_classifier_; 305 UserClassifier user_classifier_;
304 306
305 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); 307 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService);
306 }; 308 };
307 309
308 } // namespace ntp_snippets 310 } // namespace ntp_snippets
309 311
310 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ 312 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698