Chromium Code Reviews| Index: components/safe_browsing_db/v4_protocol_manager_util.h |
| diff --git a/components/safe_browsing_db/v4_protocol_manager_util.h b/components/safe_browsing_db/v4_protocol_manager_util.h |
| index f4665f00587fc979ddbab8bb19c4530b87cd4287..1bee75f281e1f30df4bf6d5697b5f7551aff86ca 100644 |
| --- a/components/safe_browsing_db/v4_protocol_manager_util.h |
| +++ b/components/safe_browsing_db/v4_protocol_manager_util.h |
| @@ -11,11 +11,12 @@ |
| #include <string> |
| #include "base/gtest_prod_util.h" |
| +#include "base/hash.h" |
| +#include "components/safe_browsing_db/safebrowsing.pb.h" |
| #include "net/url_request/url_request_status.h" |
| #include "url/gurl.h" |
| namespace safe_browsing { |
| - |
| // Config passed to the constructor of a V4 protocol manager. |
| struct V4ProtocolConfig { |
| // The safe browsing client name sent in each request. |
| @@ -28,6 +29,67 @@ struct V4ProtocolConfig { |
| std::string key_param; |
| }; |
| +// The information required to uniquely identify each list the client is |
| +// interested in maintaining and downloading from the SafeBrowsing servers. |
| +// For example, for digests of Malware binaries on Windows: |
| +// platform_type = WINDOWS, |
| +// threat_entry_type = BINARY_DIGEST, |
| +// threat_type = MALWARE |
| +struct UpdateListIdentifier { |
| + PlatformType platform_type; |
| + ThreatEntryType threat_entry_type; |
| + ThreatType threat_type; |
| + |
| + bool operator==(const UpdateListIdentifier& other) const { |
| + return platform_type == other.platform_type && |
|
Nathan Parker
2016/03/25 23:51:01
The body of these should probably go in a .cc file
vakh (use Gerrit instead)
2016/03/26 00:06:56
Done.
|
| + threat_entry_type == other.threat_entry_type && |
| + threat_type == other.threat_type; |
| + } |
| + |
| + bool operator!=(const UpdateListIdentifier& other) const { |
| + return !operator==(other); |
| + } |
| + |
| + size_t hash() const { |
| + std::size_t first = std::hash<unsigned int>()(platform_type); |
| + std::size_t second = std::hash<unsigned int>()(threat_entry_type); |
| + std::size_t third = std::hash<unsigned int>()(threat_type); |
| + |
| + std::size_t interim = base::HashInts(first, second); |
| + return base::HashInts(interim, third); |
| + } |
| +}; |
| + |
| +// Enumerate failures for histogramming purposes. DO NOT CHANGE THE |
| +// ORDERING OF THESE VALUES. |
| +enum V4OperationResult { |
| + // 200 response code means that the server recognized the request. |
| + STATUS_200 = 0, |
| + |
| + // Subset of successful responses where the response body wasn't parsable. |
| + PARSE_ERROR = 1, |
| + |
| + // Operation request failed (network error). |
| + NETWORK_ERROR = 2, |
| + |
| + // Operation request returned HTTP result code other than 200. |
| + HTTP_ERROR = 3, |
| + |
| + // Operation attempted during error backoff, no request sent. |
| + BACKOFF_ERROR = 4, |
| + |
| + // Operation attempted before min wait duration elapsed, no request sent. |
| + MIN_WAIT_DURATION_ERROR = 5, |
| + |
| + // Identical operation already pending. |
| + ALREADY_PENDING_ERROR = 6, |
| + |
| + // Memory space for histograms is determined by the max. ALWAYS |
| + // ADD NEW VALUES BEFORE THIS ONE. |
| + OPERATION_RESULT_MAX = 7 |
| +}; |
| + |
| +// A class that provides static methods related to the Pver4 protocol. |
| class V4ProtocolManagerUtil { |
| public: |
| // Record HTTP response code when there's no error in fetching an HTTP |
| @@ -76,4 +138,13 @@ class V4ProtocolManagerUtil { |
| } // namespace safe_browsing |
| +namespace std { |
| +template <> |
| +struct hash<safe_browsing::UpdateListIdentifier> { |
| + std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { |
|
Nathan Parker
2016/03/25 23:51:01
Cool! I'm glad you figured out how to do this. I'
vakh (use Gerrit instead)
2016/03/26 00:06:56
Acknowledged.
|
| + return s.hash(); |
| + } |
| +}; |
| +} |
| + |
| #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ |