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 08b9fa2910c4abbb05b4232100bd2bb6038144e1..fa5d1262f1eaa03ba1770685997668769fceecc2 100644 |
--- a/components/previews/core/previews_black_list.cc |
+++ b/components/previews/core/previews_black_list.cc |
@@ -37,6 +37,17 @@ void EvictOldestOptOut(BlackListItemMap* black_list_item_map) { |
black_list_item_map->erase(item_to_delete); |
} |
+// Returns the PreviewsBlackListItem representing |host_name| in |
+// |black_list_item_map|. If there is no item for |host_name|, returns null. |
+PreviewsBlackListItem* GetBlackListItemFromMap( |
+ const BlackListItemMap& black_list_item_map, |
+ const std::string& host_name) { |
+ BlackListItemMap::const_iterator iter = black_list_item_map.find(host_name); |
+ if (iter != black_list_item_map.end()) |
+ return iter->second.get(); |
+ return nullptr; |
+} |
+ |
} // namespace |
PreviewsBlackList::PreviewsBlackList( |
@@ -50,7 +61,8 @@ PreviewsBlackList::PreviewsBlackList( |
opt_out_store_->LoadBlackList(base::Bind( |
&PreviewsBlackList::LoadBlackListDone, weak_factory_.GetWeakPtr())); |
} else { |
- LoadBlackListDone(base::MakeUnique<BlackListItemMap>()); |
+ LoadBlackListDone(base::MakeUnique<BlackListItemMap>(), |
+ CreateHostIndifferentBlackListItem()); |
} |
} |
@@ -81,13 +93,16 @@ void PreviewsBlackList::AddPreviewNavigationSync(const GURL& url, |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(url.has_host()); |
DCHECK(loaded_); |
+ DCHECK(host_indifferent_black_list_item_); |
+ DCHECK(black_list_item_map_); |
std::string host_name = url.host(); |
base::Time now = clock_->Now(); |
PreviewsBlackListItem* item = |
- GetOrCreateBlackListItem(black_list_item_map_.get(), host_name); |
+ GetOrCreateBlackListItemForMap(black_list_item_map_.get(), host_name); |
item->AddPreviewNavigation(opt_out, now); |
DCHECK_LE(black_list_item_map_->size(), |
params::MaxInMemoryHostsInBlackList()); |
+ host_indifferent_black_list_item_->AddPreviewNavigation(opt_out, now); |
if (!opt_out_store_) |
return; |
opt_out_store_->AddPreviewNavigation(opt_out, host_name, type, now); |
@@ -99,13 +114,16 @@ bool PreviewsBlackList::IsLoadedAndAllowed(const GURL& url, |
DCHECK(url.has_host()); |
if (!loaded_) |
return false; |
+ DCHECK(black_list_item_map_); |
if (last_opt_out_time_ && |
clock_->Now() < |
last_opt_out_time_.value() + params::SingleOptOutDuration()) { |
return false; |
} |
+ if (host_indifferent_black_list_item_->IsBlackListed(clock_->Now())) |
+ return false; |
PreviewsBlackListItem* black_list_item = |
- GetBlackListItem(*black_list_item_map_, url.host()); |
+ GetBlackListItemFromMap(*black_list_item_map_, url.host()); |
return !black_list_item || !black_list_item->IsBlackListed(clock_->Now()); |
} |
@@ -129,7 +147,8 @@ void PreviewsBlackList::ClearBlackListSync(base::Time begin_time, |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(loaded_); |
DCHECK_LE(begin_time, end_time); |
- black_list_item_map_.reset(nullptr); |
+ black_list_item_map_.reset(); |
+ host_indifferent_black_list_item_.reset(); |
loaded_ = false; |
// Delete relevant entries and reload the blacklist into memory. |
if (opt_out_store_) { |
@@ -137,7 +156,8 @@ void PreviewsBlackList::ClearBlackListSync(base::Time begin_time, |
opt_out_store_->LoadBlackList(base::Bind( |
&PreviewsBlackList::LoadBlackListDone, weak_factory_.GetWeakPtr())); |
} else { |
- LoadBlackListDone(base::MakeUnique<BlackListItemMap>()); |
+ LoadBlackListDone(base::MakeUnique<BlackListItemMap>(), |
+ CreateHostIndifferentBlackListItem()); |
} |
} |
@@ -149,11 +169,16 @@ void PreviewsBlackList::QueuePendingTask(base::Closure callback) { |
} |
void PreviewsBlackList::LoadBlackListDone( |
- std::unique_ptr<BlackListItemMap> black_list_item_map) { |
+ std::unique_ptr<BlackListItemMap> black_list_item_map, |
+ std::unique_ptr<PreviewsBlackListItem> host_indifferent_black_list_item) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ DCHECK(black_list_item_map); |
+ DCHECK(host_indifferent_black_list_item); |
DCHECK_LE(black_list_item_map->size(), params::MaxInMemoryHostsInBlackList()); |
loaded_ = true; |
black_list_item_map_ = std::move(black_list_item_map); |
+ host_indifferent_black_list_item_ = |
+ std::move(host_indifferent_black_list_item); |
// Run all pending tasks. |loaded_| may change if ClearBlackList is queued. |
while (pending_callbacks_.size() > 0 && loaded_) { |
@@ -163,32 +188,32 @@ void PreviewsBlackList::LoadBlackListDone( |
} |
// static |
-PreviewsBlackListItem* PreviewsBlackList::GetBlackListItem( |
- const BlackListItemMap& black_list_item_map, |
- const std::string& host_name) { |
- BlackListItemMap::const_iterator iter = black_list_item_map.find(host_name); |
- if (iter != black_list_item_map.end()) |
- return iter->second.get(); |
- return nullptr; |
-} |
- |
-// static |
-PreviewsBlackListItem* PreviewsBlackList::GetOrCreateBlackListItem( |
+PreviewsBlackListItem* PreviewsBlackList::GetOrCreateBlackListItemForMap( |
BlackListItemMap* black_list_item_map, |
const std::string& host_name) { |
PreviewsBlackListItem* black_list_item = |
- GetBlackListItem(*black_list_item_map, host_name); |
+ GetBlackListItemFromMap(*black_list_item_map, host_name); |
if (black_list_item) |
return black_list_item; |
if (black_list_item_map->size() >= params::MaxInMemoryHostsInBlackList()) |
EvictOldestOptOut(black_list_item_map); |
DCHECK_LT(black_list_item_map->size(), params::MaxInMemoryHostsInBlackList()); |
black_list_item = new PreviewsBlackListItem( |
- params::MaxStoredHistoryLengthForBlackList(), |
- params::BlackListOptOutThreshold(), params::BlackListDuration()); |
+ params::MaxStoredHistoryLengthForPerHostBlackList(), |
+ params::PerHostBlackListOptOutThreshold(), |
+ params::PerHostBlackListDuration()); |
black_list_item_map->operator[](host_name) = |
base::WrapUnique(black_list_item); |
return black_list_item; |
} |
+// static |
+std::unique_ptr<PreviewsBlackListItem> |
+PreviewsBlackList::CreateHostIndifferentBlackListItem() { |
+ return base::MakeUnique<PreviewsBlackListItem>( |
+ params::MaxStoredHistoryLengthForHostIndifferentBlackList(), |
+ params::HostIndifferentBlackListOptOutThreshold(), |
+ params::HostIndifferentBlackListPerHostDuration()); |
+} |
+ |
} // namespace previews |