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

Side by Side Diff: components/previews/core/previews_black_list.cc

Issue 2491803002: Revert "Adding UMA to track previews opt outs and blacklist eligibility" (Closed)
Patch Set: 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/metrics/histogram_macros.h"
10 #include "base/optional.h" 9 #include "base/optional.h"
11 #include "base/time/clock.h" 10 #include "base/time/clock.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
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 66 }
68 } 67 }
69 68
70 PreviewsBlackList::~PreviewsBlackList() {} 69 PreviewsBlackList::~PreviewsBlackList() {}
71 70
72 void PreviewsBlackList::AddPreviewNavigation(const GURL& url, 71 void PreviewsBlackList::AddPreviewNavigation(const GURL& url,
73 bool opt_out, 72 bool opt_out,
74 PreviewsType type) { 73 PreviewsType type) {
75 DCHECK(thread_checker_.CalledOnValidThread()); 74 DCHECK(thread_checker_.CalledOnValidThread());
76 DCHECK(url.has_host()); 75 DCHECK(url.has_host());
77 switch (type) {
78 case PreviewsType::OFFLINE:
79 UMA_HISTOGRAM_BOOLEAN("Previews.OptOut.UserOptedOut.Offline", opt_out);
80 break;
81 default:
82 NOTREACHED();
83 }
84 if (opt_out) { 76 if (opt_out) {
85 last_opt_out_time_ = clock_->Now(); 77 last_opt_out_time_ = clock_->Now();
86 } 78 }
87 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, 79 // If the |black_list_item_map_| has been loaded from |opt_out_store_|,
88 // synchronous operations will be accurate. Otherwise, queue the task to run 80 // synchronous operations will be accurate. Otherwise, queue the task to run
89 // asynchronously. 81 // asynchronously.
90 if (loaded_) { 82 if (loaded_) {
91 AddPreviewNavigationSync(url, opt_out, type); 83 AddPreviewNavigationSync(url, opt_out, type);
92 } else { 84 } else {
93 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync, 85 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync,
(...skipping 15 matching lines...) Expand all
109 GetOrCreateBlackListItemForMap(black_list_item_map_.get(), host_name); 101 GetOrCreateBlackListItemForMap(black_list_item_map_.get(), host_name);
110 item->AddPreviewNavigation(opt_out, now); 102 item->AddPreviewNavigation(opt_out, now);
111 DCHECK_LE(black_list_item_map_->size(), 103 DCHECK_LE(black_list_item_map_->size(),
112 params::MaxInMemoryHostsInBlackList()); 104 params::MaxInMemoryHostsInBlackList());
113 host_indifferent_black_list_item_->AddPreviewNavigation(opt_out, now); 105 host_indifferent_black_list_item_->AddPreviewNavigation(opt_out, now);
114 if (!opt_out_store_) 106 if (!opt_out_store_)
115 return; 107 return;
116 opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now); 108 opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now);
117 } 109 }
118 110
119 PreviewsEligibilityReason PreviewsBlackList::IsLoadedAndAllowed( 111 bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url,
120 const GURL& url, 112 PreviewsType type) const {
121 PreviewsType type) const {
122 DCHECK(thread_checker_.CalledOnValidThread()); 113 DCHECK(thread_checker_.CalledOnValidThread());
123 DCHECK(url.has_host()); 114 DCHECK(url.has_host());
124 if (!loaded_) 115 if (!loaded_)
125 return PreviewsEligibilityReason::BLACKLIST_DATA_NOT_LOADED; 116 return false;
126 DCHECK(black_list_item_map_); 117 DCHECK(black_list_item_map_);
127 if (last_opt_out_time_ && 118 if (last_opt_out_time_ &&
128 clock_->Now() < 119 clock_->Now() <
129 last_opt_out_time_.value() + params::SingleOptOutDuration()) { 120 last_opt_out_time_.value() + params::SingleOptOutDuration()) {
130 return PreviewsEligibilityReason::USER_RECENTLY_OPTED_OUT; 121 return false;
131 } 122 }
132 if (host_indifferent_black_list_item_->IsBlackListed(clock_->Now())) 123 if (host_indifferent_black_list_item_->IsBlackListed(clock_->Now()))
133 return PreviewsEligibilityReason::USER_BLACKLISTED; 124 return false;
134 PreviewsBlackListItem* black_list_item = 125 PreviewsBlackListItem* black_list_item =
135 GetBlackListItemFromMap(*black_list_item_map_, url.host()); 126 GetBlackListItemFromMap(*black_list_item_map_, url.host());
136 if (black_list_item && black_list_item->IsBlackListed(clock_->Now())) 127 return !black_list_item || !black_list_item->IsBlackListed(clock_->Now());
137 return PreviewsEligibilityReason::HOST_BLACKLISTED;
138 return PreviewsEligibilityReason::ALLOWED;
139 } 128 }
140 129
141 void PreviewsBlackList::ClearBlackList(base::Time begin_time, 130 void PreviewsBlackList::ClearBlackList(base::Time begin_time,
142 base::Time end_time) { 131 base::Time end_time) {
143 DCHECK(thread_checker_.CalledOnValidThread()); 132 DCHECK(thread_checker_.CalledOnValidThread());
144 DCHECK_LE(begin_time, end_time); 133 DCHECK_LE(begin_time, end_time);
145 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, 134 // If the |black_list_item_map_| has been loaded from |opt_out_store_|,
146 // synchronous operations will be accurate. Otherwise, queue the task to run 135 // synchronous operations will be accurate. Otherwise, queue the task to run
147 // asynchronously. 136 // asynchronously.
148 if (loaded_) { 137 if (loaded_) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // static 210 // static
222 std::unique_ptr<PreviewsBlackListItem> 211 std::unique_ptr<PreviewsBlackListItem>
223 PreviewsBlackList::CreateHostIndifferentBlackListItem() { 212 PreviewsBlackList::CreateHostIndifferentBlackListItem() {
224 return base::MakeUnique<PreviewsBlackListItem>( 213 return base::MakeUnique<PreviewsBlackListItem>(
225 params::MaxStoredHistoryLengthForHostIndifferentBlackList(), 214 params::MaxStoredHistoryLengthForHostIndifferentBlackList(),
226 params::HostIndifferentBlackListOptOutThreshold(), 215 params::HostIndifferentBlackListOptOutThreshold(),
227 params::HostIndifferentBlackListPerHostDuration()); 216 params::HostIndifferentBlackListPerHostDuration());
228 } 217 }
229 218
230 } // namespace previews 219 } // 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