| 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 <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/hash.h" | 14 #include "base/hash.h" |
| 15 #include "components/safe_browsing_db/safebrowsing.pb.h" | 15 #include "components/safe_browsing_db/safebrowsing.pb.h" |
| 16 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 namespace safe_browsing { | 19 namespace safe_browsing { |
| 20 // Config passed to the constructor of a V4 protocol manager. | 20 // Config passed to the constructor of a V4 protocol manager. |
| 21 struct V4ProtocolConfig { | 21 struct V4ProtocolConfig { |
| 22 // The safe browsing client name sent in each request. | 22 // The safe browsing client name sent in each request. |
| 23 std::string client_name; | 23 std::string client_name; |
| 24 | 24 |
| 25 // Current product version sent in each request. | 25 // Current product version sent in each request. |
| 26 std::string version; | 26 std::string version; |
| 27 | 27 |
| 28 // The Google API key. | 28 // The Google API key. |
| 29 std::string key_param; | 29 std::string key_param; |
| 30 |
| 31 // Disable auto-updates using a command line switch? |
| 32 bool disable_auto_update; |
| 33 |
| 34 V4ProtocolConfig(); |
| 35 ~V4ProtocolConfig(); |
| 30 }; | 36 }; |
| 31 | 37 |
| 32 // The information required to uniquely identify each list the client is | 38 // The information required to uniquely identify each list the client is |
| 33 // interested in maintaining and downloading from the SafeBrowsing servers. | 39 // interested in maintaining and downloading from the SafeBrowsing servers. |
| 34 // For example, for digests of Malware binaries on Windows: | 40 // For example, for digests of Malware binaries on Windows: |
| 35 // platform_type = WINDOWS, | 41 // platform_type = WINDOWS, |
| 36 // threat_entry_type = BINARY_DIGEST, | 42 // threat_entry_type = BINARY_DIGEST, |
| 37 // threat_type = MALWARE | 43 // threat_type = MALWARE |
| 38 struct UpdateListIdentifier { | 44 struct UpdateListIdentifier { |
| 39 PlatformType platform_type; | 45 PlatformType platform_type; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 const std::string& method_name, | 101 const std::string& method_name, |
| 96 const V4ProtocolConfig& config); | 102 const V4ProtocolConfig& config); |
| 97 | 103 |
| 98 // Worker function for calculating the backoff times. | 104 // Worker function for calculating the backoff times. |
| 99 // |multiplier| is doubled for each consecutive error after the | 105 // |multiplier| is doubled for each consecutive error after the |
| 100 // first, and |error_count| is incremented with each call. | 106 // first, and |error_count| is incremented with each call. |
| 101 static base::TimeDelta GetNextBackOffInterval(size_t* error_count, | 107 static base::TimeDelta GetNextBackOffInterval(size_t* error_count, |
| 102 size_t* multiplier); | 108 size_t* multiplier); |
| 103 | 109 |
| 104 private: | 110 private: |
| 105 V4ProtocolManagerUtil() {}; | 111 V4ProtocolManagerUtil(){}; |
| 106 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, | 112 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, |
| 107 TestBackOffLogic); | 113 TestBackOffLogic); |
| 108 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, | 114 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, |
| 109 TestGetRequestUrl); | 115 TestGetRequestUrl); |
| 110 | 116 |
| 111 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes). | 117 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes). |
| 112 // |request_base64|, |client_id|, |version| and |key_param|. |prefix| | 118 // |request_base64|, |client_id|, |version| and |key_param|. |prefix| |
| 113 // should contain the entire url prefix including scheme, host and path. | 119 // should contain the entire url prefix including scheme, host and path. |
| 114 static std::string ComposeUrl(const std::string& prefix, | 120 static std::string ComposeUrl(const std::string& prefix, |
| 115 const std::string& method, | 121 const std::string& method, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 126 namespace std { | 132 namespace std { |
| 127 template <> | 133 template <> |
| 128 struct hash<safe_browsing::UpdateListIdentifier> { | 134 struct hash<safe_browsing::UpdateListIdentifier> { |
| 129 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { | 135 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { |
| 130 return s.hash(); | 136 return s.hash(); |
| 131 } | 137 } |
| 132 }; | 138 }; |
| 133 } | 139 } |
| 134 | 140 |
| 135 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ | 141 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |
| OLD | NEW |