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 555e0924e504475301a3f676a74790620d72e46d..cfb0b21c7644792a64ae20f5cb8b177b581b096c 100644 |
| --- a/components/ntp_snippets/ntp_snippets_service.h |
| +++ b/components/ntp_snippets/ntp_snippets_service.h |
| @@ -153,8 +153,8 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
| static int GetMaxSnippetCountForTesting(); |
| // Available snippets, only for unit tests. |
| - const NTPSnippet::PtrVector& GetSnippetsForTesting() const { |
| - return snippets_; |
| + const NTPSnippet::PtrVector& GetSnippetsForTesting(Category category) const { |
| + return categories_.find(category)->second.snippets; |
| } |
| private: |
| @@ -222,7 +222,7 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
| void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets); |
| // Merges newly available snippets with the previously available list. |
| - void MergeSnippets(NTPSnippet::PtrVector new_snippets); |
| + void MergeSnippets(Category category, NTPSnippet::PtrVector new_snippets); |
| std::set<std::string> GetSnippetHostsFromPrefs() const; |
| void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts); |
| @@ -239,14 +239,14 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
| void FinishInitialization(); |
| void OnSnippetImageFetchedFromDatabase(const ImageFetchedCallback& callback, |
| - const std::string& snippet_id, |
| + const std::string& suggestion_id, |
|
Marc Treib
2016/08/25 09:10:50
snippet_id, also below and in the .cc
sfiera
2016/08/25 12:45:13
|suggestion_id| is correct, I think. Nowhere do we
Marc Treib
2016/08/25 12:56:24
Ah, you're right. In fact, ...
|
| std::string data); |
| void OnSnippetImageDecodedFromDatabase(const ImageFetchedCallback& callback, |
| - const std::string& snippet_id, |
| + const std::string& suggestion_id, |
| const gfx::Image& image); |
| - void FetchSnippetImageFromNetwork(const std::string& snippet_id, |
| + void FetchSnippetImageFromNetwork(const std::string& suggestion_id, |
| const ImageFetchedCallback& callback); |
| void OnSnippetImageDecodedFromNetwork(const ImageFetchedCallback& callback, |
| @@ -261,7 +261,7 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
| // Verifies state transitions (see |State|'s documentation) and applies them. |
| // Also updates the provider status. Does nothing except updating the provider |
| // status if called with the current state. |
| - void EnterState(State state, CategoryStatus status); |
| + void EnterState(State state); |
| // Enables the service and triggers a fetch if required. Do not call directly, |
| // use |EnterState| instead. |
| @@ -278,24 +278,37 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
| // the observers. |
| void NotifyNewSuggestions(); |
| - // Updates the internal status |category_status_| and notifies the content |
| - // suggestions observer if it changed. |
| - void UpdateCategoryStatus(CategoryStatus status); |
| + // Updates the internal status for |category| to |category_status_| and |
| + // notifies the content suggestions observer if it changed. |
| + void UpdateCategoryStatus(Category category, CategoryStatus status); |
| + // Calls UpdateCategoryStatus() for all provided categories. |
| + void UpdateAllCategoryStatus(CategoryStatus status); |
| State state_; |
| - CategoryStatus category_status_; |
| - |
| PrefService* pref_service_; |
| suggestions::SuggestionsService* suggestions_service_; |
| - // All current suggestions (i.e. not dismissed ones). |
| - NTPSnippet::PtrVector snippets_; |
| + const Category articles_category_; |
| - // Suggestions that the user dismissed. We keep these around until they expire |
| - // so we won't re-add them on the next fetch. |
| - NTPSnippet::PtrVector dismissed_snippets_; |
| + struct CategoryContent { |
| + CategoryStatus status = CategoryStatus::INITIALIZING; |
| + |
| + // True iff the server returned results in this category in the last fetch. |
| + // We never remove categories that the server still provides, but if the |
| + // server stops providing a category, we won't yet report it as NOT_PROVIDED |
| + // while we still have non-expired snippets in it. |
| + bool provided_by_server = true; |
| + |
| + // All current suggestions (i.e. not dismissed ones). |
| + NTPSnippet::PtrVector snippets; |
| + |
| + // Suggestions that the user dismissed. We keep these around until they |
| + // expire so we won't re-add them on the next fetch. |
| + NTPSnippet::PtrVector dismissed; |
| + }; |
| + std::map<Category, CategoryContent, Category::CompareByID> categories_; |
| // The ISO 639-1 code of the language used by the application. |
| const std::string application_language_code_; |
| @@ -338,8 +351,6 @@ class NTPSnippetsService : public ContentSuggestionsProvider, |
| // loaded. The nuke will be executed after the database load finishes. |
| bool nuke_after_load_; |
| - const Category provided_category_; |
| - |
| // Request throttler for limiting requests to thumbnail images. |
| RequestThrottler thumbnail_requests_throttler_; |