Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: components/previews/core/previews_black_list.cc

Issue 2387823002: Adding ClearBlackList to the PreviewsBlackList and plumbing to UI (Closed)
Patch Set: tbansal comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url, 71 bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url,
72 PreviewsType type) const { 72 PreviewsType type) const {
73 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
74 DCHECK(url.has_host()); 74 DCHECK(url.has_host());
75 if (!loaded_) 75 if (!loaded_)
76 return false; 76 return false;
77 PreviewsBlackListItem* black_list_item = GetBlackListItem(url.host()); 77 PreviewsBlackListItem* black_list_item = GetBlackListItem(url.host());
78 return !black_list_item || !black_list_item->IsBlackListed(clock_->Now()); 78 return !black_list_item || !black_list_item->IsBlackListed(clock_->Now());
79 } 79 }
80 80
81 void PreviewsBlackList::ClearBlackList(base::Time begin_time,
82 base::Time end_time) {
83 DCHECK(thread_checker_.CalledOnValidThread());
84 DCHECK_LE(begin_time, end_time);
85 // If the |black_list_item_map_| has been loaded from |opt_out_store_|,
86 // synchronous operations will be accurate. Otherwise, queue the task to run
87 // asynchronously.
88 if (loaded_) {
89 ClearBlackListSync(begin_time, end_time);
90 } else {
91 QueuePendingTask(base::Bind(&PreviewsBlackList::ClearBlackListSync,
92 weak_factory_.GetWeakPtr(), begin_time,
93 end_time));
94 }
95 }
96
97 void PreviewsBlackList::ClearBlackListSync(base::Time begin_time,
98 base::Time end_time) {
99 DCHECK(thread_checker_.CalledOnValidThread());
100 DCHECK(loaded_);
101 DCHECK_LE(begin_time, end_time);
102 black_list_item_map_.reset(nullptr);
103 loaded_ = false;
104 // Delete relevant entries and reload the blacklist into memory.
105 if (opt_out_store_) {
106 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.
107 opt_out_store_->LoadBlackList(base::Bind(
108 &PreviewsBlackList::LoadBlackListDone, weak_factory_.GetWeakPtr()));
109 } else {
110 LoadBlackListDone(base::MakeUnique<BlackListItemMap>());
111 }
112 }
113
81 void PreviewsBlackList::QueuePendingTask(base::Closure callback) { 114 void PreviewsBlackList::QueuePendingTask(base::Closure callback) {
82 DCHECK(thread_checker_.CalledOnValidThread()); 115 DCHECK(thread_checker_.CalledOnValidThread());
83 DCHECK(!loaded_); 116 DCHECK(!loaded_);
84 DCHECK(!callback.is_null()); 117 DCHECK(!callback.is_null());
85 pending_callbacks_.emplace(callback); 118 pending_callbacks_.emplace(callback);
86 } 119 }
87 120
88 void PreviewsBlackList::LoadBlackListDone( 121 void PreviewsBlackList::LoadBlackListDone(
89 std::unique_ptr<BlackListItemMap> black_list_item_map) { 122 std::unique_ptr<BlackListItemMap> black_list_item_map) {
90 DCHECK(thread_checker_.CalledOnValidThread()); 123 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 174 }
142 if (iter->second->most_recent_opt_out_time().value() < oldest_opt_out) { 175 if (iter->second->most_recent_opt_out_time().value() < oldest_opt_out) {
143 oldest_opt_out = iter->second->most_recent_opt_out_time().value(); 176 oldest_opt_out = iter->second->most_recent_opt_out_time().value();
144 item_to_delete = iter; 177 item_to_delete = iter;
145 } 178 }
146 } 179 }
147 black_list_item_map_->erase(item_to_delete); 180 black_list_item_map_->erase(item_to_delete);
148 } 181 }
149 182
150 } // namespace previews 183 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698