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

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 comments 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" 11 #include "base/time/time.h"
tbansal1 2016/10/25 00:47:41 Remove this include.
RyanSturm 2016/10/25 17:15:38 Done.
12 #include "components/previews/core/previews_black_list_item.h" 12 #include "components/previews/core/previews_black_list_item.h"
13 #include "components/previews/core/previews_experiments.h" 13 #include "components/previews/core/previews_experiments.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 namespace previews { 16 namespace previews {
17 17
18 namespace { 18 namespace {
19 19
20 void EvictOldestOptOut(BlackListItemMap* black_list_item_map) { 20 void EvictOldestOptOut(BlackListItemMap* black_list_item_map) {
21 // TODO(ryansturm): Add UMA. crbug.com/647717 21 // TODO(ryansturm): Add UMA. crbug.com/647717
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 } 56 }
57 57
58 PreviewsBlackList::~PreviewsBlackList() {} 58 PreviewsBlackList::~PreviewsBlackList() {}
59 59
60 void PreviewsBlackList::AddPreviewNavigation(const GURL& url, 60 void PreviewsBlackList::AddPreviewNavigation(const GURL& url,
61 bool opt_out, 61 bool opt_out,
62 PreviewsType type) { 62 PreviewsType type) {
63 DCHECK(thread_checker_.CalledOnValidThread()); 63 DCHECK(thread_checker_.CalledOnValidThread());
64 DCHECK(url.has_host()); 64 DCHECK(url.has_host());
65 if (opt_out) {
66 last_opt_out_time_ = clock_->Now();
67 }
65 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, 68 // 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 69 // synchronous operations will be accurate. Otherwise, queue the task to run
67 // asynchronously. 70 // asynchronously.
68 if (loaded_) { 71 if (loaded_) {
69 AddPreviewNavigationSync(url, opt_out, type); 72 AddPreviewNavigationSync(url, opt_out, type);
70 } else { 73 } else {
71 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync, 74 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync,
72 base::Unretained(this), url, opt_out, type)); 75 base::Unretained(this), url, opt_out, type));
73 } 76 }
74 } 77 }
75 78
76 void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url, 79 void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url,
77 bool opt_out, 80 bool opt_out,
78 PreviewsType type) { 81 PreviewsType type) {
79 DCHECK(thread_checker_.CalledOnValidThread()); 82 DCHECK(thread_checker_.CalledOnValidThread());
80 DCHECK(url.has_host()); 83 DCHECK(url.has_host());
81 DCHECK(loaded_); 84 DCHECK(loaded_);
82 std::string host_name = url.host(); 85 std::string host_name = url.host();
83 base::Time now = clock_->Now(); 86 base::Time now = clock_->Now();
84 PreviewsBlackListItem* item = 87 PreviewsBlackListItem* item =
85 GetOrCreateBlackListItem(black_list_item_map_.get(), host_name); 88 GetOrCreateBlackListItem(black_list_item_map_.get(), host_name);
86 item->AddPreviewNavigation(opt_out, now); 89 item->AddPreviewNavigation(opt_out, now);
87 DCHECK_LE(black_list_item_map_->size(), 90 DCHECK_LE(black_list_item_map_->size(),
88 params::MaxInMemoryHostsInBlackList()); 91 params::MaxInMemoryHostsInBlackList());
89 if (!opt_out_store_) 92 if (!opt_out_store_)
90 return; 93 return;
91 opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now); 94 opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now);
92 } 95 }
93 96
94 bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url, 97 bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url,
tbansal1 2016/10/25 00:47:41 At some point in future, it might be useful for th
RyanSturm 2016/10/25 17:15:38 Agreed. Seperate CL when someone wants it. We'd ne
95 PreviewsType type) const { 98 PreviewsType type) const {
96 DCHECK(thread_checker_.CalledOnValidThread()); 99 DCHECK(thread_checker_.CalledOnValidThread());
97 DCHECK(url.has_host()); 100 DCHECK(url.has_host());
98 if (!loaded_) 101 if (!loaded_)
99 return false; 102 return false;
103 if (last_opt_out_time_ &&
104 clock_->Now() <
105 last_opt_out_time_.value() + params::SingleOptOutDuration()) {
106 return false;
107 }
100 PreviewsBlackListItem* black_list_item = 108 PreviewsBlackListItem* black_list_item =
101 GetBlackListItem(*black_list_item_map_, url.host()); 109 GetBlackListItem(*black_list_item_map_, url.host());
102 return !black_list_item || !black_list_item->IsBlackListed(clock_->Now()); 110 return !black_list_item || !black_list_item->IsBlackListed(clock_->Now());
103 } 111 }
104 112
105 void PreviewsBlackList::ClearBlackList(base::Time begin_time, 113 void PreviewsBlackList::ClearBlackList(base::Time begin_time,
106 base::Time end_time) { 114 base::Time end_time) {
107 DCHECK(thread_checker_.CalledOnValidThread()); 115 DCHECK(thread_checker_.CalledOnValidThread());
108 DCHECK_LE(begin_time, end_time); 116 DCHECK_LE(begin_time, end_time);
109 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, 117 // 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()); 186 DCHECK_LT(black_list_item_map->size(), params::MaxInMemoryHostsInBlackList());
179 black_list_item = new PreviewsBlackListItem( 187 black_list_item = new PreviewsBlackListItem(
180 params::MaxStoredHistoryLengthForBlackList(), 188 params::MaxStoredHistoryLengthForBlackList(),
181 params::BlackListOptOutThreshold(), params::BlackListDuration()); 189 params::BlackListOptOutThreshold(), params::BlackListDuration());
182 black_list_item_map->operator[](host_name) = 190 black_list_item_map->operator[](host_name) =
183 base::WrapUnique(black_list_item); 191 base::WrapUnique(black_list_item);
184 return black_list_item; 192 return black_list_item;
185 } 193 }
186 194
187 } // namespace previews 195 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698