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 |
| 11 #include <ostream> | |
| 11 #include <string> | 12 #include <string> |
| 12 | 13 |
| 13 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 14 #include "base/hash.h" | 15 #include "base/hash.h" |
| 15 #include "components/safe_browsing_db/safebrowsing.pb.h" | 16 #include "components/safe_browsing_db/safebrowsing.pb.h" |
| 16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 class HttpRequestHeaders; | 21 class HttpRequestHeaders; |
| 21 } // namespace net | 22 } // namespace net |
| 22 | 23 |
| 23 namespace safe_browsing { | 24 namespace safe_browsing { |
| 25 | |
| 26 typedef FetchThreatListUpdatesRequest::ListUpdateRequest ListUpdateRequest; | |
| 27 typedef FetchThreatListUpdatesResponse::ListUpdateResponse ListUpdateResponse; | |
| 28 | |
| 24 // Config passed to the constructor of a V4 protocol manager. | 29 // Config passed to the constructor of a V4 protocol manager. |
| 25 struct V4ProtocolConfig { | 30 struct V4ProtocolConfig { |
| 26 // The safe browsing client name sent in each request. | 31 // The safe browsing client name sent in each request. |
| 27 std::string client_name; | 32 std::string client_name; |
| 28 | 33 |
| 29 // Current product version sent in each request. | 34 // Current product version sent in each request. |
| 30 std::string version; | 35 std::string version; |
| 31 | 36 |
| 32 // The Google API key. | 37 // The Google API key. |
| 33 std::string key_param; | 38 std::string key_param; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 44 // interested in maintaining and downloading from the SafeBrowsing servers. | 49 // interested in maintaining and downloading from the SafeBrowsing servers. |
| 45 // For example, for digests of Malware binaries on Windows: | 50 // For example, for digests of Malware binaries on Windows: |
| 46 // platform_type = WINDOWS, | 51 // platform_type = WINDOWS, |
| 47 // threat_entry_type = EXECUTABLE, | 52 // threat_entry_type = EXECUTABLE, |
| 48 // threat_type = MALWARE | 53 // threat_type = MALWARE |
| 49 struct UpdateListIdentifier { | 54 struct UpdateListIdentifier { |
| 50 PlatformType platform_type; | 55 PlatformType platform_type; |
| 51 ThreatEntryType threat_entry_type; | 56 ThreatEntryType threat_entry_type; |
| 52 ThreatType threat_type; | 57 ThreatType threat_type; |
| 53 | 58 |
| 59 UpdateListIdentifier(); | |
| 60 UpdateListIdentifier(PlatformType, ThreatEntryType, ThreatType); | |
| 61 UpdateListIdentifier(const ListUpdateResponse&); | |
| 62 | |
| 54 bool operator==(const UpdateListIdentifier& other) const; | 63 bool operator==(const UpdateListIdentifier& other) const; |
| 55 bool operator!=(const UpdateListIdentifier& other) const; | 64 bool operator!=(const UpdateListIdentifier& other) const; |
| 56 size_t hash() const; | 65 size_t hash() const; |
| 57 }; | 66 }; |
| 58 | 67 |
| 68 std::ostream& operator<<(std::ostream& os, const UpdateListIdentifier& id); | |
| 69 | |
| 70 // This defines a hash_map that is used to create the backing files for the | |
| 71 // stores that contain the hash-prefixes. The map key identifies the list that | |
| 72 // we're interested in and the value represents the ASCII file-name that'll be | |
| 73 // created on-disk to store the hash-prefixes for that list. This file is | |
| 74 // created inside the user's profile directory. | |
|
Nathan Parker
2016/06/15 21:24:19
s/profile/data
The'll be one set of files shared
vakh (use Gerrit instead)
2016/06/16 01:07:35
Done.
| |
| 75 // For instance, the UpdateListIdentifier could be for URL expressions for UwS | |
|
Nathan Parker
2016/06/15 21:24:19
How about just referencing the place that defines
vakh (use Gerrit instead)
2016/06/16 01:07:35
There's no such place right now. The only place wh
| |
| 76 // on Windows platform, and the corresponding file on disk could be named: | |
| 77 // "uws_win_url.store" | |
| 78 typedef base::hash_map<UpdateListIdentifier, std::string> StoreFileNameMap; | |
| 79 | |
| 80 // Used to represent the state of each store. | |
| 81 typedef base::hash_map<UpdateListIdentifier, std::string> StoreStateMap; | |
| 82 | |
| 59 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE | 83 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE |
| 60 // ORDERING OF THESE VALUES. | 84 // ORDERING OF THESE VALUES. |
| 61 enum V4OperationResult { | 85 enum V4OperationResult { |
| 62 // 200 response code means that the server recognized the request. | 86 // 200 response code means that the server recognized the request. |
| 63 STATUS_200 = 0, | 87 STATUS_200 = 0, |
| 64 | 88 |
| 65 // Subset of successful responses where the response body wasn't parsable. | 89 // Subset of successful responses where the response body wasn't parsable. |
| 66 PARSE_ERROR = 1, | 90 PARSE_ERROR = 1, |
| 67 | 91 |
| 68 // Operation request failed (network error). | 92 // Operation request failed (network error). |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 98 int response_code); | 122 int response_code); |
| 99 | 123 |
| 100 // Generates a Pver4 request URL and sets the appropriate header values. | 124 // Generates a Pver4 request URL and sets the appropriate header values. |
| 101 // |request_base64| is the serialized request protocol buffer encoded in | 125 // |request_base64| is the serialized request protocol buffer encoded in |
| 102 // base 64. | 126 // base 64. |
| 103 // |method_name| is the name of the method to call, as specified in the proto, | 127 // |method_name| is the name of the method to call, as specified in the proto, |
| 104 // |config| is an instance of V4ProtocolConfig that stores the client config, | 128 // |config| is an instance of V4ProtocolConfig that stores the client config, |
| 105 // |gurl| is set to the value of the PVer4 request URL, | 129 // |gurl| is set to the value of the PVer4 request URL, |
| 106 // |headers| is populated with the appropriate header values. | 130 // |headers| is populated with the appropriate header values. |
| 107 static void GetRequestUrlAndHeaders(const std::string& request_base64, | 131 static void GetRequestUrlAndHeaders(const std::string& request_base64, |
| 108 const std::string& method_name, | 132 const std::string& method_name, |
| 109 const V4ProtocolConfig& config, | 133 const V4ProtocolConfig& config, |
| 110 GURL* gurl, | 134 GURL* gurl, |
| 111 net::HttpRequestHeaders* headers); | 135 net::HttpRequestHeaders* headers); |
| 112 | 136 |
| 113 // Worker function for calculating the backoff times. | 137 // Worker function for calculating the backoff times. |
| 114 // |multiplier| is doubled for each consecutive error after the | 138 // |multiplier| is doubled for each consecutive error after the |
| 115 // first, and |error_count| is incremented with each call. | 139 // first, and |error_count| is incremented with each call. |
| 116 static base::TimeDelta GetNextBackOffInterval(size_t* error_count, | 140 static base::TimeDelta GetNextBackOffInterval(size_t* error_count, |
| 117 size_t* multiplier); | 141 size_t* multiplier); |
| 118 | 142 |
| 119 private: | 143 private: |
| 120 V4ProtocolManagerUtil(){}; | 144 V4ProtocolManagerUtil(){}; |
| 121 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, | 145 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 142 namespace std { | 166 namespace std { |
| 143 template <> | 167 template <> |
| 144 struct hash<safe_browsing::UpdateListIdentifier> { | 168 struct hash<safe_browsing::UpdateListIdentifier> { |
| 145 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { | 169 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { |
| 146 return s.hash(); | 170 return s.hash(); |
| 147 } | 171 } |
| 148 }; | 172 }; |
| 149 } | 173 } |
| 150 | 174 |
| 151 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ | 175 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |
| OLD | NEW |