OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // Called when the provider needs to shut down and will not deliver any | 59 // Called when the provider needs to shut down and will not deliver any |
60 // suggestions anymore. | 60 // suggestions anymore. |
61 virtual void OnProviderShutdown(ContentSuggestionsProvider* provider) = 0; | 61 virtual void OnProviderShutdown(ContentSuggestionsProvider* provider) = 0; |
62 }; | 62 }; |
63 | 63 |
64 // Sets an observer which is notified about changes to the available | 64 // Sets an observer which is notified about changes to the available |
65 // suggestions, or removes it by passing a nullptr. The provider does not take | 65 // suggestions, or removes it by passing a nullptr. The provider does not take |
66 // ownership of the observer and the observer must outlive this provider. | 66 // ownership of the observer and the observer must outlive this provider. |
67 virtual void SetObserver(Observer* observer) = 0; | 67 virtual void SetObserver(Observer* observer) = 0; |
68 | 68 |
| 69 // Returns the categories provided by this provider. |
| 70 // TODO(pke): "The value returned by this getter must not change unless |
| 71 // OnXxx is called on the observer." |
| 72 virtual std::vector<ContentSuggestionsCategory> GetProvidedCategories() = 0; |
| 73 |
69 // Determines the status of the given |category|, see | 74 // Determines the status of the given |category|, see |
70 // ContentSuggestionsCategoryStatus. | 75 // ContentSuggestionsCategoryStatus. |
71 virtual ContentSuggestionsCategoryStatus GetCategoryStatus( | 76 virtual ContentSuggestionsCategoryStatus GetCategoryStatus( |
72 ContentSuggestionsCategory category) = 0; | 77 ContentSuggestionsCategory category) = 0; |
73 | 78 |
74 // Dismisses the suggestion with the given ID. A provider needs to ensure that | 79 // Dismisses the suggestion with the given ID. A provider needs to ensure that |
75 // a once-dismissed suggestion is never delivered again (through the | 80 // a once-dismissed suggestion is never delivered again (through the |
76 // Observer). The provider must not call Observer::OnSuggestionsChanged if the | 81 // Observer). The provider must not call Observer::OnSuggestionsChanged if the |
77 // removal of the dismissed suggestion is the only change. | 82 // removal of the dismissed suggestion is the only change. |
78 virtual void DismissSuggestion(const std::string& suggestion_id) = 0; | 83 virtual void DismissSuggestion(const std::string& suggestion_id) = 0; |
79 | 84 |
80 // Fetches the image for the suggestion with the given ID and returns it | 85 // Fetches the image for the suggestion with the given ID and returns it |
81 // through the callback. This fetch may occur locally or from the internet. | 86 // through the callback. This fetch may occur locally or from the internet. |
82 // If that suggestion doesn't exist, doesn't have an image or if the fetch | 87 // If that suggestion doesn't exist, doesn't have an image or if the fetch |
83 // fails, the callback gets a null image. | 88 // fails, the callback gets a null image. |
84 virtual void FetchSuggestionImage(const std::string& suggestion_id, | 89 virtual void FetchSuggestionImage(const std::string& suggestion_id, |
85 const ImageFetchedCallback& callback) = 0; | 90 const ImageFetchedCallback& callback) = 0; |
86 | 91 |
87 // Used only for debugging purposes. Clears all caches so that the next | 92 // Used only for debugging purposes. Clears all caches so that the next |
88 // fetch starts from scratch. | 93 // fetch starts from scratch. |
89 virtual void ClearCachedSuggestionsForDebugging() = 0; | 94 virtual void ClearCachedSuggestionsForDebugging() = 0; |
90 | 95 |
91 // Used only for debugging purposes. Clears the cache of dismissed | 96 // Used only for debugging purposes. Clears the cache of dismissed |
92 // suggestions, if present, so that no suggestions are suppressed. This does | 97 // suggestions, if present, so that no suggestions are suppressed. This does |
93 // not necessarily make previously dismissed suggestions reappear, as they may | 98 // not necessarily make previously dismissed suggestions reappear, as they may |
94 // have been permanently deleted, depending on the provider implementation. | 99 // have been permanently deleted, depending on the provider implementation. |
95 virtual void ClearDismissedSuggestionsForDebugging() = 0; | 100 virtual void ClearDismissedSuggestionsForDebugging() = 0; |
96 | 101 |
97 const std::vector<ContentSuggestionsCategory>& provided_categories() const { | |
98 return provided_categories_; | |
99 } | |
100 | |
101 protected: | 102 protected: |
102 ContentSuggestionsProvider( | 103 ContentSuggestionsProvider( |
103 const std::vector<ContentSuggestionsCategory>& provided_categories); | 104 ContentSuggestionsCategoryFactory* category_factory); |
104 virtual ~ContentSuggestionsProvider(); | 105 virtual ~ContentSuggestionsProvider(); |
105 | 106 |
106 // Creates a unique ID. The given |within_category_id| must be unique among | 107 // Creates a unique ID. The given |within_category_id| must be unique among |
107 // all suggestion IDs from this provider for the given |category|. This method | 108 // all suggestion IDs from this provider for the given |category|. This method |
108 // combines it with the |category| to form an ID that is unique | 109 // combines it with the |category| to form an ID that is unique |
109 // application-wide, because this provider is the only one that provides | 110 // application-wide, because this provider is the only one that provides |
110 // suggestions for that category. | 111 // suggestions for that category. |
111 static std::string MakeUniqueID(ContentSuggestionsCategory category, | 112 std::string MakeUniqueID(ContentSuggestionsCategory category, |
112 const std::string& within_category_id); | 113 const std::string& within_category_id); |
113 // Reverse functions for MakeUniqueID() | 114 // Reverse functions for MakeUniqueID() |
114 static ContentSuggestionsCategory GetCategoryFromUniqueID( | 115 ContentSuggestionsCategory GetCategoryFromUniqueID( |
115 const std::string& unique_id); | 116 const std::string& unique_id); |
116 static std::string GetWithinCategoryIDFromUniqueID( | 117 std::string GetWithinCategoryIDFromUniqueID(const std::string& unique_id); |
117 const std::string& unique_id); | 118 |
| 119 ContentSuggestionsCategoryFactory* category_factory() const { |
| 120 return category_factory_; |
| 121 } |
118 | 122 |
119 private: | 123 private: |
120 const std::vector<ContentSuggestionsCategory> provided_categories_; | 124 ContentSuggestionsCategoryFactory* category_factory_; |
121 }; | 125 }; |
122 | 126 |
123 } // namespace ntp_snippets | 127 } // namespace ntp_snippets |
124 | 128 |
125 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ | 129 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
OLD | NEW |