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

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

Issue 2616813003: [NTP::SectionOrder] Ensure decreasing clicks when category dismissed. (Closed)
Patch Set: jkrcal@ comment. Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66c00b909a07134925ff6d6bd34d302c3b7333cb..3fe59a8415555299695ead960f04ec783909bc78 100644
--- a/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
+++ b/components/ntp_snippets/category_rankers/click_based_category_ranker.cc
@@ -198,13 +198,13 @@ void ClickBasedCategoryRanker::OnCategoryDismissed(Category category) {
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);
+ DCHECK(current != ordered_categories_.begin());
+ std::vector<RankedCategory>::iterator previous = current - 1;
+ int new_clicks = std::max(previous->clicks - kPassingMargin, 0);
+ // The previous category may have more clicks (but not enough to pass the
+ // margin, this is possible when penalty >= 2), therefore, we ensure that for
+ // this category we don't increase clicks.
+ current->clicks = std::min(current->clicks, new_clicks);
StoreOrderToPrefs(ordered_categories_);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698