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

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

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

Powered by Google App Engine
This is Rietveld 408576698