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

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: 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 <set>
Marc Treib 2016/06/28 11:29:09 not needed
Philipp Keck 2016/06/28 14:18:55 Done.
9 #include <string>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "components/ntp_snippets/content_suggestion.h"
14 #include "components/ntp_snippets/content_suggestions_provider_type.h"
15
16 namespace gfx {
17 class Image;
18 }
19
20 namespace ntp_snippets {
21
22 // Provides content suggestions from one particular source. The provided
23 // suggestions can belong to different ContentSuggestionCategories. A provider
24 // can be a keyed service, in which case it should notify the
25 // ContentSuggestionsService through the delegate before it shuts down.
26 class ContentSuggestionsProvider {
27 public:
28 using ImageFetchedCallback =
29 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>;
30
31 // The delegate of a provider is notified when new data is available.
32 class Delegate {
33 public:
34 // Called when the available content changed.
35 // If a provider provides suggestions of multiple categories, it must call
36 // this callback for every category individually. The |suggestions|
37 // parameter should always contain the full list of currently available
38 // suggestions of that category, i.e., passing an empty list will remove
39 // all suggestions of the given category for the provider. Note that to
40 // clear them from the UI immediately, the provider needs to shut down. The
41 // list must not contain ContentSuggestions assigned to a category other
42 // than the passed |changed_category|.
43 virtual void OnContentChanged(
44 const ContentSuggestionsProvider& source,
Marc Treib 2016/06/28 11:29:08 Should this just pass the provider type? Seems lik
Philipp Keck 2016/06/28 14:18:55 That would indeed be enough, the service has the m
Marc Treib 2016/06/28 15:04:55 Oh, I'm not worried about performance. But the ser
tschumann 2016/06/28 16:48:35 I don't want to sidetrack the whole discussion, bu
Philipp Keck 2016/06/30 09:35:34 Thank you. The code here now passes the provider_t
45 ContentSuggestionCategory changed_category,
46 std::vector<ContentSuggestion> suggestions) = 0;
47 virtual void OnProviderShutdown(const ContentSuggestionsProvider& source){};
Marc Treib 2016/06/28 11:29:09 nit: space before "{" and no ";" (though really, t
Philipp Keck 2016/06/28 14:18:55 Done. Replaced with "= 0". You are right, default
48 };
49
50 // Returns the type of the provider.
51 virtual ContentSuggestionsProviderType GetProviderType() const = 0;
52
53 // Accessor for delegate, which is notified about new available suggestions.
54 virtual void SetDelegate(Delegate* delegate) = 0;
55
56 // Used only for debugging purposes. Clears all caches so that the next
57 // fetch starts from scratch.
58 virtual void ClearSuggestions() {}
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() {}
65
66 // Discards the suggestion with the given ID. A provider needs to ensure that
67 // a once-discarded suggestion is never delivered again (through the
68 // Delegate). It can do so by deleting it from the underlying source or by
69 // marking it as discarded internally.
Marc Treib 2016/06/28 11:29:08 I'd remove the last sentence, since it's not reall
Philipp Keck 2016/06/28 14:18:55 Done.
70 virtual void Discard(const std::string& suggestion_id) {}
Marc Treib 2016/06/28 11:29:08 This shouldn't have a default implementation. Prob
Philipp Keck 2016/06/28 14:18:55 Removed the default implementation. I left the de
Marc Treib 2016/06/28 15:04:55 I think it's still better for those providers to e
Philipp Keck 2016/06/30 09:35:34 Done.
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.
Marc Treib 2016/06/28 11:29:08 nit: don't capitalize internet
Philipp Keck 2016/06/28 14:18:55 Done.
74 virtual void FetchImage(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