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_protocol_manager_util.h" | 5 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
12 #include "net/http/http_request_headers.h" | 12 #include "net/http/http_request_headers.h" |
13 | 13 |
14 using base::Time; | 14 using base::Time; |
15 using base::TimeDelta; | 15 using base::TimeDelta; |
16 | 16 |
17 namespace safe_browsing { | 17 namespace safe_browsing { |
18 | 18 |
| 19 std::ostream& operator<<(std::ostream& os, const UpdateListIdentifier& id) { |
| 20 os << "{hash: " << id.hash() << "; platform_type: " << id.platform_type |
| 21 << "; threat_entry_type: " << id.threat_entry_type |
| 22 << "; threat_type: " << id.threat_type << "}"; |
| 23 return os; |
| 24 } |
| 25 |
19 // The Safe Browsing V4 server URL prefix. | 26 // The Safe Browsing V4 server URL prefix. |
20 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; | 27 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; |
21 | 28 |
22 bool UpdateListIdentifier::operator==(const UpdateListIdentifier& other) const { | 29 bool UpdateListIdentifier::operator==(const UpdateListIdentifier& other) const { |
23 return platform_type == other.platform_type && | 30 return platform_type == other.platform_type && |
24 threat_entry_type == other.threat_entry_type && | 31 threat_entry_type == other.threat_entry_type && |
25 threat_type == other.threat_type; | 32 threat_type == other.threat_type; |
26 } | 33 } |
27 | 34 |
28 bool UpdateListIdentifier::operator!=(const UpdateListIdentifier& other) const { | 35 bool UpdateListIdentifier::operator!=(const UpdateListIdentifier& other) const { |
29 return !operator==(other); | 36 return !operator==(other); |
30 } | 37 } |
31 | 38 |
32 size_t UpdateListIdentifier::hash() const { | 39 size_t UpdateListIdentifier::hash() const { |
33 std::size_t first = std::hash<unsigned int>()(platform_type); | 40 std::size_t first = std::hash<unsigned int>()(platform_type); |
34 std::size_t second = std::hash<unsigned int>()(threat_entry_type); | 41 std::size_t second = std::hash<unsigned int>()(threat_entry_type); |
35 std::size_t third = std::hash<unsigned int>()(threat_type); | 42 std::size_t third = std::hash<unsigned int>()(threat_type); |
36 | 43 |
37 std::size_t interim = base::HashInts(first, second); | 44 std::size_t interim = base::HashInts(first, second); |
38 return base::HashInts(interim, third); | 45 return base::HashInts(interim, third); |
39 } | 46 } |
40 | 47 |
| 48 UpdateListIdentifier::UpdateListIdentifier() {} |
| 49 |
| 50 UpdateListIdentifier::UpdateListIdentifier(PlatformType platform_type, |
| 51 ThreatEntryType threat_entry_type, |
| 52 ThreatType threat_type) |
| 53 : platform_type(platform_type), |
| 54 threat_entry_type(threat_entry_type), |
| 55 threat_type(threat_type) { |
| 56 DCHECK(PlatformType_IsValid(platform_type)); |
| 57 DCHECK(ThreatEntryType_IsValid(threat_entry_type)); |
| 58 DCHECK(ThreatType_IsValid(threat_type)); |
| 59 } |
| 60 |
| 61 UpdateListIdentifier::UpdateListIdentifier(const ListUpdateResponse& response) |
| 62 : UpdateListIdentifier(response.platform_type(), |
| 63 response.threat_entry_type(), |
| 64 response.threat_type()) {} |
| 65 |
41 V4ProtocolConfig::V4ProtocolConfig() : disable_auto_update(false) {} | 66 V4ProtocolConfig::V4ProtocolConfig() : disable_auto_update(false) {} |
42 | 67 |
43 V4ProtocolConfig::V4ProtocolConfig(const V4ProtocolConfig& other) = default; | 68 V4ProtocolConfig::V4ProtocolConfig(const V4ProtocolConfig& other) = default; |
44 | 69 |
45 V4ProtocolConfig::~V4ProtocolConfig() {} | 70 V4ProtocolConfig::~V4ProtocolConfig() {} |
46 | 71 |
47 // static | 72 // static |
48 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where | 73 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where |
49 // n is the number of consecutive errors. | 74 // n is the number of consecutive errors. |
50 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval( | 75 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 132 |
108 // static | 133 // static |
109 void V4ProtocolManagerUtil::UpdateHeaders(net::HttpRequestHeaders* headers) { | 134 void V4ProtocolManagerUtil::UpdateHeaders(net::HttpRequestHeaders* headers) { |
110 // NOTE(vakh): The following header informs the envelope server (which sits in | 135 // NOTE(vakh): The following header informs the envelope server (which sits in |
111 // front of Google's stubby server) that the received GET request should be | 136 // front of Google's stubby server) that the received GET request should be |
112 // interpreted as a POST. | 137 // interpreted as a POST. |
113 headers->SetHeaderIfMissing("X-HTTP-Method-Override", "POST"); | 138 headers->SetHeaderIfMissing("X-HTTP-Method-Override", "POST"); |
114 } | 139 } |
115 | 140 |
116 } // namespace safe_browsing | 141 } // namespace safe_browsing |
OLD | NEW |