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 fa5d1262f1eaa03ba1770685997668769fceecc2..4140fcd6a4db7bcabc2d0240bcf7618203adadef 100644 |
--- a/components/previews/core/previews_black_list.cc |
+++ b/components/previews/core/previews_black_list.cc |
@@ -1,18 +1,19 @@ |
// 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/metrics/histogram.h" |
#include "base/optional.h" |
#include "base/time/clock.h" |
#include "components/previews/core/previews_black_list_item.h" |
#include "components/previews/core/previews_experiments.h" |
#include "url/gurl.h" |
namespace previews { |
namespace { |
@@ -66,20 +67,27 @@ PreviewsBlackList::PreviewsBlackList( |
} |
} |
PreviewsBlackList::~PreviewsBlackList() {} |
void PreviewsBlackList::AddPreviewNavigation(const GURL& url, |
bool opt_out, |
PreviewsType type) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(url.has_host()); |
+ switch (type) { |
+ case PreviewsType::OFFLINE: |
+ UMA_HISTOGRAM_BOOLEAN("Previews.OptOut.UserOptedOut.Offline", opt_out); |
tbansal1
2016/11/08 00:30:52
May be Previews.Offline.*.* so that all Offline hi
RyanSturm
2016/11/08 22:22:29
I was thinking of having a suffix for all of them
|
+ break; |
+ default: |
+ NOTREACHED(); |
+ } |
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, |
@@ -101,37 +109,40 @@ void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url, |
GetOrCreateBlackListItemForMap(black_list_item_map_.get(), host_name); |
item->AddPreviewNavigation(opt_out, now); |
DCHECK_LE(black_list_item_map_->size(), |
params::MaxInMemoryHostsInBlackList()); |
host_indifferent_black_list_item_->AddPreviewNavigation(opt_out, now); |
if (!opt_out_store_) |
return; |
opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now); |
} |
-bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url, |
- PreviewsType type) const { |
+PreviewsEligibilityReason PreviewsBlackList::IsLoadedAndAllowed( |
+ const GURL& url, |
+ PreviewsType type) const { |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(url.has_host()); |
if (!loaded_) |
- return false; |
+ return PreviewsEligibilityReason::BLACKLIST_DATA_NOT_LOADED; |
DCHECK(black_list_item_map_); |
if (last_opt_out_time_ && |
clock_->Now() < |
last_opt_out_time_.value() + params::SingleOptOutDuration()) { |
- return false; |
+ return PreviewsEligibilityReason::USER_RECENTLY_OPTED_OUT; |
} |
if (host_indifferent_black_list_item_->IsBlackListed(clock_->Now())) |
- return false; |
+ return PreviewsEligibilityReason::USER_BLACKLISTED; |
PreviewsBlackListItem* black_list_item = |
GetBlackListItemFromMap(*black_list_item_map_, url.host()); |
- return !black_list_item || !black_list_item->IsBlackListed(clock_->Now()); |
+ if (black_list_item && black_list_item->IsBlackListed(clock_->Now())) |
+ return PreviewsEligibilityReason::HOST_BLACKLISTED; |
+ return PreviewsEligibilityReason::ALLOWED; |
} |
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_|, |
// synchronous operations will be accurate. Otherwise, queue the task to run |
// asynchronously. |
if (loaded_) { |