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" |
| 11 | 11 |
| 12 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager() | 12 FakeSafeBrowsingDatabaseManager::FakeSafeBrowsingDatabaseManager() |
| 13 : simulate_timeout_(false) {} | 13 : simulate_timeout_(false) {} |
| 14 | 14 |
| 15 void FakeSafeBrowsingDatabaseManager::AddBlacklistedUrl( | 15 void FakeSafeBrowsingDatabaseManager::AddBlacklistedUrl( |
| 16 const GURL& url, | 16 const GURL& url, |
| 17 safe_browsing::SBThreatType threat_type) { | 17 safe_browsing::SBThreatType threat_type) { |
| 18 url_to_threat_type_[url] = threat_type; | 18 AddBlacklistedUrl(url, threat_type, safe_browsing::ThreatPatternType::NONE); |
| 19 } | |
| 20 | |
| 21 void FakeSafeBrowsingDatabaseManager::AddBlacklistedUrl( | |
| 22 const GURL& url, | |
| 23 safe_browsing::SBThreatType threat_type, | |
| 24 safe_browsing::ThreatPatternType pattern_type) { | |
|
engedy
2017/04/26 13:47:10
nit: Could we just make NONE the default value for
melandory
2017/04/26 15:02:21
Done.
| |
| 25 url_to_threat_type_[url] = std::make_pair(threat_type, pattern_type); | |
| 19 } | 26 } |
| 20 | 27 |
| 21 void FakeSafeBrowsingDatabaseManager::SimulateTimeout() { | 28 void FakeSafeBrowsingDatabaseManager::SimulateTimeout() { |
| 22 simulate_timeout_ = true; | 29 simulate_timeout_ = true; |
| 23 } | 30 } |
| 24 | 31 |
| 25 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() {} | 32 FakeSafeBrowsingDatabaseManager::~FakeSafeBrowsingDatabaseManager() {} |
| 26 | 33 |
| 27 bool FakeSafeBrowsingDatabaseManager::CheckUrlForSubresourceFilter( | 34 bool FakeSafeBrowsingDatabaseManager::CheckUrlForSubresourceFilter( |
| 28 const GURL& url, | 35 const GURL& url, |
| 29 Client* client) { | 36 Client* client) { |
| 30 if (simulate_timeout_) | 37 if (simulate_timeout_) |
| 31 return false; | 38 return false; |
| 32 if (!url_to_threat_type_.count(url)) | 39 if (!url_to_threat_type_.count(url)) |
| 33 return true; | 40 return true; |
| 34 | 41 safe_browsing::ThreatMetadata metadata; |
| 42 metadata.threat_pattern_type = url_to_threat_type_[url].second; | |
| 35 content::BrowserThread::PostTask( | 43 content::BrowserThread::PostTask( |
| 36 content::BrowserThread::IO, FROM_HERE, | 44 content::BrowserThread::IO, FROM_HERE, |
| 37 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), url, | 45 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), url, |
| 38 url_to_threat_type_[url], safe_browsing::ThreatMetadata())); | 46 url_to_threat_type_[url].first, metadata)); |
| 39 return false; | 47 return false; |
| 40 } | 48 } |
| 41 | 49 |
| 42 bool FakeSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url, | 50 bool FakeSafeBrowsingDatabaseManager::CheckResourceUrl(const GURL& url, |
| 43 Client* client) { | 51 Client* client) { |
| 44 return true; | 52 return true; |
| 45 } | 53 } |
| 46 | 54 |
| 47 bool FakeSafeBrowsingDatabaseManager::IsSupported() const { | 55 bool FakeSafeBrowsingDatabaseManager::IsSupported() const { |
| 48 return true; | 56 return true; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 59 safe_browsing::ThreatSource FakeSafeBrowsingDatabaseManager::GetThreatSource() | 67 safe_browsing::ThreatSource FakeSafeBrowsingDatabaseManager::GetThreatSource() |
| 60 const { | 68 const { |
| 61 return safe_browsing::ThreatSource::LOCAL_PVER4; | 69 return safe_browsing::ThreatSource::LOCAL_PVER4; |
| 62 } | 70 } |
| 63 | 71 |
| 64 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( | 72 bool FakeSafeBrowsingDatabaseManager::CheckExtensionIDs( |
| 65 const std::set<std::string>& extension_ids, | 73 const std::set<std::string>& extension_ids, |
| 66 Client* client) { | 74 Client* client) { |
| 67 return true; | 75 return true; |
| 68 } | 76 } |
| OLD | NEW |