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

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

Issue 2610553002: [NTP::SectionOrder] Make ClickBasedRanker move dismissed sections down. (Closed)
Patch Set: jkrcal@ comment. Created 3 years, 12 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/category_rankers/click_based_category_ranker.cc
diff --git a/components/ntp_snippets/category_rankers/click_based_category_ranker.cc b/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
index 45da64bd5bdf2a0c55db471f604eec4f1cef2e4f..6dbab54b52c0a22bec4dbac162f6ac58da67f956 100644
--- a/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
+++ b/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
@@ -38,6 +38,9 @@ const int kNumTopCategoriesWithExtraMargin = 3;
// value than the first non-top category).
const int kExtraPassingMargin = 2;
+// Number of positions by which a dismissed category is downgraded.
+const int kDismissedCategoryPenalty = 1;
+
const char kCategoryIdKey[] = "category";
const char kClicksKey[] = "clicks";
@@ -94,7 +97,6 @@ void ClickBasedCategoryRanker::AppendCategoryIfNecessary(Category category) {
}
}
-// TODO(vitaliii): Listen to dismissed sections and penalise them.
void ClickBasedCategoryRanker::OnSuggestionOpened(Category category) {
if (!ContainsCategory(category)) {
LOG(DFATAL) << "The category with ID " << category.id()
@@ -119,6 +121,33 @@ void ClickBasedCategoryRanker::OnSuggestionOpened(Category category) {
StoreOrderToPrefs(ordered_categories_);
}
+void ClickBasedCategoryRanker::OnCategoryDismissed(Category category) {
+ if (!ContainsCategory(category)) {
+ LOG(DFATAL) << "The category with ID " << category.id()
+ << " has not been added using AppendCategoryIfNecessary.";
+ return;
+ }
+
+ std::vector<RankedCategory>::iterator current = FindCategory(category);
+ for (int downgrade = 0; downgrade < kDismissedCategoryPenalty; ++downgrade) {
+ std::vector<RankedCategory>::iterator next = current + 1;
+ if (next == ordered_categories_.end()) {
+ break;
+ }
+ std::swap(*current, *next);
+ current = next;
+ }
+
+ int next_clicks = 0;
+ std::vector<RankedCategory>::iterator next = current + 1;
+ if (next != ordered_categories_.end()) {
+ next_clicks = next->clicks;
+ }
+
+ current->clicks = std::max(next_clicks - kPassingMargin, 0);
+ StoreOrderToPrefs(ordered_categories_);
+}
+
// static
void ClickBasedCategoryRanker::RegisterProfilePrefs(
PrefRegistrySimple* registry) {
@@ -135,6 +164,11 @@ int ClickBasedCategoryRanker::GetNumTopCategoriesWithExtraMargin() {
return kNumTopCategoriesWithExtraMargin;
}
+// static
+int ClickBasedCategoryRanker::GetDismissedCategoryPenalty() {
+ return kDismissedCategoryPenalty;
+}
+
ClickBasedCategoryRanker::RankedCategory::RankedCategory(Category category,
int clicks)
: category(category), clicks(clicks) {}

Powered by Google App Engine
This is Rietveld 408576698