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_); |
} |