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

Side by Side 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, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/subresource_filter/content/browser/fake_safe_browsing_datab ase_manager.h" 5 #include "components/subresource_filter/content/browser/fake_safe_browsing_datab ase_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
9 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
10 #include "url/gurl.h" 11 #include "url/gurl.h"
11 12
12 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager() 13 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager()
13 : simulate_timeout_(false) {} 14 : simulate_timeout_(false) {}
14 15
15 void FakeSafeBrowsingDatabaseManager::AddBlacklistedUrl( 16 void FakeSafeBrowsingDatabaseManager::AddBlacklistedUrl(
16 const GURL& url, 17 const GURL& url,
17 safe_browsing::SBThreatType threat_type) { 18 safe_browsing::SBThreatType threat_type) {
18 url_to_threat_type_[url] = threat_type; 19 url_to_threat_type_[url] = threat_type;
19 } 20 }
20 21
21 void FakeSafeBrowsingDatabaseManager::SimulateTimeout() { 22 void FakeSafeBrowsingDatabaseManager::SimulateTimeout() {
22 simulate_timeout_ = true; 23 simulate_timeout_ = true;
23 } 24 }
24 25
25 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() {} 26 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() {}
26 27
27 bool FakeSafeBrowsingDatabaseManager::CheckUrlForSubresourceFilter( 28 bool FakeSafeBrowsingDatabaseManager::CheckUrlForSubresourceFilter(
28 const GURL& url, 29 const GURL& url,
29 Client* client) { 30 Client* client) {
30 if (simulate_timeout_) 31 if (simulate_timeout_)
31 return false; 32 return false;
32 if (!url_to_threat_type_.count(url)) 33 if (!url_to_threat_type_.count(url))
33 return true; 34 return true;
34 35
36 // Enforce the invariant that a client will not send multiple requests, with
37 // the subresource filter client implementation.
38 DCHECK(checks_.find(client) == checks_.end());
39 checks_.insert(client);
35 content::BrowserThread::PostTask( 40 content::BrowserThread::PostTask(
36 content::BrowserThread::IO, FROM_HERE, 41 content::BrowserThread::IO, FROM_HERE,
37 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), url, 42 base::Bind(&FakeSafeBrowsingDatabaseManager::
38 url_to_threat_type_[url], safe_browsing::ThreatMetadata())); 43 OnCheckUrlForSubresourceFilterComplete,
44 base::Unretained(this), base::Unretained(client), url));
39 return false; 45 return false;
40 } 46 }
41 47
48 void FakeSafeBrowsingDatabaseManager::OnCheckUrlForSubresourceFilterComplete(
49 Client* client,
50 const GURL& url) {
51 // Check to see if the request was cancelled to avoid use-after-free.
52 if (checks_.find(client) == checks_.end())
53 return;
54 client->OnCheckBrowseUrlResult(url, url_to_threat_type_[url],
55 safe_browsing::ThreatMetadata());
56 }
57
42 bool FakeSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url, 58 bool FakeSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url,
43 Client* client) { 59 Client* client) {
44 return true; 60 return true;
45 } 61 }
46 62
47 bool FakeSafeBrowsingDatabaseManager::IsSupported() const { 63 bool FakeSafeBrowsingDatabaseManager::IsSupported() const {
48 return true; 64 return true;
49 } 65 }
50 bool FakeSafeBrowsingDatabaseManager::ChecksAreAlwaysAsync() const { 66 bool FakeSafeBrowsingDatabaseManager::ChecksAreAlwaysAsync() const {
51 return false; 67 return false;
52 } 68 }
53 void FakeSafeBrowsingDatabaseManager::CancelCheck(Client* client) {} 69 void FakeSafeBrowsingDatabaseManager::CancelCheck(Client* client) {
70 checks_.erase(client);
71 }
54 bool FakeSafeBrowsingDatabaseManager::CanCheckResourceType( 72 bool FakeSafeBrowsingDatabaseManager::CanCheckResourceType(
55 content::ResourceType /* resource_type */) const { 73 content::ResourceType /* resource_type */) const {
56 return true; 74 return true;
57 } 75 }
58 76
59 safe_browsing::ThreatSource FakeSafeBrowsingDatabaseManager::GetThreatSource() 77 safe_browsing::ThreatSource FakeSafeBrowsingDatabaseManager::GetThreatSource()
60 const { 78 const {
61 return safe_browsing::ThreatSource::LOCAL_PVER4; 79 return safe_browsing::ThreatSource::LOCAL_PVER4;
62 } 80 }
63 81
64 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( 82 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs(
65 const std::set<std::string>& extension_ids, 83 const std::set<std::string>& extension_ids,
66 Client* client) { 84 Client* client) {
67 return true; 85 return true;
68 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698