Chromium Code Reviews| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "components/previews/core/previews_black_list_item.h" | 12 #include "components/previews/core/previews_black_list_item.h" |
| 13 #include "components/previews/core/previews_experiments.h" | 13 #include "components/previews/core/previews_experiments.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace previews { | 16 namespace previews { |
| 17 | 17 |
| 18 PreviewsBlackList::PreviewsBlackList( | 18 PreviewsBlackList::PreviewsBlackList( |
| 19 std::unique_ptr<PreviewsOptOutStore> opt_out_store, | 19 std::unique_ptr<PreviewsOptOutStore> opt_out_store, |
| 20 std::unique_ptr<base::Clock> clock) | 20 std::unique_ptr<base::Clock> clock) |
| 21 : loaded_(false), | 21 : loaded_(false), |
| 22 opt_out_store_(std::move(opt_out_store)), | 22 opt_out_store_(std::move(opt_out_store)), |
| 23 clock_(std::move(clock)), | 23 clock_(std::move(clock)), |
| 24 weak_factory_(this) { | 24 weak_factory_(this) {} |
| 25 | |
| 26 PreviewsBlackList::~PreviewsBlackList() {} | |
| 27 | |
| 28 void PreviewsBlackList::Initialize() { | |
|
tbansal1
2016/10/04 15:01:21
Add thread checker.
RyanSturm
2016/10/04 19:10:23
I'm undoing this. It doesn't actually help anythin
| |
| 25 if (opt_out_store_) { | 29 if (opt_out_store_) { |
| 26 opt_out_store_->LoadBlackList(base::Bind( | 30 opt_out_store_->LoadBlackList(base::Bind( |
| 27 &PreviewsBlackList::LoadBlackListDone, weak_factory_.GetWeakPtr())); | 31 &PreviewsBlackList::LoadBlackListDone, weak_factory_.GetWeakPtr())); |
| 28 } else { | 32 } else { |
| 29 LoadBlackListDone(base::MakeUnique<BlackListItemMap>()); | 33 LoadBlackListDone(base::MakeUnique<BlackListItemMap>()); |
| 30 } | 34 } |
| 31 } | 35 } |
| 32 | 36 |
| 33 PreviewsBlackList::~PreviewsBlackList() {} | |
| 34 | |
| 35 void PreviewsBlackList::AddPreviewNavigation(const GURL& url, | 37 void PreviewsBlackList::AddPreviewNavigation(const GURL& url, |
| 36 bool opt_out, | 38 bool opt_out, |
| 37 PreviewsType type) { | 39 PreviewsType type) { |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); | 40 DCHECK(thread_checker_.CalledOnValidThread()); |
| 39 DCHECK(url.has_host()); | 41 DCHECK(url.has_host()); |
| 40 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, | 42 // If the |black_list_item_map_| has been loaded from |opt_out_store_|, |
| 41 // synchronous operations will be accurate. Otherwise, queue the task to run | 43 // synchronous operations will be accurate. Otherwise, queue the task to run |
| 42 // asynchronously. | 44 // asynchronously. |
| 43 if (loaded_) { | 45 if (loaded_) { |
| 44 AddPreviewNavigationSync(url, opt_out, type); | 46 AddPreviewNavigationSync(url, opt_out, type); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 } | 143 } |
| 142 if (iter->second->most_recent_opt_out_time().value() < oldest_opt_out) { | 144 if (iter->second->most_recent_opt_out_time().value() < oldest_opt_out) { |
| 143 oldest_opt_out = iter->second->most_recent_opt_out_time().value(); | 145 oldest_opt_out = iter->second->most_recent_opt_out_time().value(); |
| 144 item_to_delete = iter; | 146 item_to_delete = iter; |
| 145 } | 147 } |
| 146 } | 148 } |
| 147 black_list_item_map_->erase(item_to_delete); | 149 black_list_item_map_->erase(item_to_delete); |
| 148 } | 150 } |
| 149 | 151 |
| 150 } // namespace previews | 152 } // namespace previews |
| OLD | NEW |