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_SERVICE_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves | 29 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
| 30 // them grouped into categories. There can be at most one provider per category. | 30 // them grouped into categories. There can be at most one provider per category. |
| 31 class ContentSuggestionsService : public KeyedService, | 31 class ContentSuggestionsService : public KeyedService, |
| 32 public ContentSuggestionsProvider::Observer { | 32 public ContentSuggestionsProvider::Observer { |
| 33 public: | 33 public: |
| 34 using ImageFetchedCallback = | 34 using ImageFetchedCallback = |
| 35 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; | 35 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; |
| 36 | 36 |
| 37 class Observer { | 37 class Observer { |
| 38 public: | 38 public: |
| 39 // Fired every time the service receives a new set of data, replacing any | 39 // Fired every time the service receives a new set of data for the given |
| 40 // previously available data (though in most cases there will be an overlap | 40 // |category|, replacing any previously available data (though in most cases |
| 41 // and only a few changes within the data). The new data is then available | 41 // there will be an overlap and only a few changes within the data). The new |
| 42 // through the getters of the service. | 42 // data is then available through |GetSuggestionsForCategory(category)|. |
| 43 virtual void OnNewSuggestions() = 0; | 43 virtual void OnNewSuggestions(Category category) = 0; |
| 44 | 44 |
| 45 // Fired when the status of a suggestions category changed. When the status | 45 // Fired when the status of a suggestions category changed. When the status |
| 46 // changes to an unavailable status, the suggestions of the respective | 46 // changes to an unavailable status, the suggestions of the respective |
| 47 // category have been invalidated, which means that they must no longer be | 47 // category have been invalidated, which means that they must no longer be |
| 48 // displayed to the user. The UI must immediately clear any suggestions of | 48 // displayed to the user. The UI must immediately clear any suggestions of |
| 49 // that category. | 49 // that category. |
| 50 virtual void OnCategoryStatusChanged(Category category, | 50 virtual void OnCategoryStatusChanged(Category category, |
| 51 CategoryStatus new_status) = 0; | 51 CategoryStatus new_status) = 0; |
| 52 | 52 |
| 53 // Sent when the service is shutting down. After the service has shut down, | 53 // Sent when the service is shutting down. After the service has shut down, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 83 base::Optional<CategoryInfo> GetCategoryInfo(Category category) const; | 83 base::Optional<CategoryInfo> GetCategoryInfo(Category category) const; |
| 84 | 84 |
| 85 // Gets the available suggestions for a category. The result is empty if the | 85 // Gets the available suggestions for a category. The result is empty if the |
| 86 // category is available and empty, but also if the category is unavailable | 86 // category is available and empty, but also if the category is unavailable |
| 87 // for any reason, see |GetCategoryStatus()|. | 87 // for any reason, see |GetCategoryStatus()|. |
| 88 const std::vector<ContentSuggestion>& GetSuggestionsForCategory( | 88 const std::vector<ContentSuggestion>& GetSuggestionsForCategory( |
| 89 Category category) const; | 89 Category category) const; |
| 90 | 90 |
| 91 // Fetches the image for the suggestion with the given |suggestion_id| and | 91 // Fetches the image for the suggestion with the given |suggestion_id| and |
| 92 // runs the |callback|. If that suggestion doesn't exist or the fetch fails, | 92 // runs the |callback|. If that suggestion doesn't exist or the fetch fails, |
| 93 // the callback gets an empty image. | 93 // the callback gets an empty image. The callback must not be called |
|
Marc Treib
2016/08/09 14:42:57
and here
Philipp Keck
2016/08/09 16:59:16
Done.
| |
| 94 // synchronously. | |
| 94 void FetchSuggestionImage(const std::string& suggestion_id, | 95 void FetchSuggestionImage(const std::string& suggestion_id, |
| 95 const ImageFetchedCallback& callback); | 96 const ImageFetchedCallback& callback); |
| 96 | 97 |
| 97 // Dismisses the suggestion with the given |suggestion_id|, if it exists. | 98 // Dismisses the suggestion with the given |suggestion_id|, if it exists. |
| 98 // This will not trigger an update through the observers. | 99 // This will not trigger an update through the observers. |
| 99 void DismissSuggestion(const std::string& suggestion_id); | 100 void DismissSuggestion(const std::string& suggestion_id); |
| 100 | 101 |
| 101 // Observer accessors. | 102 // Observer accessors. |
| 102 void AddObserver(Observer* observer); | 103 void AddObserver(Observer* observer); |
| 103 void RemoveObserver(Observer* observer); | 104 void RemoveObserver(Observer* observer); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 // background fetching and debugging calls to it. If the NTPSnippetsService is | 212 // background fetching and debugging calls to it. If the NTPSnippetsService is |
| 212 // loaded, it is also present in |providers_|, otherwise this is a nullptr. | 213 // loaded, it is also present in |providers_|, otherwise this is a nullptr. |
| 213 NTPSnippetsService* ntp_snippets_service_; | 214 NTPSnippetsService* ntp_snippets_service_; |
| 214 | 215 |
| 215 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 216 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
| 216 }; | 217 }; |
| 217 | 218 |
| 218 } // namespace ntp_snippets | 219 } // namespace ntp_snippets |
| 219 | 220 |
| 220 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 221 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |