Chromium Code Reviews| 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 <map> | |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 12 #include "components/ntp_snippets/category.h" | 13 #include "components/ntp_snippets/category.h" |
| 13 #include "components/ntp_snippets/category_info.h" | 14 #include "components/ntp_snippets/category_info.h" |
| 14 #include "components/ntp_snippets/category_status.h" | 15 #include "components/ntp_snippets/category_status.h" |
| 15 #include "components/ntp_snippets/content_suggestion.h" | 16 #include "components/ntp_snippets/content_suggestion.h" |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 28 // shut down by the ContentSuggestionsService. | 29 // shut down by the ContentSuggestionsService. |
| 29 class ContentSuggestionsProvider { | 30 class ContentSuggestionsProvider { |
| 30 public: | 31 public: |
| 31 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; | 32 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; |
| 32 using DismissedSuggestionsCallback = base::Callback<void( | 33 using DismissedSuggestionsCallback = base::Callback<void( |
| 33 std::vector<ContentSuggestion> dismissed_suggestions)>; | 34 std::vector<ContentSuggestion> dismissed_suggestions)>; |
| 34 | 35 |
| 35 // The observer of a provider is notified when new data is available. | 36 // The observer of a provider is notified when new data is available. |
| 36 class Observer { | 37 class Observer { |
| 37 public: | 38 public: |
| 39 typedef std:: | |
| 40 map<Category, std::vector<ContentSuggestion>, Category::CompareByID> | |
| 41 SuggestionBatch; | |
|
Marc Treib
2016/10/11 07:52:55
nit: using SuggestionBatch = ...
| |
| 42 | |
| 38 // Called when the available content changed. | 43 // Called when the available content changed. |
| 39 // If a provider provides suggestions for multiple categories, this callback | 44 // If a provider provides suggestions for multiple categories, it should |
| 40 // is called once per category. The |suggestions| parameter always contains | 45 // use OnNewSuggestionBatch() instead. The |suggestions| parameter always |
| 41 // the full list of currently available suggestions for that category, i.e., | 46 // contains the full list of currently available suggestions for that |
| 42 // an empty list will remove all suggestions from the given category. Note | 47 // category, i.e., an empty list will remove all suggestions from the given |
| 43 // that to clear them from the UI immediately, the provider needs to change | 48 // category. Note that to clear them from the UI immediately, the provider |
| 44 // the status of the respective category. If the given |category| is not | 49 // needs to change the status of the respective category. If the given |
| 45 // known yet, the calling |provider| will be registered as its provider. | 50 // |category| is not known yet, the calling |provider| will be registered as |
| 51 // its provider. | |
| 46 virtual void OnNewSuggestions( | 52 virtual void OnNewSuggestions( |
| 47 ContentSuggestionsProvider* provider, | 53 ContentSuggestionsProvider* provider, |
| 48 Category category, | 54 Category category, |
| 49 std::vector<ContentSuggestion> suggestions) = 0; | 55 std::vector<ContentSuggestion> suggestions) = 0; |
| 50 | 56 |
| 57 // Called when the available content for multiple categories changed. | |
| 58 // The |suggestions| parameter always contains the full list of currently | |
| 59 // available suggestions for that category, i.e., an empty list will remove | |
| 60 // all suggestions from the given category. Note that to clear them from the | |
| 61 // UI immediately, the provider needs to change the status of the respective | |
| 62 // category. If the given |category| is not known yet, the calling | |
| 63 // |provider| will be registered as its provider. | |
| 64 virtual void OnNewSuggestionBatch(ContentSuggestionsProvider* provider, | |
| 65 SuggestionBatch suggestion_batch) = 0; | |
|
Marc Treib
2016/10/11 07:52:55
Like Tim, I'm not happy with having two methods he
dgn
2016/10/11 19:14:01
As discussed offline, I'm going to remove this the
| |
| 66 | |
| 51 // Called when the status of a category changed, including when it is added. | 67 // Called when the status of a category changed, including when it is added. |
| 52 // If |new_status| is NOT_PROVIDED, the calling provider must be the one | 68 // If |new_status| is NOT_PROVIDED, the calling provider must be the one |
| 53 // that currently provides the |category|, and the category is unregistered | 69 // that currently provides the |category|, and the category is unregistered |
| 54 // without clearing the UI. | 70 // without clearing the UI. |
| 55 // If |new_status| is any other value, it must match the value that is | 71 // If |new_status| is any other value, it must match the value that is |
| 56 // currently returned from the provider's |GetCategoryStatus(category)|. In | 72 // currently returned from the provider's |GetCategoryStatus(category)|. In |
| 57 // case the given |category| is not known yet, the calling |provider| will | 73 // case the given |category| is not known yet, the calling |provider| will |
| 58 // be registered as its provider. Whenever the status changes to an | 74 // be registered as its provider. Whenever the status changes to an |
| 59 // unavailable status, all suggestions in that category must immediately be | 75 // unavailable status, all suggestions in that category must immediately be |
| 60 // removed from all caches and from the UI, but the provider remains | 76 // removed from all caches and from the UI, but the provider remains |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 CategoryFactory* category_factory() const { return category_factory_; } | 155 CategoryFactory* category_factory() const { return category_factory_; } |
| 140 | 156 |
| 141 private: | 157 private: |
| 142 Observer* observer_; | 158 Observer* observer_; |
| 143 CategoryFactory* category_factory_; | 159 CategoryFactory* category_factory_; |
| 144 }; | 160 }; |
| 145 | 161 |
| 146 } // namespace ntp_snippets | 162 } // namespace ntp_snippets |
| 147 | 163 |
| 148 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ | 164 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |