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

Unified 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 side-by-side diff with in-line comments
Download patch
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);
+ 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());
« no previous file with comments | « components/previews/core/previews_black_list.h ('k') | components/previews/core/previews_black_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698