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

Side by Side Diff: components/ntp_snippets/content_suggestions_provider.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_PROVIDER_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
7 7
8 #include <set>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
12 #include "components/ntp_snippets/category.h" 13 #include "components/ntp_snippets/category.h"
13 #include "components/ntp_snippets/category_info.h" 14 #include "components/ntp_snippets/category_info.h"
14 #include "components/ntp_snippets/category_status.h" 15 #include "components/ntp_snippets/category_status.h"
15 #include "components/ntp_snippets/content_suggestion.h" 16 #include "components/ntp_snippets/content_suggestion.h"
16 17
17 namespace gfx { 18 namespace gfx {
18 class Image; 19 class Image;
19 } // namespace gfx 20 } // namespace gfx
20 21
21 namespace ntp_snippets { 22 namespace ntp_snippets {
22 23
23 // Provides content suggestions from one particular source. 24 // Provides content suggestions from one particular source.
24 // A provider can provide suggestions for multiple ContentSuggestionCategories, 25 // A provider can provide suggestions for multiple ContentSuggestionCategories,
25 // but for every category that it provides, it will be the only provider in the 26 // but for every category that it provides, it will be the only provider in the
26 // system which provides suggestions for that category. 27 // system which provides suggestions for that category.
27 // Providers are created by the ContentSuggestionsServiceFactory and owned and 28 // Providers are created by the ContentSuggestionsServiceFactory and owned and
28 // shut down by the ContentSuggestionsService. 29 // shut down by the ContentSuggestionsService.
29 class ContentSuggestionsProvider { 30 class ContentSuggestionsProvider {
30 public: 31 public:
31 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; 32 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>;
32 using DismissedSuggestionsCallback = base::Callback<void( 33 using DismissedSuggestionsCallback = base::Callback<void(
33 std::vector<ContentSuggestion> dismissed_suggestions)>; 34 std::vector<ContentSuggestion> dismissed_suggestions)>;
34 using FetchedMoreCallback = 35 using FetchingCallback =
35 base::Callback<void(std::vector<ContentSuggestion> suggestions)>; 36 base::Callback<void(std::vector<ContentSuggestion> suggestions)>;
36 37
37 // The observer of a provider is notified when new data is available. 38 // The observer of a provider is notified when new data is available.
38 class Observer { 39 class Observer {
39 public: 40 public:
40 // Called when the available content changed. 41 // Called when the available content changed.
41 // If a provider provides suggestions for multiple categories, this callback 42 // If a provider provides suggestions for multiple categories, this callback
42 // is called once per category. The |suggestions| parameter always contains 43 // is called once per category. The |suggestions| parameter always contains
43 // the full list of currently available suggestions for that category, i.e., 44 // the full list of currently available suggestions for that category, i.e.,
44 // an empty list will remove all suggestions from the given category. Note 45 // an empty list will remove all suggestions from the given category. Note
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 const ContentSuggestion::ID& suggestion_id) = 0; 96 const ContentSuggestion::ID& suggestion_id) = 0;
96 97
97 // Fetches the image for the suggestion with the given ID and returns it 98 // Fetches the image for the suggestion with the given ID and returns it
98 // through the callback. This fetch may occur locally or from the internet. 99 // through the callback. This fetch may occur locally or from the internet.
99 // If that suggestion doesn't exist, doesn't have an image or if the fetch 100 // If that suggestion doesn't exist, doesn't have an image or if the fetch
100 // fails, the callback gets a null image. The callback will not be called 101 // fails, the callback gets a null image. The callback will not be called
101 // synchronously. 102 // synchronously.
102 virtual void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, 103 virtual void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
103 const ImageFetchedCallback& callback) = 0; 104 const ImageFetchedCallback& callback) = 0;
104 105
105 // A user-triggered request to fetch more content for the given category. 106 // Fetches more suggestions for the given category. The new suggestions
106 // Provides only suggestions that have not been provided. The given |callback| 107 // will not include any suggestion of the |known_suggestion_ids| sets.
107 // is called with these suggestion, along with all existing suggestions. 108 // The given |callback| is called with these suggestions, along with all
108 virtual void FetchMore(const Category& category, 109 // existing suggestions.
109 FetchedMoreCallback callback) = 0; 110 virtual void Fetch(const Category& category,
111 std::set<std::string> known_suggestion_ids,
112 FetchingCallback callback) = 0;
110 113
111 // Removes history from the specified time range where the URL matches the 114 // Removes history from the specified time range where the URL matches the
112 // |filter|. The data removed depends on the provider. Note that the 115 // |filter|. The data removed depends on the provider. Note that the
113 // data outside the time range may be deleted, for example suggestions, which 116 // data outside the time range may be deleted, for example suggestions, which
114 // are based on history from that time range. Providers should immediately 117 // are based on history from that time range. Providers should immediately
115 // clear any data related to history from the specified time range where the 118 // clear any data related to history from the specified time range where the
116 // URL matches the |filter|. 119 // URL matches the |filter|.
117 virtual void ClearHistory( 120 virtual void ClearHistory(
118 base::Time begin, 121 base::Time begin,
119 base::Time end, 122 base::Time end,
(...skipping 27 matching lines...) Expand all
147 CategoryFactory* category_factory() const { return category_factory_; } 150 CategoryFactory* category_factory() const { return category_factory_; }
148 151
149 private: 152 private:
150 Observer* observer_; 153 Observer* observer_;
151 CategoryFactory* category_factory_; 154 CategoryFactory* category_factory_;
152 }; 155 };
153 156
154 } // namespace ntp_snippets 157 } // namespace ntp_snippets
155 158
156 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ 159 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698