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 <set> | 10 #include <set> |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 namespace ntp_snippets { | 34 namespace ntp_snippets { |
| 35 | 35 |
| 36 class NTPSnippetsService; | 36 class NTPSnippetsService; |
| 37 | 37 |
| 38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves | 38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
| 39 // them grouped into categories. There can be at most one provider per category. | 39 // them grouped into categories. There can be at most one provider per category. |
| 40 class ContentSuggestionsService : public KeyedService, | 40 class ContentSuggestionsService : public KeyedService, |
| 41 public ContentSuggestionsProvider::Observer, | 41 public ContentSuggestionsProvider::Observer, |
| 42 public history::HistoryServiceObserver { | 42 public history::HistoryServiceObserver { |
| 43 public: | 43 public: |
| 44 // TODO(treib): All these should probably be OnceCallback. | |
|
Bernhard Bauer
2016/10/28 16:26:00
I didn't know about that. Neat! :)
fhorschig
2016/11/02 05:06:12
Yeah, the logic was that these callbacks are respo
| |
| 44 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; | 45 using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>; |
| 45 using DismissedSuggestionsCallback = base::Callback<void( | 46 using DismissedSuggestionsCallback = base::Callback<void( |
| 46 std::vector<ContentSuggestion> dismissed_suggestions)>; | 47 std::vector<ContentSuggestion> dismissed_suggestions)>; |
| 48 using FetchedMoreCallback = | |
| 49 base::Callback<void(std::vector<ContentSuggestion> suggestions)>; | |
| 47 | 50 |
| 48 class Observer { | 51 class Observer { |
| 49 public: | 52 public: |
| 50 // Fired every time the service receives a new set of data for the given | 53 // Fired every time the service receives a new set of data for the given |
| 51 // |category|, replacing any previously available data (though in most cases | 54 // |category|, replacing any previously available data (though in most cases |
| 52 // there will be an overlap and only a few changes within the data). The new | 55 // there will be an overlap and only a few changes within the data). The new |
| 53 // data is then available through |GetSuggestionsForCategory(category)|. | 56 // data is then available through |GetSuggestionsForCategory(category)|. |
| 54 virtual void OnNewSuggestions(Category category) = 0; | 57 virtual void OnNewSuggestions(Category category) = 0; |
| 55 | 58 |
| 56 // Fired when the status of a suggestions category changed. When the status | 59 // Fired when the status of a suggestions category changed. When the status |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 // This will not trigger an update through the observers. | 131 // This will not trigger an update through the observers. |
| 129 void DismissCategory(Category category); | 132 void DismissCategory(Category category); |
| 130 | 133 |
| 131 // Restores all dismissed categories. | 134 // Restores all dismissed categories. |
| 132 // This will not trigger an update through the observers. | 135 // This will not trigger an update through the observers. |
| 133 void RestoreDismissedCategories(); | 136 void RestoreDismissedCategories(); |
| 134 | 137 |
| 135 // Returns whether |category| is dismissed. | 138 // Returns whether |category| is dismissed. |
| 136 bool IsCategoryDismissed(Category category) const; | 139 bool IsCategoryDismissed(Category category) const; |
| 137 | 140 |
| 141 // Fetches additional contents for the given |category|. If the fetch was | |
| 142 // completed, the given |callback| is called with the updated content. | |
| 143 // This includes new and old data. | |
| 144 void FetchMore(const Category& category, const FetchedMoreCallback& callback); | |
| 145 | |
| 138 // Observer accessors. | 146 // Observer accessors. |
| 139 void AddObserver(Observer* observer); | 147 void AddObserver(Observer* observer); |
| 140 void RemoveObserver(Observer* observer); | 148 void RemoveObserver(Observer* observer); |
| 141 | 149 |
| 142 // Registers a new ContentSuggestionsProvider. It must be ensured that at most | 150 // Registers a new ContentSuggestionsProvider. It must be ensured that at most |
| 143 // one provider is registered for every category and that this method is | 151 // one provider is registered for every category and that this method is |
| 144 // called only once per provider. | 152 // called only once per provider. |
| 145 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider); | 153 void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider); |
| 146 | 154 |
| 147 // Removes history from the specified time range where the URL matches the | 155 // Removes history from the specified time range where the URL matches the |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 PrefService* pref_service_; | 301 PrefService* pref_service_; |
| 294 | 302 |
| 295 UserClassifier user_classifier_; | 303 UserClassifier user_classifier_; |
| 296 | 304 |
| 297 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 305 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
| 298 }; | 306 }; |
| 299 | 307 |
| 300 } // namespace ntp_snippets | 308 } // namespace ntp_snippets |
| 301 | 309 |
| 302 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 310 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |