Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() {} | 25 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() {} |
| 26 | 26 |
| 27 bool FakeSafeBrowsingDatabaseManager::CheckUrlForSubresourceFilter( | 27 bool FakeSafeBrowsingDatabaseManager::CheckUrlForSubresourceFilter( |
| 28 const GURL& url, | 28 const GURL& url, |
| 29 Client* client) { | 29 Client* client) { |
| 30 if (simulate_timeout_) | 30 if (simulate_timeout_) |
| 31 return false; | 31 return false; |
| 32 if (!url_to_threat_type_.count(url)) | 32 if (!url_to_threat_type_.count(url)) |
| 33 return true; | 33 return true; |
| 34 | 34 |
| 35 // Enforce the invariant that a client will not send multiple requests, with | |
| 36 // the subresource filter client implementation. | |
| 37 DCHECK(checks_.find(client) == checks_.end()); | |
|
engedy
2017/04/25 22:03:53
#include "base/logging.h"
Charlie Harrison
2017/04/26 14:30:25
Done.
| |
| 38 checks_.insert(client); | |
| 35 content::BrowserThread::PostTask( | 39 content::BrowserThread::PostTask( |
| 36 content::BrowserThread::IO, FROM_HERE, | 40 content::BrowserThread::IO, FROM_HERE, |
| 37 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), url, | 41 base::Bind(&FakeSafeBrowsingDatabaseManager:: |
| 38 url_to_threat_type_[url], safe_browsing::ThreatMetadata())); | 42 OnCheckUrlForSubresourceFilterComplete, |
| 43 base::Unretained(this), base::Unretained(client), url)); | |
| 39 return false; | 44 return false; |
| 40 } | 45 } |
| 41 | 46 |
| 47 void FakeSafeBrowsingDatabaseManager::OnCheckUrlForSubresourceFilterComplete( | |
| 48 Client* client, | |
| 49 const GURL& url) { | |
| 50 // Check to see if the request was cancelled to avoid use-after-free. | |
| 51 if (checks_.find(client) == checks_.end()) | |
| 52 return; | |
| 53 client->OnCheckBrowseUrlResult(url, url_to_threat_type_[url], | |
| 54 safe_browsing::ThreatMetadata()); | |
| 55 } | |
| 56 | |
| 42 bool FakeSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url, | 57 bool FakeSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url, |
| 43 Client* client) { | 58 Client* client) { |
| 44 return true; | 59 return true; |
| 45 } | 60 } |
| 46 | 61 |
| 47 bool FakeSafeBrowsingDatabaseManager::IsSupported() const { | 62 bool FakeSafeBrowsingDatabaseManager::IsSupported() const { |
| 48 return true; | 63 return true; |
| 49 } | 64 } |
| 50 bool FakeSafeBrowsingDatabaseManager::ChecksAreAlwaysAsync() const { | 65 bool FakeSafeBrowsingDatabaseManager::ChecksAreAlwaysAsync() const { |
| 51 return false; | 66 return false; |
| 52 } | 67 } |
| 53 void FakeSafeBrowsingDatabaseManager::CancelCheck(Client* client) {} | 68 void FakeSafeBrowsingDatabaseManager::CancelCheck(Client* client) { |
| 69 checks_.erase(client); | |
| 70 } | |
| 54 bool FakeSafeBrowsingDatabaseManager::CanCheckResourceType( | 71 bool FakeSafeBrowsingDatabaseManager::CanCheckResourceType( |
| 55 content::ResourceType /* resource_type */) const { | 72 content::ResourceType /* resource_type */) const { |
| 56 return true; | 73 return true; |
| 57 } | 74 } |
| 58 | 75 |
| 59 safe_browsing::ThreatSource FakeSafeBrowsingDatabaseManager::GetThreatSource() | 76 safe_browsing::ThreatSource FakeSafeBrowsingDatabaseManager::GetThreatSource() |
| 60 const { | 77 const { |
| 61 return safe_browsing::ThreatSource::LOCAL_PVER4; | 78 return safe_browsing::ThreatSource::LOCAL_PVER4; |
| 62 } | 79 } |
| 63 | 80 |
| 64 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( | 81 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( |
| 65 const std::set<std::string>& extension_ids, | 82 const std::set<std::string>& extension_ids, |
| 66 Client* client) { | 83 Client* client) { |
| 67 return true; | 84 return true; |
| 68 } | 85 } |
| OLD | NEW |