| Index: components/previews/core/previews_black_list.cc
|
| diff --git a/components/previews/core/previews_black_list.cc b/components/previews/core/previews_black_list.cc
|
| index 896507deee1e3391ed33a620df2b9e2777e7eba6..08b9fa2910c4abbb05b4232100bd2bb6038144e1 100644
|
| --- a/components/previews/core/previews_black_list.cc
|
| +++ b/components/previews/core/previews_black_list.cc
|
| @@ -1,21 +1,20 @@
|
| // Copyright 2016 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| #include "components/previews/core/previews_black_list.h"
|
|
|
| #include "base/bind.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/optional.h"
|
| #include "base/time/clock.h"
|
| -#include "base/time/time.h"
|
| #include "components/previews/core/previews_black_list_item.h"
|
| #include "components/previews/core/previews_experiments.h"
|
| #include "url/gurl.h"
|
|
|
| namespace previews {
|
|
|
| namespace {
|
|
|
| void EvictOldestOptOut(BlackListItemMap* black_list_item_map) {
|
| // TODO(ryansturm): Add UMA. crbug.com/647717
|
| @@ -55,20 +54,23 @@ PreviewsBlackList::PreviewsBlackList(
|
| }
|
| }
|
|
|
| PreviewsBlackList::~PreviewsBlackList() {}
|
|
|
| void PreviewsBlackList::AddPreviewNavigation(const GURL& url,
|
| bool opt_out,
|
| PreviewsType type) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(url.has_host());
|
| + if (opt_out) {
|
| + last_opt_out_time_ = clock_->Now();
|
| + }
|
| // If the |black_list_item_map_| has been loaded from |opt_out_store_|,
|
| // synchronous operations will be accurate. Otherwise, queue the task to run
|
| // asynchronously.
|
| if (loaded_) {
|
| AddPreviewNavigationSync(url, opt_out, type);
|
| } else {
|
| QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync,
|
| base::Unretained(this), url, opt_out, type));
|
| }
|
| }
|
| @@ -90,20 +92,25 @@ void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url,
|
| return;
|
| opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now);
|
| }
|
|
|
| bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url,
|
| PreviewsType type) const {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(url.has_host());
|
| if (!loaded_)
|
| return false;
|
| + if (last_opt_out_time_ &&
|
| + clock_->Now() <
|
| + last_opt_out_time_.value() + params::SingleOptOutDuration()) {
|
| + return false;
|
| + }
|
| PreviewsBlackListItem* black_list_item =
|
| GetBlackListItem(*black_list_item_map_, url.host());
|
| return !black_list_item || !black_list_item->IsBlackListed(clock_->Now());
|
| }
|
|
|
| void PreviewsBlackList::ClearBlackList(base::Time begin_time,
|
| base::Time end_time) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK_LE(begin_time, end_time);
|
| // If the |black_list_item_map_| has been loaded from |opt_out_store_|,
|
|
|