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

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: Minor corrections 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_provider_type.h"
14
15 namespace gfx {
16 class Image;
17 }
18
19 namespace ntp_snippets {
20
21 // Provides content suggestions from one particular source. The provided
22 // suggestions can belong to different ContentSuggestionCategories. A provider
23 // can be a keyed service, in which case it should notify the
24 // ContentSuggestionsService through the observer before it shuts down.
25 class ContentSuggestionsProvider {
26 public:
27 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>;
28
29 // The observer of a provider is notified when new data is available.
30 class Observer {
31 public:
32 // Called when the available content changed.
33 // If a provider provides suggestions of multiple categories, it must call
34 // this callback for every category individually. The |suggestions|
35 // parameter should always contain the full list of currently available
36 // suggestions of that category, i.e., passing an empty list will remove
37 // all suggestions of the given category for the provider. Note that to
38 // clear them from the UI immediately, the provider needs to shut down. The
39 // list must not contain ContentSuggestions assigned to a category other
40 // than the passed |changed_category|.
41 virtual void OnSuggestionsChanged(
Marc Treib 2016/06/30 10:36:53 Did we agree on a name here?
tschumann 2016/06/30 10:55:19 personally, I'd try to avoid the term 'change' in
Philipp Keck 2016/06/30 17:14:08 I also suggested OnContentChanged earlier. The na
Marc Treib 2016/07/01 09:15:32 IMO "OnSuggestionsAdded" would be a better (becaus
tschumann 2016/07/01 09:37:10 I see your point. My motivation was that the Obser
Philipp Keck 2016/07/01 13:00:03 Ok I understand your point now. It's basically a s
42 ContentSuggestionsProviderType provider_type,
43 ContentSuggestionCategory changed_category,
44 std::vector<ContentSuggestion> suggestions) = 0;
45
46 virtual void OnProviderShutdown(
tschumann 2016/06/30 10:55:19 can you document this function? When is it called?
Philipp Keck 2016/06/30 17:14:07 Done.
47 ContentSuggestionsProviderType provider_type) = 0;
48 };
49
50 // Returns the type of the provider.
51 virtual ContentSuggestionsProviderType GetProviderType() const = 0;
Marc Treib 2016/06/30 10:36:53 Hm, you could actually store the provider type her
Philipp Keck 2016/06/30 17:14:07 Done.
52
53 // Accessor for observer, which is notified about new available suggestions.
54 virtual void SetObserver(Observer* observer) = 0;
55
56 // Used only for debugging purposes. Clears all caches so that the next
57 // fetch starts from scratch.
58 virtual void ClearCachedSuggestions() = 0;
tschumann 2016/06/30 10:55:19 for functions which should not be called in produc
Philipp Keck 2016/06/30 17:14:07 Done.
59
60 // Used only for debugging purposes. Clears the cache of discarded
61 // suggestions, if present, so that no suggestions are suppressed. This does
62 // not necessarily make previously discarded suggestions reappear, as they may
63 // have been permanently deleted, depending on the provider implementation.
64 virtual void ClearDiscardedSuggestions() = 0;
65
66 // Discards the suggestion with the given ID. A provider needs to ensure that
Marc Treib 2016/06/30 10:36:53 nit: I'd put the "real" API methods before the deb
Philipp Keck 2016/06/30 17:14:07 Done.
67 // a once-discarded suggestion is never delivered again (through the
68 // Observer). There is no need to call the observer for an update after a
Marc Treib 2016/06/30 10:36:53 This formulation leaves it open whether the observ
Philipp Keck 2016/06/30 17:14:07 I didn't want to require that to happen because it
Marc Treib 2016/07/01 09:15:32 I'd slightly prefer sending no update, because the
Philipp Keck 2016/07/01 13:00:03 We have to answer this question twice (for both Ob
69 // suggestion has been discarded.
70 virtual void DiscardSuggestion(const std::string& suggestion_id) = 0;
71
72 // Fetches the image for the suggestion with the given ID and returns it
73 // through the callback. This fetch may occur locally or from the internet.
74 virtual void FetchSuggestionImage(const std::string& suggestion_id,
75 const ImageFetchedCallback& callback) = 0;
76
77 protected:
78 virtual ~ContentSuggestionsProvider() {}
79 };
80
81 } // namespace ntp_snippets
82
83 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698