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

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

Issue 2647323009: Add extended reporting level in the update request (Closed)
Patch Set: rebase Created 3 years, 11 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_UPDATE_PROTOCOL_MANAGER_H_ 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_
7 7
8 // A class that implements Chrome's interface with the SafeBrowsing V4 update 8 // A class that implements Chrome's interface with the SafeBrowsing V4 update
9 // protocol. 9 // protocol.
10 // 10 //
11 // The V4UpdateProtocolManager handles formatting and making requests of, and 11 // The V4UpdateProtocolManager handles formatting and making requests of, and
12 // handling responses from, Google's SafeBrowsing servers. The purpose of this 12 // handling responses from, Google's SafeBrowsing servers. The purpose of this
13 // class is to get hash prefixes from the SB server for the given set of lists. 13 // class is to get hash prefixes from the SB server for the given set of lists.
14 14
15 #include <memory> 15 #include <memory>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/gtest_prod_util.h" 19 #include "base/gtest_prod_util.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/threading/non_thread_safe.h" 21 #include "base/threading/non_thread_safe.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "base/timer/timer.h" 23 #include "base/timer/timer.h"
24 #include "components/safe_browsing_db/safe_browsing_prefs.h"
24 #include "components/safe_browsing_db/safebrowsing.pb.h" 25 #include "components/safe_browsing_db/safebrowsing.pb.h"
25 #include "components/safe_browsing_db/util.h" 26 #include "components/safe_browsing_db/util.h"
26 #include "components/safe_browsing_db/v4_protocol_manager_util.h" 27 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
27 #include "net/url_request/url_fetcher_delegate.h" 28 #include "net/url_request/url_fetcher_delegate.h"
28 29
29 class GURL; 30 class GURL;
30 31
31 namespace net { 32 namespace net {
32 class URLFetcher; 33 class URLFetcher;
33 class URLRequestContextGetter; 34 class URLRequestContextGetter;
34 } // namespace net 35 } // namespace net
35 36
36 namespace safe_browsing { 37 namespace safe_browsing {
37 38
38 class V4UpdateProtocolManagerFactory; 39 class V4UpdateProtocolManagerFactory;
39 40
40 // V4UpdateCallback is invoked when a scheduled update completes. 41 // V4UpdateCallback is invoked when a scheduled update completes.
41 // Parameters: 42 // Parameters:
42 // - The vector of update response protobufs received from the server for 43 // - The vector of update response protobufs received from the server for
43 // each list type. 44 // each list type.
44 typedef base::Callback<void(std::unique_ptr<ParsedServerResponse>)> 45 typedef base::Callback<void(std::unique_ptr<ParsedServerResponse>)>
45 V4UpdateCallback; 46 V4UpdateCallback;
46 47
48 typedef base::Callback<ExtendedReportingLevel()> ExtendedReportingLevelCallback;
49
47 class V4UpdateProtocolManager : public net::URLFetcherDelegate, 50 class V4UpdateProtocolManager : public net::URLFetcherDelegate,
48 public base::NonThreadSafe { 51 public base::NonThreadSafe {
49 public: 52 public:
50 ~V4UpdateProtocolManager() override; 53 ~V4UpdateProtocolManager() override;
51 54
52 // Makes the passed |factory| the factory used to instantiate 55 // Makes the passed |factory| the factory used to instantiate
53 // a V4UpdateProtocolManager. Useful for tests. 56 // a V4UpdateProtocolManager. Useful for tests.
54 static void RegisterFactory(V4UpdateProtocolManagerFactory* factory) { 57 static void RegisterFactory(V4UpdateProtocolManagerFactory* factory) {
55 factory_ = factory; 58 factory_ = factory;
56 } 59 }
57 60
58 // Create an instance of the safe browsing v4 protocol manager. 61 // Create an instance of the safe browsing v4 protocol manager.
59 static std::unique_ptr<V4UpdateProtocolManager> Create( 62 static std::unique_ptr<V4UpdateProtocolManager> Create(
60 net::URLRequestContextGetter* request_context_getter, 63 net::URLRequestContextGetter* request_context_getter,
61 const V4ProtocolConfig& config, 64 const V4ProtocolConfig& config,
62 V4UpdateCallback callback); 65 V4UpdateCallback update_callback,
66 ExtendedReportingLevelCallback extended_reporting_level_callback);
63 67
64 // net::URLFetcherDelegate interface. 68 // net::URLFetcherDelegate interface.
65 void OnURLFetchComplete(const net::URLFetcher* source) override; 69 void OnURLFetchComplete(const net::URLFetcher* source) override;
66 70
67 // Schedule the next update without backoff. 71 // Schedule the next update without backoff.
68 void ScheduleNextUpdate(std::unique_ptr<StoreStateMap> store_state_map); 72 void ScheduleNextUpdate(std::unique_ptr<StoreStateMap> store_state_map);
69 73
70 protected: 74 protected:
71 // Constructs a V4UpdateProtocolManager that issues network requests using 75 // Constructs a V4UpdateProtocolManager that issues network requests using
72 // |request_context_getter|. It schedules updates to get the hash prefixes for 76 // |request_context_getter|. It schedules updates to get the hash prefixes for
73 // SafeBrowsing lists, and invoke |callback| when the results are retrieved. 77 // SafeBrowsing lists, and invoke |callback| when the results are retrieved.
74 // The callback may be invoked synchronously. 78 // The callback may be invoked synchronously.
75 V4UpdateProtocolManager( 79 V4UpdateProtocolManager(
76 net::URLRequestContextGetter* request_context_getter, 80 net::URLRequestContextGetter* request_context_getter,
77 const V4ProtocolConfig& config, 81 const V4ProtocolConfig& config,
78 V4UpdateCallback callback); 82 V4UpdateCallback update_callback,
83 ExtendedReportingLevelCallback extended_reporting_level_callback);
79 84
80 private: 85 private:
81 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 86 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
82 TestGetUpdatesErrorHandlingNetwork); 87 TestGetUpdatesErrorHandlingNetwork);
83 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 88 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
84 TestGetUpdatesErrorHandlingResponseCode); 89 TestGetUpdatesErrorHandlingResponseCode);
85 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, TestGetUpdatesNoError); 90 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, TestGetUpdatesNoError);
86 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 91 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
87 TestGetUpdatesWithOneBackoff); 92 TestGetUpdatesWithOneBackoff);
88 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 93 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
89 TestBase64EncodingUsesUrlEncoding); 94 TestBase64EncodingUsesUrlEncoding);
90 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, TestDisableAutoUpdates); 95 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, TestDisableAutoUpdates);
91 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest, 96 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
92 TestGetUpdatesHasTimeout); 97 TestGetUpdatesHasTimeout);
98 FRIEND_TEST_ALL_PREFIXES(V4UpdateProtocolManagerTest,
99 TestExtendedReportingLevelIncluded);
93 friend class V4UpdateProtocolManagerFactoryImpl; 100 friend class V4UpdateProtocolManagerFactoryImpl;
94 101
95 // Fills a FetchThreatListUpdatesRequest protocol buffer for a request. 102 // Fills a FetchThreatListUpdatesRequest protocol buffer for a request.
96 // Returns the serialized and base64 URL encoded request as a string. 103 // Returns the serialized and base64 URL encoded request as a string.
97 std::string GetBase64SerializedUpdateRequestProto(); 104 std::string GetBase64SerializedUpdateRequestProto();
98 105
99 // The method to populate |gurl| with the URL to be sent to the server. 106 // The method to populate |gurl| with the URL to be sent to the server.
100 // |request_base64| is the base64 encoded form of an instance of the protobuf 107 // |request_base64| is the base64 encoded form of an instance of the protobuf
101 // FetchThreatListUpdatesRequest. Also sets the appropriate header values for 108 // FetchThreatListUpdatesRequest. Also sets the appropriate header values for
102 // sending PVer4 requests in |headers|. 109 // sending PVer4 requests in |headers|.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 183
177 // Timer to setup the next update request. 184 // Timer to setup the next update request.
178 base::OneShotTimer update_timer_; 185 base::OneShotTimer update_timer_;
179 186
180 base::Time last_response_time_; 187 base::Time last_response_time_;
181 188
182 // Used to interrupt and re-schedule update requests that take too long to 189 // Used to interrupt and re-schedule update requests that take too long to
183 // complete. 190 // complete.
184 base::OneShotTimer timeout_timer_; 191 base::OneShotTimer timeout_timer_;
185 192
193 ExtendedReportingLevelCallback extended_reporting_level_callback_;
194
186 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager); 195 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManager);
187 }; 196 };
188 197
189 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests. 198 // Interface of a factory to create V4UpdateProtocolManager. Useful for tests.
190 class V4UpdateProtocolManagerFactory { 199 class V4UpdateProtocolManagerFactory {
191 public: 200 public:
192 V4UpdateProtocolManagerFactory() {} 201 V4UpdateProtocolManagerFactory() {}
193 virtual ~V4UpdateProtocolManagerFactory() {} 202 virtual ~V4UpdateProtocolManagerFactory() {}
194 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager( 203 virtual std::unique_ptr<V4UpdateProtocolManager> CreateProtocolManager(
195 net::URLRequestContextGetter* request_context_getter, 204 net::URLRequestContextGetter* request_context_getter,
196 const V4ProtocolConfig& config, 205 const V4ProtocolConfig& config,
197 V4UpdateCallback callback) = 0; 206 V4UpdateCallback update_callback,
207 ExtendedReportingLevelCallback extended_reporting_level_callback) = 0;
198 208
199 private: 209 private:
200 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory); 210 DISALLOW_COPY_AND_ASSIGN(V4UpdateProtocolManagerFactory);
201 }; 211 };
202 212
203 } // namespace safe_browsing 213 } // namespace safe_browsing
204 214
205 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_ 215 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_UPDATE_PROTOCOL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698