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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/previews/core/previews_black_list.h" 5 #include "components/previews/core/previews_black_list.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/optional.h" 9 #include "base/optional.h"
10 #include "base/time/clock.h" 10 #include "base/time/clock.h"
11 #include "base/time/time.h"
12 #include "components/previews/core/previews_black_list_item.h" 11 #include "components/previews/core/previews_black_list_item.h"
13 #include "components/previews/core/previews_experiments.h" 12 #include "components/previews/core/previews_experiments.h"
14 #include "url/gurl.h" 13 #include "url/gurl.h"
15 14
16 namespace previews { 15 namespace previews {
17 16
18 namespace { 17 namespace {
19 18
20 void EvictOldestOptOut(BlackListItemMap* black_list_item_map) { 19 void EvictOldestOptOut(BlackListItemMap* black_list_item_map) {
21 // TODO(ryansturm): Add UMA. crbug.com/647717 20 // TODO(ryansturm): Add UMA. crbug.com/647717
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 54 }
56 } 55 }
57 56
58 PreviewsBlackList::~PreviewsBlackList() {} 57 PreviewsBlackList::~PreviewsBlackList() {}
59 58
60 void PreviewsBlackList::AddPreviewNavigation(const GURL& url, 59 void PreviewsBlackList::AddPreviewNavigation(const GURL& url,
61 bool opt_out, 60 bool opt_out,
62 PreviewsType type) { 61 PreviewsType type) {
63 DCHECK(thread_checker_.CalledOnValidThread()); 62 DCHECK(thread_checker_.CalledOnValidThread());
64 DCHECK(url.has_host()); 63 DCHECK(url.has_host());
64 if (opt_out) {
65 last_opt_out_time_ = clock_->Now();
66 }
65 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, 67 // If the |black_list_item_map_| has been loaded from |opt_out_store_|,
66 // synchronous operations will be accurate. Otherwise, queue the task to run 68 // synchronous operations will be accurate. Otherwise, queue the task to run
67 // asynchronously. 69 // asynchronously.
68 if (loaded_) { 70 if (loaded_) {
69 AddPreviewNavigationSync(url, opt_out, type); 71 AddPreviewNavigationSync(url, opt_out, type);
70 } else { 72 } else {
71 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync, 73 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync,
72 base::Unretained(this), url, opt_out, type)); 74 base::Unretained(this), url, opt_out, type));
73 } 75 }
74 } 76 }
(...skipping 15 matching lines...) Expand all
90 return; 92 return;
91 opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now); 93 opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now);
92 } 94 }
93 95
94 bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url, 96 bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url,
95 PreviewsType type) const { 97 PreviewsType type) const {
96 DCHECK(thread_checker_.CalledOnValidThread()); 98 DCHECK(thread_checker_.CalledOnValidThread());
97 DCHECK(url.has_host()); 99 DCHECK(url.has_host());
98 if (!loaded_) 100 if (!loaded_)
99 return false; 101 return false;
102 if (last_opt_out_time_ &&
103 clock_->Now() <
104 last_opt_out_time_.value() + params::SingleOptOutDuration()) {
105 return false;
106 }
100 PreviewsBlackListItem* black_list_item = 107 PreviewsBlackListItem* black_list_item =
101 GetBlackListItem(*black_list_item_map_, url.host()); 108 GetBlackListItem(*black_list_item_map_, url.host());
102 return !black_list_item || !black_list_item->IsBlackListed(clock_->Now()); 109 return !black_list_item || !black_list_item->IsBlackListed(clock_->Now());
103 } 110 }
104 111
105 void PreviewsBlackList::ClearBlackList(base::Time begin_time, 112 void PreviewsBlackList::ClearBlackList(base::Time begin_time,
106 base::Time end_time) { 113 base::Time end_time) {
107 DCHECK(thread_checker_.CalledOnValidThread()); 114 DCHECK(thread_checker_.CalledOnValidThread());
108 DCHECK_LE(begin_time, end_time); 115 DCHECK_LE(begin_time, end_time);
109 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, 116 // If the |black_list_item_map_| has been loaded from |opt_out_store_|,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 DCHECK_LT(black_list_item_map->size(), params::MaxInMemoryHostsInBlackList()); 185 DCHECK_LT(black_list_item_map->size(), params::MaxInMemoryHostsInBlackList());
179 black_list_item = new PreviewsBlackListItem( 186 black_list_item = new PreviewsBlackListItem(
180 params::MaxStoredHistoryLengthForBlackList(), 187 params::MaxStoredHistoryLengthForBlackList(),
181 params::BlackListOptOutThreshold(), params::BlackListDuration()); 188 params::BlackListOptOutThreshold(), params::BlackListDuration());
182 black_list_item_map->operator[](host_name) = 189 black_list_item_map->operator[](host_name) =
183 base::WrapUnique(black_list_item); 190 base::WrapUnique(black_list_item);
184 return black_list_item; 191 return black_list_item;
185 } 192 }
186 193
187 } // namespace previews 194 } // namespace previews
OLDNEW
« 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