Chromium Code Reviews| 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 f4b277b6f231ee0f0e6b4dca36c274bd30b29f94..fd1afed3b0ad23b33e14584d4e4fb0188546e89e 100644 |
| --- a/components/previews/core/previews_black_list.cc |
| +++ b/components/previews/core/previews_black_list.cc |
| @@ -71,20 +71,53 @@ void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url, |
| bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url, |
| PreviewsType type) const { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(url.has_host()); |
| if (!loaded_) |
| return false; |
| PreviewsBlackListItem* black_list_item = GetBlackListItem(url.host()); |
| return !black_list_item || !black_list_item->IsBlackListed(clock_->Now()); |
| } |
| +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_) { |
| + ClearBlackListSync(begin_time, end_time); |
| + } else { |
| + QueuePendingTask(base::Bind(&PreviewsBlackList::ClearBlackListSync, |
| + weak_factory_.GetWeakPtr(), begin_time, |
| + end_time)); |
| + } |
| +} |
| + |
| +void PreviewsBlackList::ClearBlackListSync(base::Time begin_time, |
| + base::Time end_time) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + DCHECK(loaded_); |
| + DCHECK_LE(begin_time, end_time); |
| + black_list_item_map_.reset(nullptr); |
| + loaded_ = false; |
| + // Delete relevant entries and reload the blacklist into memory. |
| + if (opt_out_store_) { |
| + opt_out_store_->ClearBlackList(begin_time, end_time); |
|
tbansal1
2016/10/04 00:16:59
So, this means that opt out store must execute Cle
tbansal1
2016/10/04 01:31:46
Discard this comment.
|
| + opt_out_store_->LoadBlackList(base::Bind( |
| + &PreviewsBlackList::LoadBlackListDone, weak_factory_.GetWeakPtr())); |
| + } else { |
| + LoadBlackListDone(base::MakeUnique<BlackListItemMap>()); |
| + } |
| +} |
| + |
| void PreviewsBlackList::QueuePendingTask(base::Closure callback) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(!loaded_); |
| DCHECK(!callback.is_null()); |
| pending_callbacks_.emplace(callback); |
| } |
| void PreviewsBlackList::LoadBlackListDone( |
| std::unique_ptr<BlackListItemMap> black_list_item_map) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |