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

Side by Side 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: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ntp_snippets/ntp_snippets_service.h" 5 #include "components/ntp_snippets/ntp_snippets_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 image_decoder_(std::move(image_decoder)), 214 image_decoder_(std::move(image_decoder)),
215 database_(std::move(database)), 215 database_(std::move(database)),
216 snippets_status_service_(std::move(status_service)), 216 snippets_status_service_(std::move(status_service)),
217 fetch_after_load_(false), 217 fetch_after_load_(false),
218 nuke_after_load_(false), 218 nuke_after_load_(false),
219 thumbnail_requests_throttler_( 219 thumbnail_requests_throttler_(
220 pref_service, 220 pref_service,
221 RequestThrottler::RequestType::CONTENT_SUGGESTION_THUMBNAIL) { 221 RequestThrottler::RequestType::CONTENT_SUGGESTION_THUMBNAIL) {
222 // Articles category always exists; others will be added as needed. 222 // Articles category always exists; others will be added as needed.
223 categories_[articles_category_] = CategoryContent(); 223 categories_[articles_category_] = CategoryContent();
224 categories_[articles_category_].localized_title =
225 l10n_util::GetStringUTF16(IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER);
224 observer->OnCategoryStatusChanged(this, articles_category_, 226 observer->OnCategoryStatusChanged(this, articles_category_,
225 categories_[articles_category_].status); 227 categories_[articles_category_].status);
226 if (database_->IsErrorState()) { 228 if (database_->IsErrorState()) {
227 EnterState(State::ERROR_OCCURRED); 229 EnterState(State::ERROR_OCCURRED);
228 UpdateAllCategoryStatus(CategoryStatus::LOADING_ERROR); 230 UpdateAllCategoryStatus(CategoryStatus::LOADING_ERROR);
229 return; 231 return;
230 } 232 }
231 233
232 // Can be null in tests. 234 // Can be null in tests.
233 if (history_service) 235 if (history_service)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 301 }
300 } 302 }
301 303
302 CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) { 304 CategoryStatus NTPSnippetsService::GetCategoryStatus(Category category) {
303 DCHECK(categories_.find(category) != categories_.end()); 305 DCHECK(categories_.find(category) != categories_.end());
304 return categories_[category].status; 306 return categories_[category].status;
305 } 307 }
306 308
307 CategoryInfo NTPSnippetsService::GetCategoryInfo(Category category) { 309 CategoryInfo NTPSnippetsService::GetCategoryInfo(Category category) {
308 DCHECK(categories_.find(category) != categories_.end()); 310 DCHECK(categories_.find(category) != categories_.end());
309 // TODO(sfiera): pass back titles for server categories. 311 const CategoryContent& content = categories_[category];
310 return CategoryInfo( 312 return CategoryInfo(content.localized_title,
311 l10n_util::GetStringUTF16(IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER), 313 ContentSuggestionsCardLayout::FULL_CARD,
312 ContentSuggestionsCardLayout::FULL_CARD, 314 /* has_more_button */ false,
313 /* has_more_button */ false, 315 /* show_if_empty */ true);
314 /* show_if_empty */ true);
315 } 316 }
316 317
317 void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) { 318 void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) {
318 if (!ready()) 319 if (!ready())
319 return; 320 return;
320 321
321 Category category = GetCategoryFromUniqueID(suggestion_id); 322 Category category = GetCategoryFromUniqueID(suggestion_id);
322 std::string snippet_id = GetWithinCategoryIDFromUniqueID(suggestion_id); 323 std::string snippet_id = GetWithinCategoryIDFromUniqueID(suggestion_id);
323 324
324 DCHECK(categories_.find(category) != categories_.end()); 325 DCHECK(categories_.find(category) != categories_.end());
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 return; 552 return;
552 553
553 for (auto& item : categories_) { 554 for (auto& item : categories_) {
554 CategoryContent* content = &item.second; 555 CategoryContent* content = &item.second;
555 content->provided_by_server = false; 556 content->provided_by_server = false;
556 } 557 }
557 558
558 // If snippets were fetched successfully, update our |categories_| from each 559 // If snippets were fetched successfully, update our |categories_| from each
559 // category provided by the server. 560 // category provided by the server.
560 if (snippets) { 561 if (snippets) {
561 for (std::pair<const Category, NTPSnippet::PtrVector>& item : *snippets) { 562 for (NTPSnippetsFetcher::FetchedCategory& fetched_category : *snippets) {
562 Category category = item.first; 563 Category category = fetched_category.category;
563 NTPSnippet::PtrVector& new_snippets = item.second; 564 NTPSnippet::PtrVector& new_snippets = fetched_category.snippets;
Marc Treib 2016/08/25 16:33:11 This isn't really necessary anymore, now that we'r
sfiera 2016/08/26 09:16:15 Removed it. Kept category, because it's referred t
565
566 if (category != articles_category_)
Marc Treib 2016/08/25 16:33:11 Braces if the body doesn't fit on one line
sfiera 2016/08/26 09:16:15 Done.
567 categories_[category].localized_title =
568 fetched_category.localized_title;
564 569
565 DCHECK_LE(snippets->size(), static_cast<size_t>(kMaxSnippetCount)); 570 DCHECK_LE(snippets->size(), static_cast<size_t>(kMaxSnippetCount));
566 // TODO(sfiera): histograms for server categories. 571 // TODO(sfiera): histograms for server categories.
567 // Sparse histogram used because the number of snippets is small (bound by 572 // Sparse histogram used because the number of snippets is small (bound by
568 // kMaxSnippetCount). 573 // kMaxSnippetCount).
569 if (category == articles_category_) { 574 if (category == articles_category_) {
570 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumArticlesFetched", 575 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumArticlesFetched",
571 new_snippets.size()); 576 new_snippets.size());
572 } 577 }
573 578
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 } 1067 }
1063 1068
1064 NTPSnippetsService::CategoryContent::CategoryContent() = default; 1069 NTPSnippetsService::CategoryContent::CategoryContent() = default;
1065 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) = 1070 NTPSnippetsService::CategoryContent::CategoryContent(CategoryContent&&) =
1066 default; 1071 default;
1067 NTPSnippetsService::CategoryContent::~CategoryContent() = default; 1072 NTPSnippetsService::CategoryContent::~CategoryContent() = default;
1068 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent:: 1073 NTPSnippetsService::CategoryContent& NTPSnippetsService::CategoryContent::
1069 operator=(CategoryContent&&) = default; 1074 operator=(CategoryContent&&) = default;
1070 1075
1071 } // namespace ntp_snippets 1076 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698