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 6b81e8b5c0bf5703aded8ee36d5e1c0bb47b20a3..f49c623b6b5aafece3404c9009319b2104f59475 100644 |
| --- a/components/safe_browsing_db/v4_protocol_manager_util.h |
| +++ b/components/safe_browsing_db/v4_protocol_manager_util.h |
| @@ -13,6 +13,7 @@ |
| #include "base/gtest_prod_util.h" |
| #include "base/hash.h" |
| +#include "base/strings/string_piece.h" |
| #include "components/safe_browsing_db/safebrowsing.pb.h" |
| #include "net/url_request/url_request_status.h" |
| #include "url/gurl.h" |
| @@ -23,6 +24,19 @@ class HttpRequestHeaders; |
| namespace safe_browsing { |
| +// The size of the hash prefix, in bytes. It should be between 4 to 32 (full |
| +// hash). |
| +typedef size_t PrefixSize; |
| + |
| +// A hash prefix sent by the SafeBrowsing PVer4 service. |
| +typedef std::string HashPrefix; |
| + |
| +// The sorted list of hash prefixes. |
|
Nathan Parker
2016/08/05 18:07:39
Is this needed by anything other than the v4LocalD
vakh (use Gerrit instead)
2016/08/05 18:25:48
Currently it is being used by the Store only.
I mo
|
| +typedef std::string HashPrefixes; |
| + |
| +// A full SHA256 hash. |
| +typedef HashPrefix FullHash; |
| + |
| typedef FetchThreatListUpdatesRequest::ListUpdateRequest ListUpdateRequest; |
| typedef FetchThreatListUpdatesResponse::ListUpdateResponse ListUpdateResponse; |
| @@ -70,6 +84,26 @@ struct UpdateListIdentifier { |
| std::ostream& operator<<(std::ostream& os, const UpdateListIdentifier& id); |
| +#if defined(OS_WIN) |
| +#define PLATFORM_TYPE WINDOWS_PLATFORM |
| +#elif defined(OS_LINUX) |
| +#define PLATFORM_TYPE LINUX_PLATFORM |
| +#elif defined(OS_MACOSX) |
| +#define PLATFORM_TYPE OSX_PLATFORM |
| +#else |
| +// This should ideally never compile but it is getting compiled on Android. |
| +// See: https://bugs.chromium.org/p/chromium/issues/detail?id=621647 |
| +// TODO(vakh): Once that bug is fixed, this should be removed. If we leave |
| +// the platform_type empty, the server won't recognize the request and |
| +// return an error response which will pollute our UMA metrics. |
| +#define PLATFORM_TYPE LINUX_PLATFORM |
| +#endif |
| + |
| +const UpdateListIdentifier kUrlMalware(PLATFORM_TYPE, URL, MALWARE_THREAT); |
|
Nathan Parker
2016/08/05 18:07:39
nit: The names could include "Id" or "ListId", so
vakh (use Gerrit instead)
2016/08/05 18:25:48
Done.
|
| +const UpdateListIdentifier kUrlSoceng(PLATFORM_TYPE, |
| + URL, |
| + SOCIAL_ENGINEERING_PUBLIC); |
| + |
| // The set of interesting lists and ASCII filenames for their hash prefix |
| // stores. The stores are created inside the user-data directory. |
| // For instance, the UpdateListIdentifier could be for URL expressions for UwS |
| @@ -117,14 +151,25 @@ enum V4OperationResult { |
| // 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 |
| - // request, and the error code, when there is. |
| - // |metric_name| is the name of the UMA metric to record the response code or |
| - // error code against, |status| represents the status of the HTTP request, and |
| - // |response code| represents the HTTP response code received from the server. |
| - static void RecordHttpResponseOrErrorCode(const char* metric_name, |
| - const net::URLRequestStatus& status, |
| - int response_code); |
| + // Canonicalizes url as per Google Safe Browsing Specification. |
| + // See: https://developers.google.com/safe-browsing/v4/urls-hashing |
| + static void CanonicalizeUrl(const GURL& url, |
| + std::string* canonicalized_hostname, |
| + std::string* canonicalized_path, |
| + std::string* canonicalized_query); |
| + |
| + // This method returns the host suffix combinations from the hostname in the |
| + // URL, as described here: |
| + // https://developers.google.com/safe-browsing/v4/urls-hashing |
| + static void GenerateHostVariantsToCheck(const std::string& host, |
| + std::vector<std::string>* hosts); |
| + |
| + // This method returns the path prefix combinations from the path in the |
| + // URL, as described here: |
| + // https://developers.google.com/safe-browsing/v4/urls-hashing |
| + static void GeneratePathVariantsToCheck(const std::string& path, |
| + const std::string& query, |
| + std::vector<std::string>* paths); |
| // Generates a Pver4 request URL and sets the appropriate header values. |
| // |request_base64| is the serialized request protocol buffer encoded in |
| @@ -145,12 +190,26 @@ class V4ProtocolManagerUtil { |
| static base::TimeDelta GetNextBackOffInterval(size_t* error_count, |
| size_t* multiplier); |
| + // Record HTTP response code when there's no error in fetching an HTTP |
| + // request, and the error code, when there is. |
| + // |metric_name| is the name of the UMA metric to record the response code or |
| + // error code against, |status| represents the status of the HTTP request, and |
| + // |response code| represents the HTTP response code received from the server. |
| + static void RecordHttpResponseOrErrorCode(const char* metric_name, |
|
Nathan Parker
2016/08/05 18:07:39
Is this specific to the V4ProtocolManager? Maybe t
vakh (use Gerrit instead)
2016/08/05 18:25:48
It records the information about the response rece
|
| + const net::URLRequestStatus& status, |
| + int response_code); |
| + |
| + // Generate the set of FullHashes to check for |url|. |
| + static void UrlToFullHashes(const GURL& url, |
| + base::hash_set<FullHash>* full_hashes); |
| + |
| private: |
| V4ProtocolManagerUtil(){}; |
| - FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, |
| - TestBackOffLogic); |
| - FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, |
| + FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, TestBackOffLogic); |
| + FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, |
| TestGetRequestUrlAndUpdateHeaders); |
| + FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, UrlParsing); |
| + FRIEND_TEST_ALL_PREFIXES(V4ProtocolManagerUtilTest, CanonicalizeUrl); |
| // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes). |
| // |request_base64|, |client_id|, |version| and |key_param|. |prefix| |
| @@ -163,6 +222,22 @@ class V4ProtocolManagerUtil { |
| // Sets the HTTP headers expected by a standard PVer4 request. |
| static void UpdateHeaders(net::HttpRequestHeaders* headers); |
| + // Given a URL, returns all the hosts we need to check. They are returned |
| + // in order of size (i.e. b.c is first, then a.b.c). |
| + static void GenerateHostsToCheck(const GURL& url, |
| + std::vector<std::string>* hosts); |
| + |
| + // Given a URL, returns all the paths we need to check. |
| + static void GeneratePathsToCheck(const GURL& url, |
| + std::vector<std::string>* paths); |
| + |
| + // Given a URL, returns all the patterns we need to check. |
| + static void GeneratePatternsToCheck(const GURL& url, |
| + std::vector<std::string>* urls); |
| + |
| + static std::string RemoveConsecutiveChars(base::StringPiece str, |
| + const char c); |
| + |
| DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil); |
| }; |