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

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

Issue 1703413002: Move common PVer4 code into a V4ProtocolManagerUtil class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass config as pointer, instead of reference Created 4 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
7
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.
10
11 #include <string>
12
13 #include "base/gtest_prod_util.h"
14 #include "net/url_request/url_request_status.h"
15 #include "url/gurl.h"
16
17 namespace safe_browsing {
18
19 // Config passed to the constructor of a V4 protocol manager.
20 struct V4ProtocolConfig {
21 // The safe browsing client name sent in each request.
22 std::string client_name;
23
24 // Current product version sent in each request.
25 std::string version;
26
27 // The Google API key.
28 std::string key_param;
29 };
30
31 class V4ProtocolManagerUtil {
32 public:
33 // Record HTTP response code when there's no error in fetching an HTTP
34 // request, and the error code, when there is.
35 // |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
37 // |response code| represents the HTTP response code received from the server.
38 static void RecordHttpResponseOrErrorCode(const char* metric_name,
39 const net::URLRequestStatus& status,
40 int response_code);
41
42 // Generates a Pver4 request URL.
43 // |request_base64| is the serialized request protocol buffer encoded in
44 // base 64.
45 // |method_name| is the name of the method to call, as specified in the proto,
46 // |config| is an instance of V4ProtocolConfig that stores the client config.
47 static GURL GetRequestUrl(const std::string& request_base64,
48 const std::string& method_name,
49 const V4ProtocolConfig& config);
50
51 // Worker function for calculating the backoff times.
52 // |multiplier| is doubled for each consecutive error after the
53 // first, and |error_count| is incremented with each call.
54 static base::TimeDelta GetNextBackOffInterval(size_t* error_count,
55 size_t* multiplier);
56
57 private:
58 V4ProtocolManagerUtil() {};
59 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest,
60 TestBackOffLogic);
61 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest,
62 TestGetRequestUrl);
63
64 // Composes a URL using |prefix|, |method| (e.g.: encodedFullHashes).
65 // |request_base64|, |client_id|, |version| and |key_param|. |prefix|
66 // should contain the entire url prefix including scheme, host and path.
67 static std::string ComposeUrl(const std::string& prefix,
68 const std::string& method,
69 const std::string& request_base64,
70 const std::string& client_id,
71 const std::string& version,
72 const std::string& key_param);
73
74 DISALLOW_COPY_AND_ASSIGN(V4ProtocolManagerUtil);
75 };
76
77 } // namespace safe_browsing
78
79 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698