Commit 3af30d62 authored by vitaliii's avatar vitaliii Committed by Commit bot

[NTP::SectionOrder] Ensure decreasing clicks when category dismissed.

Ensure that dismissing a category cannot increase its clicks and use
the previous category clicks, not the next one.

Due to PassingMargin, it is possible that lower categories have more
clicks. Before this CL, this could lead to dismissed category clicks
increase, which was not intended. Now we take mininum of new and old
clicks.
In addition to this before this CL, click count was reduced based on
the next category in the list, after this CL, on the previous one.

BUG=678586

Review-Url: https://codereview.chromium.org/2616813003
Cr-Commit-Position: refs/heads/master@{#443237}
parent be825729
......@@ -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_);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment