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

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

Issue 2421463002: FetchMore functionality backend (Closed)
Patch Set: ID set reference, Optional callback, ... (2466863003 comments). 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)>;
35 using FetchingCallback =
36 base::Callback<void(std::vector<ContentSuggestion> suggestions)>;
34 37
35 // 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.
36 class Observer { 39 class Observer {
37 public: 40 public:
38 // Called when the available content changed. 41 // Called when the available content changed.
39 // If a provider provides suggestions for multiple categories, this callback 42 // If a provider provides suggestions for multiple categories, this callback
40 // is called once per category. The |suggestions| parameter always contains 43 // is called once per category. The |suggestions| parameter always contains
41 // 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.,
42 // 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
43 // that to clear them from the UI immediately, the provider needs to change 46 // that to clear them from the UI immediately, the provider needs to change
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const ContentSuggestion::ID& suggestion_id) = 0; 96 const ContentSuggestion::ID& suggestion_id) = 0;
94 97
95 // 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
96 // 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.
97 // 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
98 // 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
99 // synchronously. 102 // synchronously.
100 virtual void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, 103 virtual void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
101 const ImageFetchedCallback& callback) = 0; 104 const ImageFetchedCallback& callback) = 0;
102 105
106 // Fetches more suggestions for the given category. The new suggestions
107 // will not include any suggestion of the |known_suggestion_ids| sets.
108 // The given |callback| is called with these suggestions, along with all
109 // existing suggestions.
110 virtual void Fetch(const Category& category,
111 const std::set<std::string>& known_suggestion_ids,
112 FetchingCallback callback) = 0;
113
103 // 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
104 // |filter|. The data removed depends on the provider. Note that the 115 // |filter|. The data removed depends on the provider. Note that the
105 // 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
106 // are based on history from that time range. Providers should immediately 117 // are based on history from that time range. Providers should immediately
107 // 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
108 // URL matches the |filter|. 119 // URL matches the |filter|.
109 virtual void ClearHistory( 120 virtual void ClearHistory(
110 base::Time begin, 121 base::Time begin,
111 base::Time end, 122 base::Time end,
112 const base::Callback<bool(const GURL& url)>& filter) = 0; 123 const base::Callback<bool(const GURL& url)>& filter) = 0;
(...skipping 26 matching lines...) Expand all
139 CategoryFactory* category_factory() const { return category_factory_; } 150 CategoryFactory* category_factory() const { return category_factory_; }
140 151
141 private: 152 private:
142 Observer* observer_; 153 Observer* observer_;
143 CategoryFactory* category_factory_; 154 CategoryFactory* category_factory_;
144 }; 155 };
145 156
146 } // namespace ntp_snippets 157 } // namespace ntp_snippets
147 158
148 #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