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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // registered. | 63 // registered. |
64 virtual void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 64 virtual void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
65 Category category, | 65 Category category, |
66 CategoryStatus new_status) = 0; | 66 CategoryStatus new_status) = 0; |
67 | 67 |
68 // Called when a suggestion has been invalidated. It will not be provided | 68 // Called when a suggestion has been invalidated. It will not be provided |
69 // through |OnNewSuggestions| anymore, is not supported by | 69 // through |OnNewSuggestions| anymore, is not supported by |
70 // |FetchSuggestionImage| or |DismissSuggestion| anymore, and should | 70 // |FetchSuggestionImage| or |DismissSuggestion| anymore, and should |
71 // immediately be cleared from the UI and caches. This happens, for example, | 71 // immediately be cleared from the UI and caches. This happens, for example, |
72 // when the content that the suggestion refers to is gone. | 72 // when the content that the suggestion refers to is gone. |
73 // Note that this event may be fired even if the corresponding |category| is | 73 // Note that this event may be fired even if the corresponding category is |
74 // not currently AVAILABLE, because open UIs may still be showing the | 74 // not currently AVAILABLE, because open UIs may still be showing the |
75 // suggestion that is to be removed. This event may also be fired for | 75 // suggestion that is to be removed. This event may also be fired for |
76 // |suggestion_id|s that never existed and should be ignored in that case. | 76 // |suggestion_id|s that never existed and should be ignored in that case. |
77 virtual void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, | 77 virtual void OnSuggestionInvalidated( |
78 Category category, | 78 ContentSuggestionsProvider* provider, |
79 const std::string& suggestion_id) = 0; | 79 const ContentSuggestion::ID& suggestion_id) = 0; |
80 }; | 80 }; |
81 | 81 |
82 virtual ~ContentSuggestionsProvider(); | 82 virtual ~ContentSuggestionsProvider(); |
83 | 83 |
84 // Determines the status of the given |category|, see CategoryStatus. | 84 // Determines the status of the given |category|, see CategoryStatus. |
85 virtual CategoryStatus GetCategoryStatus(Category category) = 0; | 85 virtual CategoryStatus GetCategoryStatus(Category category) = 0; |
86 | 86 |
87 // Returns the meta information for the given |category|. | 87 // Returns the meta information for the given |category|. |
88 virtual CategoryInfo GetCategoryInfo(Category category) = 0; | 88 virtual CategoryInfo GetCategoryInfo(Category category) = 0; |
89 | 89 |
90 // Dismisses the suggestion with the given ID. A provider needs to ensure that | 90 // Dismisses the suggestion with the given ID. A provider needs to ensure that |
91 // a once-dismissed suggestion is never delivered again (through the | 91 // a once-dismissed suggestion is never delivered again (through the |
92 // Observer). The provider must not call Observer::OnSuggestionsChanged if the | 92 // Observer). The provider must not call Observer::OnSuggestionsChanged if the |
93 // removal of the dismissed suggestion is the only change. | 93 // removal of the dismissed suggestion is the only change. |
94 virtual void DismissSuggestion(const std::string& suggestion_id) = 0; | 94 virtual void DismissSuggestion( |
| 95 const ContentSuggestion::ID& suggestion_id) = 0; |
95 | 96 |
96 // Fetches the image for the suggestion with the given ID and returns it | 97 // Fetches the image for the suggestion with the given ID and returns it |
97 // through the callback. This fetch may occur locally or from the internet. | 98 // through the callback. This fetch may occur locally or from the internet. |
98 // If that suggestion doesn't exist, doesn't have an image or if the fetch | 99 // If that suggestion doesn't exist, doesn't have an image or if the fetch |
99 // fails, the callback gets a null image. The callback will not be called | 100 // fails, the callback gets a null image. The callback will not be called |
100 // synchronously. | 101 // synchronously. |
101 virtual void FetchSuggestionImage(const std::string& suggestion_id, | 102 virtual void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, |
102 const ImageFetchedCallback& callback) = 0; | 103 const ImageFetchedCallback& callback) = 0; |
103 | 104 |
104 // Removes history from the specified time range where the URL matches the | 105 // Removes history from the specified time range where the URL matches the |
105 // |filter|. The data removed depends on the provider. Note that the | 106 // |filter|. The data removed depends on the provider. Note that the |
106 // data outside the time range may be deleted, for example suggestions, which | 107 // data outside the time range may be deleted, for example suggestions, which |
107 // are based on history from that time range. Providers should immediately | 108 // are based on history from that time range. Providers should immediately |
108 // clear any data related to history from the specified time range where the | 109 // clear any data related to history from the specified time range where the |
109 // URL matches the |filter|. | 110 // URL matches the |filter|. |
110 virtual void ClearHistory( | 111 virtual void ClearHistory( |
111 base::Time begin, | 112 base::Time begin, |
(...skipping 17 matching lines...) Expand all Loading... |
129 // suggestions for the given |category|, if present, so that no suggestions | 130 // suggestions for the given |category|, if present, so that no suggestions |
130 // are suppressed. This does not necessarily make previously dismissed | 131 // are suppressed. This does not necessarily make previously dismissed |
131 // suggestions reappear, as they may have been permanently deleted, depending | 132 // suggestions reappear, as they may have been permanently deleted, depending |
132 // on the provider implementation. | 133 // on the provider implementation. |
133 virtual void ClearDismissedSuggestionsForDebugging(Category category) = 0; | 134 virtual void ClearDismissedSuggestionsForDebugging(Category category) = 0; |
134 | 135 |
135 protected: | 136 protected: |
136 ContentSuggestionsProvider(Observer* observer, | 137 ContentSuggestionsProvider(Observer* observer, |
137 CategoryFactory* category_factory); | 138 CategoryFactory* category_factory); |
138 | 139 |
139 // Creates a unique ID. The given |within_category_id| must be unique among | |
140 // all suggestion IDs from this provider for the given |category|. This method | |
141 // combines it with the |category| to form an ID that is unique | |
142 // application-wide, because this provider is the only one that provides | |
143 // suggestions for that category. | |
144 std::string MakeUniqueID(Category category, | |
145 const std::string& within_category_id) const; | |
146 | |
147 // Reverse functions for MakeUniqueID() | |
148 Category GetCategoryFromUniqueID(const std::string& unique_id) const; | |
149 std::string GetWithinCategoryIDFromUniqueID( | |
150 const std::string& unique_id) const; | |
151 | |
152 Observer* observer() const { return observer_; } | 140 Observer* observer() const { return observer_; } |
153 CategoryFactory* category_factory() const { return category_factory_; } | 141 CategoryFactory* category_factory() const { return category_factory_; } |
154 | 142 |
155 private: | 143 private: |
156 Observer* observer_; | 144 Observer* observer_; |
157 CategoryFactory* category_factory_; | 145 CategoryFactory* category_factory_; |
158 }; | 146 }; |
159 | 147 |
160 } // namespace ntp_snippets | 148 } // namespace ntp_snippets |
161 | 149 |
162 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ | 150 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
OLD | NEW |