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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2276383002: Support server-provided category names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Move "ignored" comment. 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
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 1f0909290671e5b99efe52cb9d8630e2a48f1b50..c401f632e4fcef08e046fcf91e59279cf0ea94d4 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -221,6 +221,8 @@ NTPSnippetsService::NTPSnippetsService(
RequestThrottler::RequestType::CONTENT_SUGGESTION_THUMBNAIL) {
// Articles category always exists; others will be added as needed.
categories_[articles_category_] = CategoryContent();
+ categories_[articles_category_].localized_title =
+ l10n_util::GetStringUTF16(IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER);
observer->OnCategoryStatusChanged(this, articles_category_,
categories_[articles_category_].status);
if (database_->IsErrorState()) {
@@ -306,12 +308,11 @@ CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) {
CategoryInfo NTPSnippetsService::GetCategoryInfo(Category category) {
DCHECK(categories_.find(category) != categories_.end());
- // TODO(sfiera): pass back titles for server categories.
- return CategoryInfo(
- l10n_util::GetStringUTF16(IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER),
- ContentSuggestionsCardLayout::FULL_CARD,
- /* has_more_button */ false,
- /* show_if_empty */ true);
+ const CategoryContent& content = categories_[category];
+ return CategoryInfo(content.localized_title,
+ ContentSuggestionsCardLayout::FULL_CARD,
+ /* has_more_button */ false,
+ /* show_if_empty */ true);
}
void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) {
@@ -558,9 +559,13 @@ void NTPSnippetsService::OnFetchFinished(
// If snippets were fetched successfully, update our |categories_| from each
// category provided by the server.
if (snippets) {
- for (std::pair<const Category, NTPSnippet::PtrVector>& item : *snippets) {
- Category category = item.first;
- NTPSnippet::PtrVector& new_snippets = item.second;
+ for (NTPSnippetsFetcher::FetchedCategory& fetched_category : *snippets) {
+ Category category = fetched_category.category;
+
+ if (category != articles_category_) {
tschumann 2016/08/29 09:59:53 note: special casing the articles category like th
Michael van Ouwerkerk 2016/09/08 13:03:27 The form of "category != articles_category_" is us
+ categories_[category].localized_title =
+ fetched_category.localized_title;
+ }
DCHECK_LE(snippets->size(), static_cast<size_t>(kMaxSnippetCount));
// TODO(sfiera): histograms for server categories.
@@ -568,10 +573,10 @@ void NTPSnippetsService::OnFetchFinished(
// kMaxSnippetCount).
if (category == articles_category_) {
UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumArticlesFetched",
- new_snippets.size());
+ fetched_category.snippets.size());
}
- MergeSnippets(category, std::move(new_snippets));
+ MergeSnippets(category, std::move(fetched_category.snippets));
// If there are more snippets than we want to show, delete the extra ones.
CategoryContent* content = &categories_[category];

Powered by Google App Engine
This is Rietveld 408576698