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 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ | 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |
7 | 7 |
8 // A class that implements the stateless methods used by the GetHashUpdate and | 8 // A class that implements the stateless methods used by the GetHashUpdate and |
9 // GetFullHash stubby calls made by Chrome using the SafeBrowsing V4 protocol. | 9 // GetFullHash stubby calls made by Chrome using the SafeBrowsing V4 protocol. |
10 | 10 |
11 #include <ostream> | 11 #include <ostream> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/hash.h" | 15 #include "base/hash.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "components/safe_browsing_db/safebrowsing.pb.h" | 17 #include "components/safe_browsing_db/safebrowsing.pb.h" |
18 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 class HttpRequestHeaders; | 22 class HttpRequestHeaders; |
23 } // namespace net | 23 } // namespace net |
24 | 24 |
25 struct EnumClassHash { | |
26 template <typename T> | |
27 std::size_t operator()(T t) const { | |
28 return static_cast<std::size_t>(t); | |
29 } | |
30 }; | |
31 | |
25 namespace safe_browsing { | 32 namespace safe_browsing { |
26 | 33 |
27 // A hash prefix sent by the SafeBrowsing PVer4 service. | 34 // A hash prefix sent by the SafeBrowsing PVer4 service. |
28 typedef std::string HashPrefix; | 35 typedef std::string HashPrefix; |
29 | 36 |
30 // A full SHA256 hash. | 37 // A full SHA256 hash. |
31 typedef HashPrefix FullHash; | 38 typedef HashPrefix FullHash; |
32 | 39 |
33 typedef FetchThreatListUpdatesRequest::ListUpdateRequest ListUpdateRequest; | 40 typedef FetchThreatListUpdatesRequest::ListUpdateRequest ListUpdateRequest; |
34 typedef FetchThreatListUpdatesResponse::ListUpdateResponse ListUpdateResponse; | 41 typedef FetchThreatListUpdatesResponse::ListUpdateResponse ListUpdateResponse; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // Given a URL, returns all the paths we need to check. | 217 // Given a URL, returns all the paths we need to check. |
211 static void GeneratePathsToCheck(const GURL& url, | 218 static void GeneratePathsToCheck(const GURL& url, |
212 std::vector<std::string>* paths); | 219 std::vector<std::string>* paths); |
213 | 220 |
214 static std::string RemoveConsecutiveChars(base::StringPiece str, | 221 static std::string RemoveConsecutiveChars(base::StringPiece str, |
215 const char c); | 222 const char c); |
216 | 223 |
217 DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil); | 224 DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil); |
218 }; | 225 }; |
219 | 226 |
227 typedef base::hash_set<PlatformType, EnumClassHash> PlatformTypeSet; | |
228 typedef base::hash_set<ThreatEntryType, EnumClassHash> ThreatEntryTypeSet; | |
229 typedef base::hash_set<ThreatType, EnumClassHash> ThreatTypeSet; | |
Scott Hess - ex-Googler
2016/08/23 20:25:46
These feel like more-expensive versions of std::bi
| |
230 | |
220 } // namespace safe_browsing | 231 } // namespace safe_browsing |
221 | 232 |
222 namespace std { | 233 namespace std { |
223 template <> | 234 template <> |
224 struct hash<safe_browsing::UpdateListIdentifier> { | 235 struct hash<safe_browsing::UpdateListIdentifier> { |
225 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { | 236 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { |
226 return s.hash(); | 237 return s.hash(); |
227 } | 238 } |
228 }; | 239 }; |
229 } | 240 } |
230 | 241 |
231 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ | 242 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |
OLD | NEW |