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" |
| 15 #include "components/safe_browsing_db/safebrowsing.pb.h" |
14 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
16 | 18 |
17 namespace safe_browsing { | 19 namespace safe_browsing { |
18 | |
19 // Config passed to the constructor of a V4 protocol manager. | 20 // Config passed to the constructor of a V4 protocol manager. |
20 struct V4ProtocolConfig { | 21 struct V4ProtocolConfig { |
21 // The safe browsing client name sent in each request. | 22 // The safe browsing client name sent in each request. |
22 std::string client_name; | 23 std::string client_name; |
23 | 24 |
24 // Current product version sent in each request. | 25 // Current product version sent in each request. |
25 std::string version; | 26 std::string version; |
26 | 27 |
27 // The Google API key. | 28 // The Google API key. |
28 std::string key_param; | 29 std::string key_param; |
29 }; | 30 }; |
30 | 31 |
| 32 // The information required to uniquely identify each list the client is |
| 33 // interested in maintaining and downloading from the SafeBrowsing servers. |
| 34 // For example, for digests of Malware binaries on Windows: |
| 35 // platform_type = WINDOWS, |
| 36 // threat_entry_type = BINARY_DIGEST, |
| 37 // threat_type = MALWARE |
| 38 struct UpdateListIdentifier { |
| 39 PlatformType platform_type; |
| 40 ThreatEntryType threat_entry_type; |
| 41 ThreatType threat_type; |
| 42 |
| 43 bool operator==(const UpdateListIdentifier& other) const; |
| 44 bool operator!=(const UpdateListIdentifier& other) const; |
| 45 size_t hash() const; |
| 46 }; |
| 47 |
| 48 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE |
| 49 // ORDERING OF THESE VALUES. |
| 50 enum V4OperationResult { |
| 51 // 200 response code means that the server recognized the request. |
| 52 STATUS_200 = 0, |
| 53 |
| 54 // Subset of successful responses where the response body wasn't parsable. |
| 55 PARSE_ERROR = 1, |
| 56 |
| 57 // Operation request failed (network error). |
| 58 NETWORK_ERROR = 2, |
| 59 |
| 60 // Operation request returned HTTP result code other than 200. |
| 61 HTTP_ERROR = 3, |
| 62 |
| 63 // Operation attempted during error backoff, no request sent. |
| 64 BACKOFF_ERROR = 4, |
| 65 |
| 66 // Operation attempted before min wait duration elapsed, no request sent. |
| 67 MIN_WAIT_DURATION_ERROR = 5, |
| 68 |
| 69 // Identical operation already pending. |
| 70 ALREADY_PENDING_ERROR = 6, |
| 71 |
| 72 // Memory space for histograms is determined by the max. ALWAYS |
| 73 // ADD NEW VALUES BEFORE THIS ONE. |
| 74 OPERATION_RESULT_MAX = 7 |
| 75 }; |
| 76 |
| 77 // A class that provides static methods related to the Pver4 protocol. |
31 class V4ProtocolManagerUtil { | 78 class V4ProtocolManagerUtil { |
32 public: | 79 public: |
33 // Record HTTP response code when there's no error in fetching an HTTP | 80 // Record HTTP response code when there's no error in fetching an HTTP |
34 // request, and the error code, when there is. | 81 // request, and the error code, when there is. |
35 // |metric_name| is the name of the UMA metric to record the response code or | 82 // |metric_name| is the name of the UMA metric to record the response code or |
36 // error code against, |status| represents the status of the HTTP request, and | 83 // error code against, |status| represents the status of the HTTP request, and |
37 // |response code| represents the HTTP response code received from the server. | 84 // |response code| represents the HTTP response code received from the server. |
38 static void RecordHttpResponseOrErrorCode(const char* metric_name, | 85 static void RecordHttpResponseOrErrorCode(const char* metric_name, |
39 const net::URLRequestStatus& status, | 86 const net::URLRequestStatus& status, |
40 int response_code); | 87 int response_code); |
(...skipping 28 matching lines...) Expand all Loading... |
69 const std::string& request_base64, | 116 const std::string& request_base64, |
70 const std::string& client_id, | 117 const std::string& client_id, |
71 const std::string& version, | 118 const std::string& version, |
72 const std::string& key_param); | 119 const std::string& key_param); |
73 | 120 |
74 DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil); | 121 DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil); |
75 }; | 122 }; |
76 | 123 |
77 } // namespace safe_browsing | 124 } // namespace safe_browsing |
78 | 125 |
| 126 namespace std { |
| 127 template <> |
| 128 struct hash<safe_browsing::UpdateListIdentifier> { |
| 129 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { |
| 130 return s.hash(); |
| 131 } |
| 132 }; |
| 133 } |
| 134 |
79 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ | 135 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |
OLD | NEW |