| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // that to clear them from the UI immediately, the provider needs to change | 42 // that to clear them from the UI immediately, the provider needs to change |
| 43 // the status of the respective category. If the given |category| is not | 43 // the status of the respective category. If the given |category| is not |
| 44 // known yet, the calling |provider| will be registered as its provider. | 44 // known yet, the calling |provider| will be registered as its provider. |
| 45 // IDs for the ContentSuggestions should be generated with | 45 // IDs for the ContentSuggestions should be generated with |
| 46 // |MakeUniqueID(..)| below. | 46 // |MakeUniqueID(..)| below. |
| 47 virtual void OnNewSuggestions( | 47 virtual void OnNewSuggestions( |
| 48 ContentSuggestionsProvider* provider, | 48 ContentSuggestionsProvider* provider, |
| 49 Category category, | 49 Category category, |
| 50 std::vector<ContentSuggestion> suggestions) = 0; | 50 std::vector<ContentSuggestion> suggestions) = 0; |
| 51 | 51 |
| 52 // Called when the status of a category changed. | 52 // Called when the status of a category changed, including when it is added. |
| 53 // If |new_status| is NOT_PROVIDED, the calling provider must be the one | 53 // If |new_status| is NOT_PROVIDED, the calling provider must be the one |
| 54 // that currently provides the |category|, and the category is unregistered | 54 // that currently provides the |category|, and the category is unregistered |
| 55 // without clearing the UI. The |category| must also be removed from | 55 // without clearing the UI. |
| 56 // |GetProvidedCategories()|. | |
| 57 // If |new_status| is any other value, it must match the value that is | 56 // If |new_status| is any other value, it must match the value that is |
| 58 // currently returned from the provider's |GetCategoryStatus(category)|. In | 57 // currently returned from the provider's |GetCategoryStatus(category)|. In |
| 59 // case the given |category| is not known yet, the calling |provider| will | 58 // case the given |category| is not known yet, the calling |provider| will |
| 60 // be registered as its provider. Whenever the status changes to an | 59 // be registered as its provider. Whenever the status changes to an |
| 61 // unavailable status, all suggestions in that category must immediately be | 60 // unavailable status, all suggestions in that category must immediately be |
| 62 // removed from all caches and from the UI, but the provider remains | 61 // removed from all caches and from the UI, but the provider remains |
| 63 // registered. | 62 // registered. |
| 64 virtual void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 63 virtual void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
| 65 Category category, | 64 Category category, |
| 66 CategoryStatus new_status) = 0; | 65 CategoryStatus new_status) = 0; |
| 67 | 66 |
| 68 // Called when a suggestion has been invalidated. It will not be provided | 67 // Called when a suggestion has been invalidated. It will not be provided |
| 69 // through |OnNewSuggestions| anymore, is not supported by | 68 // through |OnNewSuggestions| anymore, is not supported by |
| 70 // |FetchSuggestionImage| or |DismissSuggestion| anymore, and should | 69 // |FetchSuggestionImage| or |DismissSuggestion| anymore, and should |
| 71 // immediately be cleared from the UI and caches. This happens, for example, | 70 // immediately be cleared from the UI and caches. This happens, for example, |
| 72 // when the content that the suggestion refers to is gone. | 71 // when the content that the suggestion refers to is gone. |
| 73 // Note that this event may be fired even if the corresponding |category| is | 72 // 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 | 73 // 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 | 74 // 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. | 75 // |suggestion_id|s that never existed and should be ignored in that case. |
| 77 virtual void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, | 76 virtual void OnSuggestionInvalidated(ContentSuggestionsProvider* provider, |
| 78 Category category, | 77 Category category, |
| 79 const std::string& suggestion_id) = 0; | 78 const std::string& suggestion_id) = 0; |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 virtual ~ContentSuggestionsProvider(); | 81 virtual ~ContentSuggestionsProvider(); |
| 83 | 82 |
| 84 // Returns the categories provided by this provider. | |
| 85 // When the set of provided categories changes, the Observer is notified | |
| 86 // through |OnNewSuggestions| or |OnCategoryStatusChanged| for added | |
| 87 // categories, and through |OnCategoryStatusChanged| with parameter | |
| 88 // NOT_PROVIDED for removed categories. | |
| 89 virtual std::vector<Category> GetProvidedCategories() = 0; | |
| 90 | |
| 91 // Determines the status of the given |category|, see CategoryStatus. | 83 // Determines the status of the given |category|, see CategoryStatus. |
| 92 virtual CategoryStatus GetCategoryStatus(Category category) = 0; | 84 virtual CategoryStatus GetCategoryStatus(Category category) = 0; |
| 93 | 85 |
| 94 // Returns the meta information for the given |category|. | 86 // Returns the meta information for the given |category|. |
| 95 virtual CategoryInfo GetCategoryInfo(Category category) = 0; | 87 virtual CategoryInfo GetCategoryInfo(Category category) = 0; |
| 96 | 88 |
| 97 // Dismisses the suggestion with the given ID. A provider needs to ensure that | 89 // Dismisses the suggestion with the given ID. A provider needs to ensure that |
| 98 // a once-dismissed suggestion is never delivered again (through the | 90 // a once-dismissed suggestion is never delivered again (through the |
| 99 // Observer). The provider must not call Observer::OnSuggestionsChanged if the | 91 // Observer). The provider must not call Observer::OnSuggestionsChanged if the |
| 100 // removal of the dismissed suggestion is the only change. | 92 // removal of the dismissed suggestion is the only change. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 CategoryFactory* category_factory() const { return category_factory_; } | 139 CategoryFactory* category_factory() const { return category_factory_; } |
| 148 | 140 |
| 149 private: | 141 private: |
| 150 Observer* observer_; | 142 Observer* observer_; |
| 151 CategoryFactory* category_factory_; | 143 CategoryFactory* category_factory_; |
| 152 }; | 144 }; |
| 153 | 145 |
| 154 } // namespace ntp_snippets | 146 } // namespace ntp_snippets |
| 155 | 147 |
| 156 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ | 148 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |