Chromium Code Reviews| Index: components/ntp_snippets/content_suggestions_service.h |
| diff --git a/components/ntp_snippets/content_suggestions_service.h b/components/ntp_snippets/content_suggestions_service.h |
| index 9c7645cfb412cbc51d554597b73c19cad6fdc975..b93047982c61778e3c473e3b6a9f8b69f0e969d4 100644 |
| --- a/components/ntp_snippets/content_suggestions_service.h |
| +++ b/components/ntp_snippets/content_suggestions_service.h |
| @@ -22,6 +22,8 @@ class Image; |
| namespace ntp_snippets { |
| +class NTPSnippetsService; |
| + |
| // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
| // them grouped into categories. There can be at most one provider per category. |
| class ContentSuggestionsService : public KeyedService, |
| @@ -98,7 +100,7 @@ class ContentSuggestionsService : public KeyedService, |
| // Registers a new ContentSuggestionsProvider. It must be ensured that at most |
| // one provider is registered for every category and that this method is |
| // called only once per provider. |
| - void RegisterProvider(ContentSuggestionsProvider* provider); |
| + void RegisterProvider(std::unique_ptr<ContentSuggestionsProvider> provider); |
| // Only for debugging use through the internals page. |
| // Removes all suggestions from all caches or internal stores in all |
| @@ -116,6 +118,13 @@ class ContentSuggestionsService : public KeyedService, |
| CategoryFactory* category_factory() { return &category_factory_; } |
| + // The reference to the NTPSnippetsService provider should only be set by the |
| + // factory and only be used for scheduling, periodic fetching and debugging. |
| + NTPSnippetsService* ntp_snippets_service() { return ntp_snippets_service_; } |
| + void set_ntp_snippets_service(NTPSnippetsService* ntp_snippets_service) { |
| + ntp_snippets_service_ = ntp_snippets_service; |
| + } |
| + |
| private: |
| friend class ContentSuggestionsServiceTest; |
| @@ -132,7 +141,6 @@ class ContentSuggestionsService : public KeyedService, |
| void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
| Category category, |
| CategoryStatus new_status) override; |
| - void OnProviderShutdown(ContentSuggestionsProvider* provider) override; |
| // Registers the given |provider| for the given |category|, unless it is |
| // already registered. Returns true if the category was newly registered or |
| @@ -149,15 +157,19 @@ class ContentSuggestionsService : public KeyedService, |
| // Provides new and existing categories and an order for them. |
| CategoryFactory category_factory_; |
| - // All registered providers. A provider may be contained multiple times, if it |
| - // provides multiple categories. The keys of this map are exactly the entries |
| - // of |categories_|. |
| + // All registered providers, owned by the service. |
| + std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_; |
| + |
| + // All registered categories and their providers. A provider may be contained |
| + // multiple times, if it provides multiple categories. The keys of this map |
| + // are exactly the entries of |categories_| and the values are a subset of |
| + // |providers_|. |
| std::map<Category, ContentSuggestionsProvider*, CompareCategoriesByID> |
| providers_by_category_; |
| // All current suggestion categories, in an order determined by the |
| // |category_factory_|. This vector contains exactly the same categories as |
| - // |providers_|. |
| + // |providers_by_category_|. |
| std::vector<Category> categories_; |
| // All current suggestions grouped by category. This contains an entry for |
| @@ -176,6 +188,11 @@ class ContentSuggestionsService : public KeyedService, |
| const std::vector<ContentSuggestion> no_suggestions_; |
| + // Keep a direct reference to this special provider to redirect scheduling, |
| + // fetching and debugging calls to it. This is a pointer into |providers_| or |
|
Marc Treib
2016/08/03 11:53:23
It's not really a pointer into providers_, just pr
Marc Treib
2016/08/03 11:53:23
s/fetching/background fetching
Philipp Keck
2016/08/03 12:28:24
Done.
Philipp Keck
2016/08/03 12:28:24
Done.
|
| + // a nullptr if the provider is not loaded. |
| + NTPSnippetsService* ntp_snippets_service_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
| }; |