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..c73ba6b650acfe8efcc25dd929095f0d4c1a49a7 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,19 @@ 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_ = |
+ ContentSuggestionsCategoryStatus::LOADING; |
Marc Treib
2016/07/08 13:26:02
Do we need both this and state_? Seems that it sho
Philipp Keck
2016/07/08 14:02:55
Yes, state_ and the "disabled reason" together are
Marc Treib
2016/07/08 15:17:23
Hm. We have fairly nice handling of state transiti
Philipp Keck
2016/07/08 16:17:01
The NTPSnippetsService's state diagram is quite ne
Marc Treib
2016/07/11 08:41:33
Alright. But I still don't like how category_statu
Philipp Keck
2016/07/11 09:41:49
Done.
|
+ |
PrefService* pref_service_; |
suggestions::SuggestionsService* suggestions_service_; |
@@ -271,8 +281,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_ = nullptr; |
+ |
// Scheduler for fetching snippets. Not owned. |
NTPSnippetsScheduler* scheduler_; |
@@ -308,6 +322,10 @@ class NTPSnippetsService : public KeyedService, |
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. |
+ // TODO(pke): Remove this when snippets internals don't access this service |
Marc Treib
2016/07/08 13:26:02
The whole class should be removed, right? Then I'd
Philipp Keck
2016/07/08 14:02:55
Done.
|
+ // directly anymore. |
virtual void NTPSnippetsServiceLoaded() = 0; |
// Sent when the service is shutting down. |