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

Unified Diff: components/ntp_snippets/category_rankers/constant_category_ranker.cc

Issue 2585263002: [NTP::SectionOrder] First version of click based category ranker. (Closed)
Patch Set: tschumann@ & bauerb@ comments. Created 4 years 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/category_rankers/constant_category_ranker.cc
diff --git a/components/ntp_snippets/category_rankers/constant_category_ranker.cc b/components/ntp_snippets/category_rankers/constant_category_ranker.cc
index 9fb648a7e41e470ce2c220d9aeef7a2b9f199a0d..859cf81425186b1cdbfec884d475b27d1201dcca 100644
--- a/components/ntp_snippets/category_rankers/constant_category_ranker.cc
+++ b/components/ntp_snippets/category_rankers/constant_category_ranker.cc
@@ -9,22 +9,11 @@
namespace ntp_snippets {
ConstantCategoryRanker::ConstantCategoryRanker() {
- // Add all local categories in a fixed order.
- AppendKnownCategory(KnownCategories::PHYSICAL_WEB_PAGES);
- AppendKnownCategory(KnownCategories::DOWNLOADS);
- AppendKnownCategory(KnownCategories::RECENT_TABS);
- AppendKnownCategory(KnownCategories::FOREIGN_TABS);
- AppendKnownCategory(KnownCategories::BOOKMARKS);
-
- DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT),
- ordered_categories_.size());
-
- // Known remote categories come after. Other remote categories will be ordered
- // after these depending on when providers notify us about them using
- // AppendCategoryIfNecessary.
- // TODO(treib): Consider not adding ARTICLES here, so that providers can
- // define the order themselves.
- AppendKnownCategory(KnownCategories::ARTICLES);
+ std::vector<KnownCategories> ordered_known_categories =
+ GetKnownCategoriesDefaultOrder();
+ for (KnownCategories known_category : ordered_known_categories) {
+ AppendKnownCategory(known_category);
+ }
}
ConstantCategoryRanker::~ConstantCategoryRanker() = default;
@@ -71,6 +60,31 @@ void ConstantCategoryRanker::OnSuggestionOpened(Category category) {
// Ignored. The order is constant.
}
+// static
+std::vector<KnownCategories>
+ConstantCategoryRanker::GetKnownCategoriesDefaultOrder() {
+ std::vector<KnownCategories> categories;
+
+ // Add all local categories in a fixed order.
+ categories.push_back(KnownCategories::PHYSICAL_WEB_PAGES);
+ categories.push_back(KnownCategories::DOWNLOADS);
+ categories.push_back(KnownCategories::RECENT_TABS);
+ categories.push_back(KnownCategories::FOREIGN_TABS);
+ categories.push_back(KnownCategories::BOOKMARKS);
+
+ DCHECK_EQ(static_cast<size_t>(KnownCategories::LOCAL_CATEGORIES_COUNT),
+ categories.size());
+
+ // Known remote categories come after. Other remote categories will be ordered
+ // after these depending on when providers notify us about them using
+ // AppendCategoryIfNecessary.
+ // TODO(treib): Consider not adding ARTICLES here, so that providers can
+ // define the order themselves.
+ categories.push_back(KnownCategories::ARTICLES);
+
+ return categories;
+}
+
void ConstantCategoryRanker::AppendKnownCategory(
KnownCategories known_category) {
Category category = Category::FromKnownCategory(known_category);
« no previous file with comments | « components/ntp_snippets/category_rankers/constant_category_ranker.h ('k') | components/ntp_snippets/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698