| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 std::unique_ptr<CategoryRanker> category_ranker); | 93 std::unique_ptr<CategoryRanker> category_ranker); |
| 94 ~ContentSuggestionsService() override; | 94 ~ContentSuggestionsService() override; |
| 95 | 95 |
| 96 // Inherited from KeyedService. | 96 // Inherited from KeyedService. |
| 97 void Shutdown() override; | 97 void Shutdown() override; |
| 98 | 98 |
| 99 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 99 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 100 | 100 |
| 101 State state() { return state_; } | 101 State state() { return state_; } |
| 102 | 102 |
| 103 // Gets all categories for which a provider is registered. The categories | 103 // Gets all categories for which a provider is registered. The categories may |
| 104 // may or may not be available, see |GetCategoryStatus()|. | 104 // or may not be available, see |GetCategoryStatus()|. The order in which the |
| 105 const std::vector<Category>& GetCategories() const { return categories_; } | 105 // categories are returned is the order in which they should be displayed. |
| 106 std::vector<Category> GetCategories() const; |
| 106 | 107 |
| 107 // Gets the status of a category. | 108 // Gets the status of a category. |
| 108 CategoryStatus GetCategoryStatus(Category category) const; | 109 CategoryStatus GetCategoryStatus(Category category) const; |
| 109 | 110 |
| 110 // Gets the meta information of a category. | 111 // Gets the meta information of a category. |
| 111 base::Optional<CategoryInfo> GetCategoryInfo(Category category) const; | 112 base::Optional<CategoryInfo> GetCategoryInfo(Category category) const; |
| 112 | 113 |
| 113 // Gets the available suggestions for a category. The result is empty if the | 114 // Gets the available suggestions for a category. The result is empty if the |
| 114 // category is available and empty, but also if the category is unavailable | 115 // category is available and empty, but also if the category is unavailable |
| 115 // for any reason, see |GetCategoryStatus()|. | 116 // for any reason, see |GetCategoryStatus()|. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 250 |
| 250 // Removes a suggestion from the local store |suggestions_by_category_|, if it | 251 // Removes a suggestion from the local store |suggestions_by_category_|, if it |
| 251 // exists. Returns true if a suggestion was removed. | 252 // exists. Returns true if a suggestion was removed. |
| 252 bool RemoveSuggestionByID(const ContentSuggestion::ID& suggestion_id); | 253 bool RemoveSuggestionByID(const ContentSuggestion::ID& suggestion_id); |
| 253 | 254 |
| 254 // Fires the OnCategoryStatusChanged event for the given |category|. | 255 // Fires the OnCategoryStatusChanged event for the given |category|. |
| 255 void NotifyCategoryStatusChanged(Category category); | 256 void NotifyCategoryStatusChanged(Category category); |
| 256 | 257 |
| 257 void OnSignInStateChanged(); | 258 void OnSignInStateChanged(); |
| 258 | 259 |
| 259 void SortCategories(); | |
| 260 | |
| 261 // Re-enables a dismissed category, making querying its provider possible. | 260 // Re-enables a dismissed category, making querying its provider possible. |
| 262 void RestoreDismissedCategory(Category category); | 261 void RestoreDismissedCategory(Category category); |
| 263 | 262 |
| 264 void RestoreDismissedCategoriesFromPrefs(); | 263 void RestoreDismissedCategoriesFromPrefs(); |
| 265 void StoreDismissedCategoriesToPrefs(); | 264 void StoreDismissedCategoriesToPrefs(); |
| 266 | 265 |
| 267 // Whether the content suggestions feature is enabled. | 266 // Whether the content suggestions feature is enabled. |
| 268 State state_; | 267 State state_; |
| 269 | 268 |
| 270 // All registered providers, owned by the service. | 269 // All registered providers, owned by the service. |
| 271 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_; | 270 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_; |
| 272 | 271 |
| 273 // All registered categories and their providers. A provider may be contained | 272 // All registered categories and their providers. A provider may be contained |
| 274 // multiple times, if it provides multiple categories. The keys of this map | 273 // multiple times, if it provides multiple categories. The keys of this map |
| 275 // are exactly the entries of |categories_| and the values are a subset of | 274 // are exactly the entries of |categories_| and the values are a subset of |
| 276 // |providers_|. | 275 // |providers_|. |
| 277 std::map<Category, ContentSuggestionsProvider*, Category::CompareByID> | 276 std::map<Category, ContentSuggestionsProvider*, Category::CompareByID> |
| 278 providers_by_category_; | 277 providers_by_category_; |
| 279 | 278 |
| 280 // All dismissed categories and their providers. These may be restored by | 279 // All dismissed categories and their providers. These may be restored by |
| 281 // RestoreDismissedCategories(). The provider can be null if the dismissed | 280 // RestoreDismissedCategories(). The provider can be null if the dismissed |
| 282 // category has received no updates since initialisation. | 281 // category has received no updates since initialisation. |
| 283 // (see RestoreDismissedCategoriesFromPrefs()) | 282 // (see RestoreDismissedCategoriesFromPrefs()) |
| 284 std::map<Category, ContentSuggestionsProvider*, Category::CompareByID> | 283 std::map<Category, ContentSuggestionsProvider*, Category::CompareByID> |
| 285 dismissed_providers_by_category_; | 284 dismissed_providers_by_category_; |
| 286 | 285 |
| 287 // All current suggestion categories, in an order determined by the | 286 // All current suggestion categories in arbitrary order. This vector contains |
| 288 // |category_factory_|. This vector contains exactly the same categories as | 287 // exactly the same categories as |providers_by_category_|. |
| 289 // |providers_by_category_|. | |
| 290 std::vector<Category> categories_; | 288 std::vector<Category> categories_; |
| 291 | 289 |
| 292 // All current suggestions grouped by category. This contains an entry for | 290 // All current suggestions grouped by category. This contains an entry for |
| 293 // every category in |categories_| whose status is an available status. It may | 291 // every category in |categories_| whose status is an available status. It may |
| 294 // contain an empty vector if the category is available but empty (or still | 292 // contain an empty vector if the category is available but empty (or still |
| 295 // loading). | 293 // loading). |
| 296 std::map<Category, std::vector<ContentSuggestion>, Category::CompareByID> | 294 std::map<Category, std::vector<ContentSuggestion>, Category::CompareByID> |
| 297 suggestions_by_category_; | 295 suggestions_by_category_; |
| 298 | 296 |
| 299 // Observer for the SigninManager. All observers are notified when the signin | 297 // Observer for the SigninManager. All observers are notified when the signin |
| (...skipping 22 matching lines...) Expand all Loading... |
| 322 | 320 |
| 323 // Provides order for categories. | 321 // Provides order for categories. |
| 324 std::unique_ptr<CategoryRanker> category_ranker_; | 322 std::unique_ptr<CategoryRanker> category_ranker_; |
| 325 | 323 |
| 326 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 324 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
| 327 }; | 325 }; |
| 328 | 326 |
| 329 } // namespace ntp_snippets | 327 } // namespace ntp_snippets |
| 330 | 328 |
| 331 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 329 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |