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

Unified Diff: components/previews/core/previews_black_list.cc

Issue 2439203002: Adding a short blacklist period after every previews opt out (Closed)
Patch Set: tbansal commetns Created 4 years, 2 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
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_|,
« no previous file with comments | « components/previews/core/previews_black_list.h ('k') | components/previews/core/previews_black_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698