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