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

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

Issue 2062013002: Fetch incremental updates. Store new state in V4Store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits: Added some comments in BUILD.gn. Using #else for platform_type until I resolve the android bu… 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 <ostream>
11 #include <string> 12 #include <string>
12 13
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/hash.h" 15 #include "base/hash.h"
15 #include "components/safe_browsing_db/safebrowsing.pb.h" 16 #include "components/safe_browsing_db/safebrowsing.pb.h"
16 #include "net/url_request/url_request_status.h" 17 #include "net/url_request/url_request_status.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace net { 20 namespace net {
20 class HttpRequestHeaders; 21 class HttpRequestHeaders;
21 } // namespace net 22 } // namespace net
22 23
23 namespace safe_browsing { 24 namespace safe_browsing {
25
26 typedef FetchThreatListUpdatesRequest::ListUpdateRequest ListUpdateRequest;
27 typedef FetchThreatListUpdatesResponse::ListUpdateResponse ListUpdateResponse;
28
24 // Config passed to the constructor of a V4 protocol manager. 29 // Config passed to the constructor of a V4 protocol manager.
25 struct V4ProtocolConfig { 30 struct V4ProtocolConfig {
26 // The safe browsing client name sent in each request. 31 // The safe browsing client name sent in each request.
27 std::string client_name; 32 std::string client_name;
28 33
29 // Current product version sent in each request. 34 // Current product version sent in each request.
30 std::string version; 35 std::string version;
31 36
32 // The Google API key. 37 // The Google API key.
33 std::string key_param; 38 std::string key_param;
(...skipping 10 matching lines...) Expand all
44 // interested in maintaining and downloading from the SafeBrowsing servers. 49 // interested in maintaining and downloading from the SafeBrowsing servers.
45 // For example, for digests of Malware binaries on Windows: 50 // For example, for digests of Malware binaries on Windows:
46 // platform_type = WINDOWS, 51 // platform_type = WINDOWS,
47 // threat_entry_type = EXECUTABLE, 52 // threat_entry_type = EXECUTABLE,
48 // threat_type = MALWARE 53 // threat_type = MALWARE
49 struct UpdateListIdentifier { 54 struct UpdateListIdentifier {
50 PlatformType platform_type; 55 PlatformType platform_type;
51 ThreatEntryType threat_entry_type; 56 ThreatEntryType threat_entry_type;
52 ThreatType threat_type; 57 ThreatType threat_type;
53 58
59 UpdateListIdentifier();
60 UpdateListIdentifier(PlatformType, ThreatEntryType, ThreatType);
61 UpdateListIdentifier(const ListUpdateResponse&);
62
54 bool operator==(const UpdateListIdentifier& other) const; 63 bool operator==(const UpdateListIdentifier& other) const;
55 bool operator!=(const UpdateListIdentifier& other) const; 64 bool operator!=(const UpdateListIdentifier& other) const;
56 size_t hash() const; 65 size_t hash() const;
57 }; 66 };
58 67
68 std::ostream& operator<<(std::ostream& os, const UpdateListIdentifier& id);
69
70 // This defines a hash_map that is used to create the backing files for the
71 // stores that contain the hash-prefixes. The map key identifies the list that
72 // we're interested in and the value represents the ASCII file-name that'll be
73 // created on-disk to store the hash-prefixes for that list. This file is
74 // created inside the user's data directory.
Scott Hess - ex-Googler 2016/06/17 22:53:43 This comment replicates a lot of specifics from th
vakh (use Gerrit instead) 2016/06/20 22:28:43 Done.
75 // For instance, the UpdateListIdentifier could be for URL expressions for UwS
76 // on Windows platform, and the corresponding file on disk could be named:
77 // "uws_win_url.store"
78 // TODO(vakh): Find the canonical place where these are defined and update the
79 // comment to point to that place.
80 typedef base::hash_map<UpdateListIdentifier, std::string> StoreFileNameMap;
81
82 // Used to represent the state of each store.
Scott Hess - ex-Googler 2016/06/17 22:53:43 Similar here, language could be less passive. "Re
vakh (use Gerrit instead) 2016/06/20 22:28:43 Done.
83 typedef base::hash_map<UpdateListIdentifier, std::string> StoreStateMap;
84
59 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE 85 // Enumerate failures for histogramming purposes. DO NOT CHANGE THE
60 // ORDERING OF THESE VALUES. 86 // ORDERING OF THESE VALUES.
61 enum V4OperationResult { 87 enum V4OperationResult {
62 // 200 response code means that the server recognized the request. 88 // 200 response code means that the server recognized the request.
63 STATUS_200 = 0, 89 STATUS_200 = 0,
64 90
65 // Subset of successful responses where the response body wasn't parsable. 91 // Subset of successful responses where the response body wasn't parsable.
66 PARSE_ERROR = 1, 92 PARSE_ERROR = 1,
67 93
68 // Operation request failed (network error). 94 // Operation request failed (network error).
(...skipping 29 matching lines...) Expand all
98 int response_code); 124 int response_code);
99 125
100 // Generates a Pver4 request URL and sets the appropriate header values. 126 // Generates a Pver4 request URL and sets the appropriate header values.
101 // |request_base64| is the serialized request protocol buffer encoded in 127 // |request_base64| is the serialized request protocol buffer encoded in
102 // base 64. 128 // base 64.
103 // |method_name| is the name of the method to call, as specified in the proto, 129 // |method_name| is the name of the method to call, as specified in the proto,
104 // |config| is an instance of V4ProtocolConfig that stores the client config, 130 // |config| is an instance of V4ProtocolConfig that stores the client config,
105 // |gurl| is set to the value of the PVer4 request URL, 131 // |gurl| is set to the value of the PVer4 request URL,
106 // |headers| is populated with the appropriate header values. 132 // |headers| is populated with the appropriate header values.
107 static void GetRequestUrlAndHeaders(const std::string& request_base64, 133 static void GetRequestUrlAndHeaders(const std::string& request_base64,
108 const std::string& method_name, 134 const std::string& method_name,
109 const V4ProtocolConfig& config, 135 const V4ProtocolConfig& config,
110 GURL* gurl, 136 GURL* gurl,
111 net::HttpRequestHeaders* headers); 137 net::HttpRequestHeaders* headers);
112 138
113 // Worker function for calculating the backoff times. 139 // Worker function for calculating the backoff times.
114 // |multiplier| is doubled for each consecutive error after the 140 // |multiplier| is doubled for each consecutive error after the
115 // first, and |error_count| is incremented with each call. 141 // first, and |error_count| is incremented with each call.
116 static base::TimeDelta GetNextBackOffInterval(size_t* error_count, 142 static base::TimeDelta GetNextBackOffInterval(size_t* error_count,
117 size_t* multiplier); 143 size_t* multiplier);
118 144
119 private: 145 private:
120 V4ProtocolManagerUtil(){}; 146 V4ProtocolManagerUtil(){};
121 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest, 147 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingV4ProtocolManagerUtilTest,
(...skipping 20 matching lines...) Expand all
142 namespace std { 168 namespace std {
143 template <> 169 template <>
144 struct hash<safe_browsing::UpdateListIdentifier> { 170 struct hash<safe_browsing::UpdateListIdentifier> {
145 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const { 171 std::size_t operator()(const safe_browsing::UpdateListIdentifier& s) const {
146 return s.hash(); 172 return s.hash();
147 } 173 }
148 }; 174 };
149 } 175 }
150 176
151 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_ 177 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_PROTOCOL_MANAGER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698