| 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/optional.h" | 9 #include "base/optional.h" |
| 10 #include "base/time/clock.h" | 10 #include "base/time/clock.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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, |
| 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::SingleOptOutBlackOutDuration()) { |
| 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 Loading... |
| 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 |
| OLD | NEW |