| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/safe_browsing_db/v4_get_hash_protocol_manager.h" | 5 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/stl_util.h" |
| 13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 16 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 17 #include "net/http/http_status_code.h" | 18 #include "net/http/http_status_code.h" |
| 18 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 20 | 21 |
| 21 using base::Time; | 22 using base::Time; |
| 22 using base::TimeDelta; | 23 using base::TimeDelta; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 const StoresToCheck& stores_to_check, | 232 const StoresToCheck& stores_to_check, |
| 232 const V4ProtocolConfig& config) | 233 const V4ProtocolConfig& config) |
| 233 : gethash_error_count_(0), | 234 : gethash_error_count_(0), |
| 234 gethash_back_off_mult_(1), | 235 gethash_back_off_mult_(1), |
| 235 next_gethash_time_(Time::FromDoubleT(0)), | 236 next_gethash_time_(Time::FromDoubleT(0)), |
| 236 config_(config), | 237 config_(config), |
| 237 request_context_getter_(request_context_getter), | 238 request_context_getter_(request_context_getter), |
| 238 url_fetcher_id_(0), | 239 url_fetcher_id_(0), |
| 239 clock_(new base::DefaultClock()) { | 240 clock_(new base::DefaultClock()) { |
| 240 DCHECK(!stores_to_check.empty()); | 241 DCHECK(!stores_to_check.empty()); |
| 242 std::set<PlatformType> platform_types; |
| 243 std::set<ThreatEntryType> threat_entry_types; |
| 244 std::set<ThreatType> threat_types; |
| 241 for (const ListIdentifier& store : stores_to_check) { | 245 for (const ListIdentifier& store : stores_to_check) { |
| 242 platform_types_.insert(store.platform_type()); | 246 platform_types.insert(store.platform_type()); |
| 243 threat_entry_types_.insert(store.threat_entry_type()); | 247 threat_entry_types.insert(store.threat_entry_type()); |
| 244 threat_types_.insert(store.threat_type()); | 248 threat_types.insert(store.threat_type()); |
| 245 } | 249 } |
| 250 platform_types_.assign(platform_types.begin(), platform_types.end()); |
| 251 threat_entry_types_.assign(threat_entry_types.begin(), |
| 252 threat_entry_types.end()); |
| 253 threat_types_.assign(threat_types.begin(), threat_types.end()); |
| 246 } | 254 } |
| 247 | 255 |
| 248 V4GetHashProtocolManager::~V4GetHashProtocolManager() {} | 256 V4GetHashProtocolManager::~V4GetHashProtocolManager() {} |
| 249 | 257 |
| 250 void V4GetHashProtocolManager::ClearCache() { | 258 void V4GetHashProtocolManager::ClearCache() { |
| 251 DCHECK(CalledOnValidThread()); | 259 DCHECK(CalledOnValidThread()); |
| 252 full_hash_cache_.clear(); | 260 full_hash_cache_.clear(); |
| 253 } | 261 } |
| 254 | 262 |
| 255 void V4GetHashProtocolManager::GetFullHashes( | 263 void V4GetHashProtocolManager::GetFullHashes( |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); | 530 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR); |
| 523 return false; | 531 return false; |
| 524 } | 532 } |
| 525 if (!match.has_threat()) { | 533 if (!match.has_threat()) { |
| 526 RecordParseGetHashResult(NO_THREAT_ERROR); | 534 RecordParseGetHashResult(NO_THREAT_ERROR); |
| 527 return false; | 535 return false; |
| 528 } | 536 } |
| 529 | 537 |
| 530 ListIdentifier list_id(match.platform_type(), match.threat_entry_type(), | 538 ListIdentifier list_id(match.platform_type(), match.threat_entry_type(), |
| 531 match.threat_type()); | 539 match.threat_type()); |
| 540 if (!base::ContainsValue(platform_types_, list_id.platform_type()) || |
| 541 !base::ContainsValue(threat_entry_types_, |
| 542 list_id.threat_entry_type()) || |
| 543 !base::ContainsValue(threat_types_, list_id.threat_type())) { |
| 544 // The server may send a ThreatMatch response for lists that we didn't ask |
| 545 // for so ignore those ThreatMatch responses. |
| 546 continue; |
| 547 } |
| 548 |
| 532 base::Time positive_expiry; | 549 base::Time positive_expiry; |
| 533 if (match.has_cache_duration()) { | 550 if (match.has_cache_duration()) { |
| 534 // Seconds resolution is good enough so we ignore the nanos field. | 551 // Seconds resolution is good enough so we ignore the nanos field. |
| 535 positive_expiry = clock_->Now() + TimeDelta::FromSeconds( | 552 positive_expiry = clock_->Now() + TimeDelta::FromSeconds( |
| 536 match.cache_duration().seconds()); | 553 match.cache_duration().seconds()); |
| 537 } else { | 554 } else { |
| 538 positive_expiry = clock_->Now() - base::TimeDelta::FromSeconds(1); | 555 positive_expiry = clock_->Now() - base::TimeDelta::FromSeconds(1); |
| 539 } | 556 } |
| 540 FullHashInfo full_hash_info(match.threat().hash(), list_id, | 557 FullHashInfo full_hash_info(match.threat().hash(), list_id, |
| 541 positive_expiry); | 558 positive_expiry); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { | 753 std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { |
| 737 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id | 754 os << "{full_hash: " << fhi.full_hash << "; list_id: " << fhi.list_id |
| 738 << "; positive_expiry: " << fhi.positive_expiry | 755 << "; positive_expiry: " << fhi.positive_expiry |
| 739 << "; metadata.api_permissions.size(): " | 756 << "; metadata.api_permissions.size(): " |
| 740 << fhi.metadata.api_permissions.size() << "}"; | 757 << fhi.metadata.api_permissions.size() << "}"; |
| 741 return os; | 758 return os; |
| 742 } | 759 } |
| 743 #endif | 760 #endif |
| 744 | 761 |
| 745 } // namespace safe_browsing | 762 } // namespace safe_browsing |
| OLD | NEW |