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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2187233002: Add ContentSuggestionsCategoryFactory; Store categories as ints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
Index: components/ntp_snippets/ntp_snippets_service.cc
diff --git a/components/ntp_snippets/ntp_snippets_service.cc b/components/ntp_snippets/ntp_snippets_service.cc
index a2cf72c8713c9943f2b19b92e1ee1fe5a8e6b008..6cd4eed5ddcde77ffe5c46bc1d044c8f54647932 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -193,8 +193,9 @@ NTPSnippetsService::NTPSnippetsService(
std::unique_ptr<ImageFetcher> image_fetcher,
std::unique_ptr<ImageDecoder> image_decoder,
std::unique_ptr<NTPSnippetsDatabase> database,
- std::unique_ptr<NTPSnippetsStatusService> status_service)
- : ContentSuggestionsProvider({ContentSuggestionsCategory::ARTICLES}),
+ std::unique_ptr<NTPSnippetsStatusService> status_service,
+ ContentSuggestionsCategoryFactory* category_factory)
+ : ContentSuggestionsProvider(category_factory),
state_(State::NOT_INITED),
category_status_(ContentSuggestionsCategoryStatus::INITIALIZING),
pref_service_(pref_service),
@@ -207,7 +208,9 @@ NTPSnippetsService::NTPSnippetsService(
image_decoder_(std::move(image_decoder)),
database_(std::move(database)),
snippets_status_service_(std::move(status_service)),
- fetch_after_load_(false) {
+ fetch_after_load_(false),
+ provided_category_(category_factory->FromKnownCategory(
+ KnownSuggestionsCategories::ARTICLES)) {
// In some cases, don't even bother loading the database.
if (!enabled) {
EnterState(State::SHUT_DOWN,
@@ -278,6 +281,11 @@ void NTPSnippetsService::RescheduleFetching() {
}
}
+std::vector<ContentSuggestionsCategory>
+NTPSnippetsService::provided_categories() {
+ return std::vector<ContentSuggestionsCategory>({provided_category_});
+}
+
void NTPSnippetsService::FetchSuggestionImage(
const std::string& suggestion_id,
const ImageFetchedCallback& callback) {
@@ -351,7 +359,7 @@ void NTPSnippetsService::SetObserver(Observer* observer) {
ContentSuggestionsCategoryStatus NTPSnippetsService::GetCategoryStatus(
ContentSuggestionsCategory category) {
- DCHECK_EQ(ContentSuggestionsCategory::ARTICLES, category);
+ DCHECK_EQ(KnownSuggestionsCategories::ARTICLES, category);
return category_status_;
}
@@ -624,8 +632,7 @@ void NTPSnippetsService::OnSnippetImageDecoded(
const ImageFetchedCallback& callback,
const gfx::Image& image) {
if (!image.IsEmpty()) {
- callback.Run(MakeUniqueID(ContentSuggestionsCategory::ARTICLES, snippet_id),
- image);
+ callback.Run(MakeUniqueID(provided_category_, snippet_id), image);
return;
}
@@ -644,8 +651,7 @@ void NTPSnippetsService::FetchSnippetImageFromNetwork(
return snippet->id() == snippet_id;
});
if (it == snippets_.end()) {
- callback.Run(MakeUniqueID(ContentSuggestionsCategory::ARTICLES, snippet_id),
- gfx::Image());
+ callback.Run(MakeUniqueID(provided_category_, snippet_id), gfx::Image());
return;
}
@@ -811,7 +817,7 @@ void NTPSnippetsService::NotifyNewSuggestions() {
if (!snippet->is_complete())
continue;
ContentSuggestion suggestion(
- MakeUniqueID(ContentSuggestionsCategory::ARTICLES, snippet->id()),
+ MakeUniqueID(provided_category_, snippet->id()),
snippet->best_source().url);
suggestion.set_amp_url(snippet->best_source().amp_url);
suggestion.set_title(snippet->title());
@@ -821,14 +827,12 @@ void NTPSnippetsService::NotifyNewSuggestions() {
suggestion.set_score(snippet->score());
result.emplace_back(std::move(suggestion));
}
- observer_->OnNewSuggestions(ContentSuggestionsCategory::ARTICLES,
- std::move(result));
+ observer_->OnNewSuggestions(provided_category_, std::move(result));
}
void NTPSnippetsService::NotifyCategoryStatusChanged() {
if (observer_) {
- observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::ARTICLES,
- category_status_);
+ observer_->OnCategoryStatusChanged(provided_category_, category_status_);
}
}

Powered by Google App Engine
This is Rietveld 408576698