| OLD | NEW |
| 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" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/optional.h" | 10 #include "base/optional.h" |
| 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/time/clock.h" | 12 #include "base/time/clock.h" |
| 12 #include "components/previews/core/previews_black_list_item.h" | 13 #include "components/previews/core/previews_black_list_item.h" |
| 13 #include "components/previews/core/previews_experiments.h" | 14 #include "components/previews/core/previews_experiments.h" |
| 14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 15 | 16 |
| 16 namespace previews { | 17 namespace previews { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 void EvictOldestOptOut(BlackListItemMap* black_list_item_map) { | 21 void EvictOldestOptOut(BlackListItemMap* black_list_item_map) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 PreviewsBlackList::~PreviewsBlackList() {} | 71 PreviewsBlackList::~PreviewsBlackList() {} |
| 71 | 72 |
| 72 void PreviewsBlackList::AddPreviewNavigation(const GURL& url, | 73 void PreviewsBlackList::AddPreviewNavigation(const GURL& url, |
| 73 bool opt_out, | 74 bool opt_out, |
| 74 PreviewsType type) { | 75 PreviewsType type) { |
| 75 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 76 DCHECK(url.has_host()); | 77 DCHECK(url.has_host()); |
| 77 switch (type) { | 78 |
| 78 case PreviewsType::OFFLINE: | 79 base::BooleanHistogram::FactoryGet( |
| 79 UMA_HISTOGRAM_BOOLEAN("Previews.OptOut.UserOptedOut.Offline", opt_out); | 80 base::StringPrintf("Previews.OptOut.UserOptedOut.%s", |
| 80 break; | 81 GetStringNameForType(type).c_str()), |
| 81 default: | 82 base::HistogramBase::kUmaTargetedHistogramFlag) |
| 82 NOTREACHED(); | 83 ->Add(opt_out); |
| 83 } | |
| 84 if (opt_out) { | 84 if (opt_out) { |
| 85 last_opt_out_time_ = clock_->Now(); | 85 last_opt_out_time_ = clock_->Now(); |
| 86 } | 86 } |
| 87 // 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_|, |
| 88 // synchronous operations will be accurate. Otherwise, queue the task to run | 88 // synchronous operations will be accurate. Otherwise, queue the task to run |
| 89 // asynchronously. | 89 // asynchronously. |
| 90 if (loaded_) { | 90 if (loaded_) { |
| 91 AddPreviewNavigationSync(url, opt_out, type); | 91 AddPreviewNavigationSync(url, opt_out, type); |
| 92 } else { | 92 } else { |
| 93 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync, | 93 QueuePendingTask(base::Bind(&PreviewsBlackList::AddPreviewNavigationSync, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // static | 221 // static |
| 222 std::unique_ptr<PreviewsBlackListItem> | 222 std::unique_ptr<PreviewsBlackListItem> |
| 223 PreviewsBlackList::CreateHostIndifferentBlackListItem() { | 223 PreviewsBlackList::CreateHostIndifferentBlackListItem() { |
| 224 return base::MakeUnique<PreviewsBlackListItem>( | 224 return base::MakeUnique<PreviewsBlackListItem>( |
| 225 params::MaxStoredHistoryLengthForHostIndifferentBlackList(), | 225 params::MaxStoredHistoryLengthForHostIndifferentBlackList(), |
| 226 params::HostIndifferentBlackListOptOutThreshold(), | 226 params::HostIndifferentBlackListOptOutThreshold(), |
| 227 params::HostIndifferentBlackListPerHostDuration()); | 227 params::HostIndifferentBlackListPerHostDuration()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace previews | 230 } // namespace previews |
| OLD | NEW |