OLD | NEW |
(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.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 delegate before it shuts down. |
| 25 class ContentSuggestionsProvider { |
| 26 public: |
| 27 using ImageFetchedCallback = |
| 28 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; |
| 29 |
| 30 // The delegate of a provider is notified when new data is available. |
| 31 class Delegate { |
| 32 public: |
| 33 // Called when the available content changed. |
| 34 // If a provider provides suggestions of multiple categories, it must call |
| 35 // this callback for every category individually. The |suggestions| |
| 36 // parameter should always contain the full list of currently available |
| 37 // suggestions of that category, i.e., passing an empty list will remove |
| 38 // all suggestions of the given category for the provider. Note that to |
| 39 // clear them from the UI immediately, the provider needs to shut down. The |
| 40 // list must not contain ContentSuggestions assigned to a category other |
| 41 // than the passed |changed_category|. |
| 42 virtual void OnSuggestionsChanged( |
| 43 const ContentSuggestionsProvider& source, |
| 44 ContentSuggestionCategory changed_category, |
| 45 std::vector<ContentSuggestion> suggestions) = 0; |
| 46 virtual void OnProviderShutdown( |
| 47 const ContentSuggestionsProvider& source) = 0; |
| 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 ClearCachedSuggestions() {} |
| 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). |
| 69 virtual void Discard(const std::string& suggestion_id) = 0; |
| 70 |
| 71 // Fetches the image for the suggestion with the given ID and returns it |
| 72 // through the callback. This fetch may occur locally or from the internet. |
| 73 virtual void FetchImage(const std::string& suggestion_id, |
| 74 const ImageFetchedCallback& callback) = 0; |
| 75 |
| 76 protected: |
| 77 virtual ~ContentSuggestionsProvider() {} |
| 78 }; |
| 79 |
| 80 } // namespace ntp_snippets |
| 81 |
| 82 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
OLD | NEW |