Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_service.h |
| diff --git a/components/ntp_snippets/ntp_snippets_service.h b/components/ntp_snippets/ntp_snippets_service.h |
| index 5c0ed8c0a6a88c89120da5c94f692c040c1fea0d..1c7c44c9ed3ba63c08cde0bbff6d5124b9077ba8 100644 |
| --- a/components/ntp_snippets/ntp_snippets_service.h |
| +++ b/components/ntp_snippets/ntp_snippets_service.h |
| @@ -19,6 +19,8 @@ |
| #include "base/timer/timer.h" |
| #include "components/image_fetcher/image_fetcher_delegate.h" |
| #include "components/keyed_service/core/keyed_service.h" |
| +#include "components/ntp_snippets/content_suggestion.h" |
| +#include "components/ntp_snippets/content_suggestions_provider.h" |
| #include "components/ntp_snippets/ntp_snippet.h" |
| #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| #include "components/ntp_snippets/ntp_snippets_scheduler.h" |
| @@ -59,10 +61,11 @@ class NTPSnippetsServiceObserver; |
| // Stores and vends fresh content data for the NTP. |
| class NTPSnippetsService : public KeyedService, |
| - public image_fetcher::ImageFetcherDelegate { |
| + public image_fetcher::ImageFetcherDelegate, |
| + public ContentSuggestionsProvider { |
| public: |
| using ImageFetchedCallback = |
| - base::Callback<void(const std::string& snippet_id, const gfx::Image&)>; |
| + base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; |
| // |application_language_code| should be a ISO 639-1 compliant string, e.g. |
| // 'en' or 'en-US'. Note that this code should only specify the language, not |
| @@ -126,21 +129,17 @@ class NTPSnippetsService : public KeyedService, |
| // the schedule depends on the time of day. |
| void RescheduleFetching(); |
| - // Fetches the image for the snippet with the given |snippet_id| and runs the |
| - // |callback|. If that snippet doesn't exist or the fetch fails, the callback |
| - // gets a null image. |
| - void FetchSnippetImage(const std::string& snippet_id, |
| - const ImageFetchedCallback& callback); |
| - |
| - // Deletes all currently stored snippets. |
| - void ClearSnippets(); |
| - |
| - // Discards the snippet with the given |snippet_id|, if it exists. Returns |
| - // true iff a snippet was discarded. |
| - bool DiscardSnippet(const std::string& snippet_id); |
| - |
| - // Clears the lists of snippets previously discarded by the user. |
| - void ClearDiscardedSnippets(); |
| + // ContentSuggestionsProvider implementation |
| + // TODO(pke): At some point reorder the implementations in the .cc file |
| + // accordingly. |
| + void SetObserver(Observer* observer) override; |
| + ContentSuggestionsCategoryStatus GetCategoryStatus( |
| + ContentSuggestionsCategory category) override; |
| + void DiscardSuggestion(const std::string& suggestion_id) override; |
| + void FetchSuggestionImage(const std::string& suggestion_id, |
| + const ImageFetchedCallback& callback) override; |
| + void ClearCachedSuggestionsForDebugging() override; |
| + void ClearDiscardedSuggestionsForDebugging() override; |
| // Returns the lists of suggestion hosts the snippets are restricted to. |
| std::set<std::string> GetSuggestionsHosts() const; |
| @@ -254,8 +253,18 @@ class NTPSnippetsService : public KeyedService, |
| void ClearDeprecatedPrefs(); |
| + // Converts the cached snippets to article content suggestions and notifies |
| + // the observers. |
| + void NotifyNewSuggestions(); |
| + |
| + // Notifies the content suggestions observer about a change in the |
| + // |category_status_|. |
| + void NotifyCategoryStatusChanged(); |
| + |
| State state_; |
| + ContentSuggestionsCategoryStatus category_status_; |
| + |
| PrefService* pref_service_; |
| suggestions::SuggestionsService* suggestions_service_; |
| @@ -271,8 +280,12 @@ class NTPSnippetsService : public KeyedService, |
| const std::string application_language_code_; |
| // The observers. |
| + // TODO(pke): This is an old kind of observers that will be removed. |
| base::ObserverList<NTPSnippetsServiceObserver> observers_; |
| + // The observer to deliver data to. |
| + Observer* observer_; |
| + |
| // Scheduler for fetching snippets. Not owned. |
| NTPSnippetsScheduler* scheduler_; |
| @@ -305,9 +318,13 @@ class NTPSnippetsService : public KeyedService, |
| DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); |
| }; |
| +// TODO(pke): Remove this when snippets internals don't access this service |
| +// directly anymore. |
| class NTPSnippetsServiceObserver { |
| public: |
| // Sent every time the service loads a new set of data. |
| + // This is called in addition to the ContentSuggestionsProvider::Observer and |
| + // should only be used by snippets-internals. |
|
Marc Treib
2016/07/11 08:41:33
nit: I'd remove this comment. As of now, this meth
Philipp Keck
2016/07/11 09:41:49
Done.
|
| virtual void NTPSnippetsServiceLoaded() = 0; |
| // Sent when the service is shutting down. |