Chromium Code Reviews| 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 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 186 |
| 187 // Identical operation already pending. | 187 // Identical operation already pending. |
| 188 ALREADY_PENDING_ERROR = 6, | 188 ALREADY_PENDING_ERROR = 6, |
| 189 | 189 |
| 190 // Memory space for histograms is determined by the max. ALWAYS | 190 // Memory space for histograms is determined by the max. ALWAYS |
| 191 // ADD NEW VALUES BEFORE THIS ONE. | 191 // ADD NEW VALUES BEFORE THIS ONE. |
| 192 OPERATION_RESULT_MAX = 7 | 192 OPERATION_RESULT_MAX = 7 |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 // A class that provides static methods related to the Pver4 protocol. | 195 // A class that provides static methods related to the Pver4 protocol. |
| 196 // TODO(vakh): Consider making this class a namespace instead. | |
| 197 // TODO(vakh): Re-order the methods in alphabetical order. | |
| 196 class V4ProtocolManagerUtil { | 198 class V4ProtocolManagerUtil { |
| 197 public: | 199 public: |
| 198 // Canonicalizes url as per Google Safe Browsing Specification. | 200 // Canonicalizes url as per Google Safe Browsing Specification. |
| 199 // See: https://developers.google.com/safe-browsing/v4/urls-hashing | 201 // See: https://developers.google.com/safe-browsing/v4/urls-hashing |
| 200 static void CanonicalizeUrl(const GURL& url, | 202 static void CanonicalizeUrl(const GURL& url, |
| 201 std::string* canonicalized_hostname, | 203 std::string* canonicalized_hostname, |
| 202 std::string* canonicalized_path, | 204 std::string* canonicalized_path, |
| 203 std::string* canonicalized_query); | 205 std::string* canonicalized_query); |
| 204 | 206 |
| 205 // This method returns the host suffix combinations from the hostname in the | 207 // This method returns the host suffix combinations from the hostname in the |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 | 259 |
| 258 static bool FullHashToSmallestHashPrefix(const FullHash& full_hash, | 260 static bool FullHashToSmallestHashPrefix(const FullHash& full_hash, |
| 259 HashPrefix* hash_prefix); | 261 HashPrefix* hash_prefix); |
| 260 | 262 |
| 261 static bool FullHashMatchesHashPrefix(const FullHash& full_hash, | 263 static bool FullHashMatchesHashPrefix(const FullHash& full_hash, |
| 262 const HashPrefix& hash_prefix); | 264 const HashPrefix& hash_prefix); |
| 263 | 265 |
| 264 static void SetClientInfoFromConfig(ClientInfo* client_info, | 266 static void SetClientInfoFromConfig(ClientInfo* client_info, |
| 265 const V4ProtocolConfig& config); | 267 const V4ProtocolConfig& config); |
| 266 | 268 |
| 269 // Returns the size of the file at |file_path|, or 0 if there's an error. | |
| 270 static int64_t GetFileSizeOrZero(const base::FilePath& file_path); | |
|
Nathan Parker
2016/10/24 20:33:54
Are you using this in v4? If not, why move it?
vakh (use Gerrit instead)
2016/10/24 22:04:50
I was. Then shess@ pointed out that I don't need t
| |
| 271 | |
| 267 private: | 272 private: |
| 268 V4ProtocolManagerUtil(){}; | 273 V4ProtocolManagerUtil(){}; |
| 269 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, TestBackOffLogic); | 274 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, TestBackOffLogic); |
| 270 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, | 275 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, |
| 271 TestGetRequestUrlAndUpdateHeaders); | 276 TestGetRequestUrlAndUpdateHeaders); |
| 272 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, UrlParsing); | 277 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, UrlParsing); |
| 273 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, CanonicalizeUrl); | 278 FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, CanonicalizeUrl); |
| 274 | 279 |
| 275 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes). | 280 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes). |
| 276 // |request_base64|, |client_id|, |version| and |key_param|. |prefix| | 281 // |request_base64|, |client_id|, |version| and |key_param|. |prefix| |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 | 331 |
| 327 template <> | 332 template <> |
| 328 struct hash<safe_browsing::ListIdentifier> { | 333 struct hash<safe_browsing::ListIdentifier> { |
| 329 std::size_t operator()(const safe_browsing::ListIdentifier& id) const { | 334 std::size_t operator()(const safe_browsing::ListIdentifier& id) const { |
| 330 return id.hash(); | 335 return id.hash(); |
| 331 } | 336 } |
| 332 }; | 337 }; |
| 333 } | 338 } |
| 334 | 339 |
| 335 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ | 340 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |
| OLD | NEW |