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

Unified Diff: components/subresource_filter/content/browser/fake_safe_browsing_database_manager.cc

Issue 2834543003: [subresource_filter] SB throttle can send multiple speculative requests. (Closed)
Patch Set: Add NoRedirectSpeculation metric Created 3 years, 8 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/subresource_filter/content/browser/fake_safe_browsing_database_manager.cc
diff --git a/components/subresource_filter/content/browser/fake_safe_browsing_database_manager.cc b/components/subresource_filter/content/browser/fake_safe_browsing_database_manager.cc
index f6526bd7b29b575c4fccaf829eb043d2db9a2613..cfd968e8f7eb8c0182389c12ba3eed06fb41e423 100644
--- a/components/subresource_filter/content/browser/fake_safe_browsing_database_manager.cc
+++ b/components/subresource_filter/content/browser/fake_safe_browsing_database_manager.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
+#include "base/logging.h"
#include "content/public/browser/browser_thread.h"
#include "url/gurl.h"
@@ -32,13 +33,28 @@ bool FakeSafeBrowsingDatabaseManager::CheckUrlForSubresourceFilter(
if (!url_to_threat_type_.count(url))
return true;
+ // Enforce the invariant that a client will not send multiple requests, with
+ // the subresource filter client implementation.
+ DCHECK(checks_.find(client) == checks_.end());
+ checks_.insert(client);
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
- base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), url,
- url_to_threat_type_[url], safe_browsing::ThreatMetadata()));
+ base::Bind(&FakeSafeBrowsingDatabaseManager::
+ OnCheckUrlForSubresourceFilterComplete,
+ base::Unretained(this), base::Unretained(client), url));
return false;
}
+void FakeSafeBrowsingDatabaseManager::OnCheckUrlForSubresourceFilterComplete(
+ Client* client,
+ const GURL& url) {
+ // Check to see if the request was cancelled to avoid use-after-free.
+ if (checks_.find(client) == checks_.end())
+ return;
+ client->OnCheckBrowseUrlResult(url, url_to_threat_type_[url],
+ safe_browsing::ThreatMetadata());
+}
+
bool FakeSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url,
Client* client) {
return true;
@@ -50,7 +66,9 @@ bool FakeSafeBrowsingDatabaseManager::IsSupported() const {
bool FakeSafeBrowsingDatabaseManager::ChecksAreAlwaysAsync() const {
return false;
}
-void FakeSafeBrowsingDatabaseManager::CancelCheck(Client* client) {}
+void FakeSafeBrowsingDatabaseManager::CancelCheck(Client* client) {
+ checks_.erase(client);
+}
bool FakeSafeBrowsingDatabaseManager::CanCheckResourceType(
content::ResourceType /* resource_type */) const {
return true;

Powered by Google App Engine
This is Rietveld 408576698