Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: components/ntp_snippets/ntp_snippets_service.h

Issue 2255783002: Support server categories in NTPSnippetsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move TODO. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
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_;
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698