Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: components/safe_browsing_db/v4_protocol_manager_util.h

Issue 2057433002: Replace the old URL format for PVer4 requests with the new format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback: nparker. GetRequestUrlAndUpdateHeaders -> GetRequestUrlAndHeaders Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 14 #include "base/hash.h"
15 #include "components/safe_browsing_db/safebrowsing.pb.h" 15 #include "components/safe_browsing_db/safebrowsing.pb.h"
16 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace net {
20 class HttpRequestHeaders;
21 } // namespace net
22
19 namespace safe_browsing { 23 namespace safe_browsing {
20 // Config passed to the constructor of a V4 protocol manager. 24 // Config passed to the constructor of a V4 protocol manager.
21 struct V4ProtocolConfig { 25 struct V4ProtocolConfig {
22 // The safe browsing client name sent in each request. 26 // The safe browsing client name sent in each request.
23 std::string client_name; 27 std::string client_name;
24 28
25 // Current product version sent in each request. 29 // Current product version sent in each request.
26 std::string version; 30 std::string version;
27 31
28 // The Google API key. 32 // The Google API key.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 public: 90 public:
87 // Record HTTP response code when there's no error in fetching an HTTP 91 // Record HTTP response code when there's no error in fetching an HTTP
88 // request, and the error code, when there is. 92 // request, and the error code, when there is.
89 // |metric_name| is the name of the UMA metric to record the response code or 93 // |metric_name| is the name of the UMA metric to record the response code or
90 // error code against, |status| represents the status of the HTTP request, and 94 // error code against, |status| represents the status of the HTTP request, and
91 // |response code| represents the HTTP response code received from the server. 95 // |response code| represents the HTTP response code received from the server.
92 static void RecordHttpResponseOrErrorCode(const char* metric_name, 96 static void RecordHttpResponseOrErrorCode(const char* metric_name,
93 const net::URLRequestStatus& status, 97 const net::URLRequestStatus& status,
94 int response_code); 98 int response_code);
95 99
96 // Generates a Pver4 request URL. 100 // Generates a Pver4 request URL and sets the appropriate header values.
97 // |request_base64| is the serialized request protocol buffer encoded in 101 // |request_base64| is the serialized request protocol buffer encoded in
98 // base 64. 102 // base 64.
99 // |method_name| is the name of the method to call, as specified in the proto, 103 // |method_name| is the name of the method to call, as specified in the proto,
100 // |config| is an instance of V4ProtocolConfig that stores the client config. 104 // |config| is an instance of V4ProtocolConfig that stores the client config,
101 static GURL GetRequestUrl(const std::string& request_base64, 105 // |gurl| is set to the value of the PVer4 request URL,
102 const std::string& method_name, 106 // |headers| is populated with the appropriate header values.
103 const V4ProtocolConfig& config); 107 static void GetRequestUrlAndHeaders(const std::string& request_base64,
108 const std::string& method_name,
109 const V4ProtocolConfig& config,
110 GURL* gurl,
111 net::HttpRequestHeaders* headers);
104 112
105 // Worker function for calculating the backoff times. 113 // Worker function for calculating the backoff times.
106 // |multiplier| is doubled for each consecutive error after the 114 // |multiplier| is doubled for each consecutive error after the
107 // first, and |error_count| is incremented with each call. 115 // first, and |error_count| is incremented with each call.
108 static base::TimeDelta GetNextBackOffInterval(size_t* error_count, 116 static base::TimeDelta GetNextBackOffInterval(size_t* error_count,
109 size_t* multiplier); 117 size_t* multiplier);
110 118
111 private: 119 private:
112 V4ProtocolManagerUtil(){}; 120 V4ProtocolManagerUtil(){};
113 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, 121 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest,
114 TestBackOffLogic); 122 TestBackOffLogic);
115 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, 123 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest,
116 TestGetRequestUrl); 124 TestGetRequestUrlAndUpdateHeaders);
117 125
118 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes). 126 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes).
119 // |request_base64|, |client_id|, |version| and |key_param|. |prefix| 127 // |request_base64|, |client_id|, |version| and |key_param|. |prefix|
120 // should contain the entire url prefix including scheme, host and path. 128 // should contain the entire url prefix including scheme, host and path.
121 static std::string ComposeUrl(const std::string& prefix, 129 static std::string ComposeUrl(const std::string& prefix,
122 const std::string& method, 130 const std::string& method,
123 const std::string& request_base64, 131 const std::string& request_base64,
124 const std::string& client_id,
125 const std::string& version,
126 const std::string& key_param); 132 const std::string& key_param);
127 133
134 // Sets the HTTP headers expected by a standard PVer4 request.
135 static void UpdateHeaders(net::HttpRequestHeaders* headers);
136
128 DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil); 137 DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil);
129 }; 138 };
130 139
131 } // namespace safe_browsing 140 } // namespace safe_browsing
132 141
133 namespace std { 142 namespace std {
134 template <> 143 template <>
135 struct hash<safe_browsing::UpdateListIdentifier> { 144 struct hash<safe_browsing::UpdateListIdentifier> {
136 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { 145 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const {
137 return s.hash(); 146 return s.hash();
138 } 147 }
139 }; 148 };
140 } 149 }
141 150
142 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ 151 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_get_hash_protocol_manager.cc ('k') | components/safe_browsing_db/v4_protocol_manager_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698