Chromium Code Reviews| Index: components/previews/core/previews_black_list_item.cc | 
| diff --git a/components/previews/core/previews_black_list_item.cc b/components/previews/core/previews_black_list_item.cc | 
| index 9fd3286772ca7497406a48351b8cb89bc7fae591..8029ce941e30504d62045afb4e28fb5641821e5a 100644 | 
| --- a/components/previews/core/previews_black_list_item.cc | 
| +++ b/components/previews/core/previews_black_list_item.cc | 
| @@ -5,54 +5,64 @@ | 
| #include "components/previews/core/previews_black_list_item.h" | 
| #include <algorithm> | 
| #include "components/previews/core/previews_opt_out_store.h" | 
| namespace previews { | 
| PreviewsBlackListItem::OptOutRecord::OptOutRecord(base::Time entry_time, | 
| bool opt_out) | 
| - : entry_time(entry_time), opt_out(opt_out) {} | 
| + : entry_time_(entry_time), opt_out_(opt_out) {} | 
| + | 
| +PreviewsBlackListItem::OptOutRecord::~OptOutRecord() {} | 
| + | 
| +PreviewsBlackListItem::OptOutRecord::OptOutRecord(OptOutRecord&&) = default; | 
| + | 
| +PreviewsBlackListItem::OptOutRecord& PreviewsBlackListItem::OptOutRecord:: | 
| +operator=(OptOutRecord&&) = default; | 
| + | 
| +bool PreviewsBlackListItem::OptOutRecord::operator<( | 
| + const OptOutRecord& other) const { | 
| + // Fresher entries are lower priority to evict, as are non-opt-outs. | 
| + return (entry_time_ == other.entry_time_) ? opt_out_ > other.opt_out_ | 
| 
 
tbansal1
2016/10/25 16:15:47
Why not use std::tie?
That's slightly more readabl
 
RyanSturm
2016/10/25 18:15:44
couldn't remember what tie was called. Thanks.
 
 | 
| + : entry_time_ > other.entry_time_; | 
| +} | 
| PreviewsBlackListItem::PreviewsBlackListItem( | 
| size_t stored_history_length, | 
| int opt_out_black_list_threshold, | 
| base::TimeDelta black_list_duration) | 
| : max_stored_history_length_(stored_history_length), | 
| opt_out_black_list_threshold_(opt_out_black_list_threshold), | 
| max_black_list_duration_(black_list_duration), | 
| total_opt_out_(0) {} | 
| PreviewsBlackListItem::~PreviewsBlackListItem() {} | 
| void PreviewsBlackListItem::AddPreviewNavigation(bool opt_out, | 
| base::Time entry_time) { | 
| DCHECK_LE(opt_out_records_.size(), max_stored_history_length_); | 
| + | 
| + opt_out_records_.emplace(entry_time, opt_out); | 
| + | 
| if (opt_out && (!most_recent_opt_out_time_ || | 
| entry_time > most_recent_opt_out_time_.value())) { | 
| most_recent_opt_out_time_ = entry_time; | 
| } | 
| total_opt_out_ += opt_out ? 1 : 0; | 
| - // Find insert postion to keep the list sorted. Typically, this will be at the | 
| - // end of the list, but for systems with clocks that are not non-decreasing | 
| - // with time, this may not be the end. Linearly search from end to begin. | 
| - auto iter = opt_out_records_.rbegin(); | 
| - while (iter != opt_out_records_.rend() && iter->entry_time > entry_time) | 
| - iter++; | 
| - opt_out_records_.emplace(iter.base(), entry_time, opt_out); | 
| - | 
| - // Remove the oldest entry if the size exceeds the history size. | 
| + // Remove the oldest entry if the size exceeds the max history size. | 
| if (opt_out_records_.size() > max_stored_history_length_) { | 
| - total_opt_out_ -= opt_out_records_.front().opt_out ? 1 : 0; | 
| - opt_out_records_.pop_front(); | 
| + DCHECK(opt_out_records_.top().entry_time() <= entry_time); | 
| 
 
tbansal1
2016/10/25 16:15:47
DCHECK_LE
 
tbansal1
2016/10/25 16:15:47
Add DCHECK_EQ(opt_out_records_.size(), max_stored_
 
RyanSturm
2016/10/25 18:15:44
Done.
 
RyanSturm
2016/10/25 18:15:44
Done.
 
 | 
| + total_opt_out_ -= opt_out_records_.top().opt_out() ? 1 : 0; | 
| + opt_out_records_.pop(); | 
| } | 
| DCHECK_LE(opt_out_records_.size(), max_stored_history_length_); | 
| } | 
| bool PreviewsBlackListItem::IsBlackListed(base::Time now) const { | 
| DCHECK_LE(opt_out_records_.size(), max_stored_history_length_); | 
| return most_recent_opt_out_time_ && | 
| now - most_recent_opt_out_time_.value() < max_black_list_duration_ && | 
| total_opt_out_ >= opt_out_black_list_threshold_; | 
| } |