Chromium Code Reviews| Index: components/ntp_snippets/content_suggestions_provider.h |
| diff --git a/components/ntp_snippets/content_suggestions_provider.h b/components/ntp_snippets/content_suggestions_provider.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e8454b94aca18b2eecb8b7813ade6df89ccad5ba |
| --- /dev/null |
| +++ b/components/ntp_snippets/content_suggestions_provider.h |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
| +#define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
| + |
| +#include <set> |
|
Marc Treib
2016/06/28 11:29:09
not needed
Philipp Keck
2016/06/28 14:18:55
Done.
|
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "components/ntp_snippets/content_suggestion.h" |
| +#include "components/ntp_snippets/content_suggestions_provider_type.h" |
| + |
| +namespace gfx { |
| +class Image; |
| +} |
| + |
| +namespace ntp_snippets { |
| + |
| +// Provides content suggestions from one particular source. The provided |
| +// suggestions can belong to different ContentSuggestionCategories. A provider |
| +// can be a keyed service, in which case it should notify the |
| +// ContentSuggestionsService through the delegate before it shuts down. |
| +class ContentSuggestionsProvider { |
| + public: |
| + using ImageFetchedCallback = |
| + base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; |
| + |
| + // The delegate of a provider is notified when new data is available. |
| + class Delegate { |
| + public: |
| + // Called when the available content changed. |
| + // If a provider provides suggestions of multiple categories, it must call |
| + // this callback for every category individually. The |suggestions| |
| + // parameter should always contain the full list of currently available |
| + // suggestions of that category, i.e., passing an empty list will remove |
| + // all suggestions of the given category for the provider. Note that to |
| + // clear them from the UI immediately, the provider needs to shut down. The |
| + // list must not contain ContentSuggestions assigned to a category other |
| + // than the passed |changed_category|. |
| + virtual void OnContentChanged( |
| + 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
|
| + ContentSuggestionCategory changed_category, |
| + std::vector<ContentSuggestion> suggestions) = 0; |
| + 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
|
| + }; |
| + |
| + // Returns the type of the provider. |
| + virtual ContentSuggestionsProviderType GetProviderType() const = 0; |
| + |
| + // Accessor for delegate, which is notified about new available suggestions. |
| + virtual void SetDelegate(Delegate* delegate) = 0; |
| + |
| + // Used only for debugging purposes. Clears all caches so that the next |
| + // fetch starts from scratch. |
| + virtual void ClearSuggestions() {} |
| + |
| + // Used only for debugging purposes. Clears the cache of discarded |
| + // suggestions, if present, so that no suggestions are suppressed. This does |
| + // not necessarily make previously discarded suggestions reappear, as they may |
| + // have been permanently deleted, depending on the provider implementation. |
| + virtual void ClearDiscardedSuggestions() {} |
| + |
| + // Discards the suggestion with the given ID. A provider needs to ensure that |
| + // a once-discarded suggestion is never delivered again (through the |
| + // Delegate). It can do so by deleting it from the underlying source or by |
| + // 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.
|
| + 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.
|
| + |
| + // Fetches the image for the suggestion with the given ID and returns it |
| + // 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.
|
| + virtual void FetchImage(const std::string& suggestion_id, |
| + const ImageFetchedCallback& callback) = 0; |
| + |
| + protected: |
| + virtual ~ContentSuggestionsProvider() {} |
| +}; |
| + |
| +} // namespace ntp_snippets |
| + |
| +#endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |