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

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

Issue 2102023002: Add ContentSuggestionsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove NTPSnippet::ToContentSuggestion and make ContentSuggestionsProvider::MakeUniqueID protected Created 4 years, 5 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback_forward.h"
12 #include "components/ntp_snippets/content_suggestion.h"
13 #include "components/ntp_snippets/content_suggestions_category.h"
14 #include "components/ntp_snippets/content_suggestions_category_status.h"
15
16 namespace gfx {
17 class Image;
18 }
19
20 namespace ntp_snippets {
21
22 // Provides content suggestions from one particular source.
23 // A provider can provide suggestions for multiple ContentSuggestionCategories,
24 // but for every category that it provides, it will be the only provider in the
25 // system which provides suggestions for that category.
26 // A provider can be a keyed service, in which case it should notify the
27 // ContentSuggestionsService through the observer before it shuts down.
28 class ContentSuggestionsProvider {
29 public:
30 using ImageFetchedCallback =
31 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>;
32
33 // The observer of a provider is notified when new data is available.
34 class Observer {
35 public:
36 // Called when the available content changed.
37 // If a provider provides suggestions of multiple categories, it must call
38 // this callback for every category individually. The |suggestions|
Marc Treib 2016/07/07 09:37:50 nit: I'd phrase this as describing the interface,
Philipp Keck 2016/07/07 12:22:29 Done.
39 // parameter should always contain the full list of currently available
Marc Treib 2016/07/07 09:37:50 Similar here: s/should always contain/always conta
Philipp Keck 2016/07/07 12:22:29 Done.
40 // suggestions of that category, i.e., passing an empty list will remove
41 // all suggestions of the given category for the provider. Note that to
42 // clear them from the UI immediately, the provider needs to change the
43 // status of the respective category.
44 // The list must not contain ContentSuggestions assigned to a category other
Marc Treib 2016/07/07 09:37:50 Since ContentSuggestions don't contain a category
Philipp Keck 2016/07/07 12:22:29 Done.
45 // than the passed |changed_category|. IDs for the ContentSuggestions should
46 // be generated with |MakeUniqueID(..)| below.
47 virtual void OnNewSuggestions(
48 ContentSuggestionsCategory changed_category,
49 std::vector<ContentSuggestion> suggestions) = 0;
50
51 // Called when the status of a category changed.
52 // Whenever the status changes to an unavailable status, all suggestions in
53 // that category must immediately be removed from all caches and from the
54 // UI.
55 virtual void OnCategoryStatusChanged(
56 ContentSuggestionsCategory changed_category,
57 ContentSuggestionsCategoryStatus new_status) = 0;
58
59 // Called when the provider needs to shut down and will not deliver any
60 // suggestions anymore. This unregisters the provider, removes the observer
61 // and deactivates all provided categories.
62 virtual void OnProviderShutdown(ContentSuggestionsProvider* provider) = 0;
63 };
64
65 // Sets an observer which is notified about changes to the available
66 // suggestions, or removes it by passing a nullptr.
67 virtual void SetObserver(Observer* observer) = 0;
68
69 // Determines the status of the given |category|, see
70 // ContentSuggestionsCategoryStatus.
71 virtual ContentSuggestionsCategoryStatus GetCategoryStatus(
72 ContentSuggestionsCategory category) = 0;
73
74 // Discards the suggestion with the given ID. A provider needs to ensure that
75 // a once-discarded suggestion is never delivered again (through the
76 // Observer). The provider must not call Observer::OnSuggestionsChanged if the
77 // removal of the discarded suggestion is the only change.
78 // Note that the |suggestion_id| to the provider here is the same as the
79 // |original_id| that was passed to the |ContentSuggestion| constructor.
Marc Treib 2016/07/07 09:37:50 I think this comment is outdated?
Philipp Keck 2016/07/07 12:22:29 Done.
80 virtual void DiscardSuggestion(const std::string& suggestion_id) = 0;
81
82 // Fetches the image for the suggestion with the given ID and returns it
83 // through the callback. This fetch may occur locally or from the internet.
84 // Note that the |suggestion_id| to the provider here is the same as the
85 // |original_id| that was passed to the |ContentSuggestion| constructor.
Marc Treib 2016/07/07 09:37:50 Also here
Philipp Keck 2016/07/07 12:22:29 Done.
86 virtual void FetchSuggestionImage(const std::string& suggestion_id,
87 const ImageFetchedCallback& callback) = 0;
88
89 // Used only for debugging purposes. Clears all caches so that the next
90 // fetch starts from scratch.
91 virtual void ClearCachedSuggestionsForDebugging() = 0;
92
93 // Used only for debugging purposes. Clears the cache of discarded
94 // suggestions, if present, so that no suggestions are suppressed. This does
95 // not necessarily make previously discarded suggestions reappear, as they may
96 // have been permanently deleted, depending on the provider implementation.
97 virtual void ClearDiscardedSuggestionsForDebugging() = 0;
98
99 const std::vector<ContentSuggestionsCategory> provided_categories() const {
Marc Treib 2016/07/07 09:37:50 ref?
Philipp Keck 2016/07/07 12:22:29 Done.
100 return provided_categories_;
101 }
102
103 protected:
104 ContentSuggestionsProvider(
105 const std::vector<ContentSuggestionsCategory>& provided_categories);
106 virtual ~ContentSuggestionsProvider();
107
108 // Creates a unique ID. The given |within_category_id| must be unique among
109 // all suggestion IDs from this provider for the given |category|. This method
110 // combines it with the |category| to form an ID that is unique
111 // application-wide, because this provider is the only one that provides
112 // suggestions for that category.
113 static std::string MakeUniqueID(ContentSuggestionsCategory category,
114 const std::string& within_category_id);
115
116 private:
117 const std::vector<ContentSuggestionsCategory> provided_categories_;
118 };
119
120 } // namespace ntp_snippets
121
122 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698