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 // The Safe Browsing V4 server URL prefix. | 19 // The Safe Browsing V4 server URL prefix. |
20 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; | 20 const char kSbV4UrlPrefix[] = "https://safebrowsing.googleapis.com/v4"; |
21 | 21 |
22 std::ostream& operator<<(std::ostream& os, const UpdateListIdentifier& id) { | |
23 os << "hash: " << id.hash() << "; platform_type: " << id.platform_type | |
24 << "; threat_entry_type: " << id.threat_entry_type | |
25 << "; threat_type: " << id.threat_type; | |
26 return os; | |
27 } | |
Scott Hess - ex-Googler
2016/06/17 22:53:43
I'm not sure how this integrates with the overall
vakh (use Gerrit instead)
2016/06/20 22:28:43
You mean just empty {}? It's not clear to me how t
Scott Hess - ex-Googler
2016/06/21 21:03:44
I mean that whoever is invoking this might be code
vakh (use Gerrit instead)
2016/06/21 23:19:35
Done.
Scott Hess - ex-Googler
2016/06/24 23:01:19
I'll grant that there may not be _much_ harm in ke
vakh (use Gerrit instead)
2016/06/27 19:38:27
It is being used in a valid case: if we get an upd
Scott Hess - ex-Googler
2016/06/27 22:19:17
Sigh, "bee in my bonnet". Basically "Why does Sco
vakh (use Gerrit instead)
2016/06/27 23:58:52
Acknowledged.
| |
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() {} | |
Scott Hess - ex-Googler
2016/06/17 22:53:43
Is the bare version ever used?
If so, will everyt
vakh (use Gerrit instead)
2016/06/20 22:28:43
Done.
| |
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 | |
57 UpdateListIdentifier::UpdateListIdentifier(const ListUpdateResponse& response) | |
58 : UpdateListIdentifier(response.platform_type(), | |
59 response.threat_entry_type(), | |
60 response.threat_type()) {} | |
61 | |
41 V4ProtocolConfig::V4ProtocolConfig() : disable_auto_update(false) {} | 62 V4ProtocolConfig::V4ProtocolConfig() : disable_auto_update(false) {} |
42 | 63 |
43 V4ProtocolConfig::V4ProtocolConfig(const V4ProtocolConfig& other) = default; | 64 V4ProtocolConfig::V4ProtocolConfig(const V4ProtocolConfig& other) = default; |
44 | 65 |
45 V4ProtocolConfig::~V4ProtocolConfig() {} | 66 V4ProtocolConfig::~V4ProtocolConfig() {} |
46 | 67 |
47 // static | 68 // static |
48 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where | 69 // Backoff interval is MIN(((2^(n-1))*15 minutes) * (RAND + 1), 24 hours) where |
49 // n is the number of consecutive errors. | 70 // n is the number of consecutive errors. |
50 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval( | 71 base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 128 |
108 // static | 129 // static |
109 void V4ProtocolManagerUtil::UpdateHeaders(net::HttpRequestHeaders* headers) { | 130 void V4ProtocolManagerUtil::UpdateHeaders(net::HttpRequestHeaders* headers) { |
110 // NOTE(vakh): The following header informs the envelope server (which sits in | 131 // 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 | 132 // front of Google's stubby server) that the received GET request should be |
112 // interpreted as a POST. | 133 // interpreted as a POST. |
113 headers->SetHeaderIfMissing("X-HTTP-Method-Override", "POST"); | 134 headers->SetHeaderIfMissing("X-HTTP-Method-Override", "POST"); |
114 } | 135 } |
115 | 136 |
116 } // namespace safe_browsing | 137 } // namespace safe_browsing |
OLD | NEW |