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 7e76430fe23632ee0640ac717743951fb1cb2f0c..9e2f513b15986962308eb589dbb48b1fd0c7de8f 100644 |
--- a/components/ntp_snippets/ntp_snippets_service.h |
+++ b/components/ntp_snippets/ntp_snippets_service.h |
@@ -136,7 +136,7 @@ class NTPSnippetsService : public image_fetcher::ImageFetcherDelegate, |
void DismissSuggestion(const std::string& suggestion_id) override; |
void FetchSuggestionImage(const std::string& suggestion_id, |
const ImageFetchedCallback& callback) override; |
- void ClearCachedSuggestionsForDebugging(Category category) override; |
+ void ClearCachedSuggestionsForDebugging(Category category_id) override; |
Marc Treib
2016/08/22 15:06:47
?
sfiera
2016/08/24 14:35:57
Done.
|
std::vector<ContentSuggestion> GetDismissedSuggestionsForDebugging( |
Category category) override; |
void ClearDismissedSuggestionsForDebugging(Category category) override; |
@@ -148,8 +148,8 @@ class NTPSnippetsService : public image_fetcher::ImageFetcherDelegate, |
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: |
@@ -208,28 +208,28 @@ class NTPSnippetsService : public image_fetcher::ImageFetcherDelegate, |
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); |
// Removes the expired snippets (including dismissed) from the service and the |
// database, and schedules another pass for the next expiration. |
- void ClearExpiredSnippets(); |
+ void ClearExpiredSnippets(Category category); |
// Completes the initialization phase of the service, registering the last |
// observers. This is done after construction, once the database is loaded. |
void FinishInitialization(); |
void OnSnippetImageFetchedFromDatabase(const ImageFetchedCallback& callback, |
- const std::string& snippet_id, |
+ const std::string& suggestion_id, |
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, |
@@ -244,7 +244,7 @@ class NTPSnippetsService : public image_fetcher::ImageFetcherDelegate, |
// 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. |
@@ -261,24 +261,30 @@ class NTPSnippetsService : public image_fetcher::ImageFetcherDelegate, |
// 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); |
+ void UpdateAllCategoryStatus(CategoryStatus status); |
Marc Treib
2016/08/22 15:06:47
Add comment?
sfiera
2016/08/24 14:35:57
Done.
|
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; |
+ |
+ // 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_; |
@@ -312,8 +318,6 @@ class NTPSnippetsService : public image_fetcher::ImageFetcherDelegate, |
// The fetch will be executed after the database load finishes. |
bool fetch_after_load_; |
- const Category provided_category_; |
- |
// Request throttler for limiting requests to thumbnail images. |
RequestThrottler thumbnail_requests_throttler_; |