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

Unified Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2565283008: Fix race condition with CancelCheck(). (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/v4_local_database_manager.cc
diff --git a/components/safe_browsing_db/v4_local_database_manager.cc b/components/safe_browsing_db/v4_local_database_manager.cc
index ce0831247ec8a796607415a0af839678f6ba3522..5c91e34b9b1b05d0bcdbdc6da288eecf12fd0146 100644
--- a/components/safe_browsing_db/v4_local_database_manager.cc
+++ b/components/safe_browsing_db/v4_local_database_manager.cc
@@ -516,6 +516,7 @@ bool V4LocalDatabaseManager::HandleCheck(std::unique_ptr<PendingCheck> check) {
}
// Post on the IO thread to enforce async behavior.
+ pending_clients_.insert(check->client);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&V4LocalDatabaseManager::PerformFullHashCheck, this,
@@ -584,8 +585,6 @@ void V4LocalDatabaseManager::PerformFullHashCheck(
DCHECK(enabled_);
DCHECK(!full_hash_to_store_and_hash_prefixes.empty());
Nathan Parker 2016/12/14 18:03:03 Maybe add a comment that the caller should have ad
Scott Hess - ex-Googler 2016/12/14 20:45:58 Should have, but if CancelCheck() was called betwe
- pending_clients_.insert(check->client);
-
v4_get_hash_protocol_manager_->GetFullHashes(
full_hash_to_store_and_hash_prefixes,
base::Bind(&V4LocalDatabaseManager::OnFullHashResponse,
@@ -594,23 +593,32 @@ void V4LocalDatabaseManager::PerformFullHashCheck(
void V4LocalDatabaseManager::ProcessQueuedChecks() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- for (auto& it : queued_checks_) {
+
+ // Steal the queue to protect against reentrant CancelCheck() calls.
Nathan Parker 2016/12/14 18:03:04 Is this if they call Cancel() from within RespondT
Scott Hess - ex-Googler 2016/12/14 20:45:58 Yes, that is my concern. We're calling out to ext
Scott Hess - ex-Googler 2016/12/14 20:56:33 OK, it looks like for(:) implementation expects to
+ QueuedChecks checks;
+ checks.swap(queued_checks_);
+
+ for (auto& it : checks) {
FullHashToStoreAndHashPrefixesMap full_hash_to_store_and_hash_prefixes;
if (!GetPrefixMatches(it, &full_hash_to_store_and_hash_prefixes)) {
RespondToClient(std::move(it));
Scott Hess - ex-Googler 2016/12/15 01:14:13 Ha, it took some work, but the amusing result is t
} else {
+ pending_clients_.insert(it->client);
PerformFullHashCheck(std::move(it), full_hash_to_store_and_hash_prefixes);
}
}
- queued_checks_.clear();
}
void V4LocalDatabaseManager::RespondSafeToQueuedChecks() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- for (std::unique_ptr<PendingCheck>& it : queued_checks_) {
+
+ // Steal the queue to protect against reentrant CancelCheck() calls.
+ QueuedChecks checks;
+ checks.swap(queued_checks_);
+
+ for (std::unique_ptr<PendingCheck>& it : checks) {
RespondToClient(std::move(it));
}
- queued_checks_.clear();
}
void V4LocalDatabaseManager::RespondToClient(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698