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

Side by Side Diff: chrome/browser/safe_browsing/protocol_manager.h

Issue 1543153002: Add a GetFullHashWithApis method to Protocol Manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
7 7
8 // A class that implements Chrome's interface with the SafeBrowsing protocol. 8 // A class that implements Chrome's interface with the SafeBrowsing protocol.
9 // See https://developers.google.com/safe-browsing/developers_guide_v2 for 9 // See https://developers.google.com/safe-browsing/developers_guide_v2 for
10 // protocol details. 10 // protocol details.
(...skipping 13 matching lines...) Expand all
24 #include "base/gtest_prod_util.h" 24 #include "base/gtest_prod_util.h"
25 #include "base/macros.h" 25 #include "base/macros.h"
26 #include "base/memory/scoped_ptr.h" 26 #include "base/memory/scoped_ptr.h"
27 #include "base/threading/non_thread_safe.h" 27 #include "base/threading/non_thread_safe.h"
28 #include "base/time/time.h" 28 #include "base/time/time.h"
29 #include "base/timer/timer.h" 29 #include "base/timer/timer.h"
30 #include "chrome/browser/safe_browsing/chunk_range.h" 30 #include "chrome/browser/safe_browsing/chunk_range.h"
31 #include "chrome/browser/safe_browsing/protocol_manager_helper.h" 31 #include "chrome/browser/safe_browsing/protocol_manager_helper.h"
32 #include "chrome/browser/safe_browsing/protocol_parser.h" 32 #include "chrome/browser/safe_browsing/protocol_parser.h"
33 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 33 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
34 #include "components/safe_browsing_db/safebrowsing.pb.h"
34 #include "net/url_request/url_fetcher_delegate.h" 35 #include "net/url_request/url_fetcher_delegate.h"
35 #include "net/url_request/url_request_status.h" 36 #include "net/url_request/url_request_status.h"
36 #include "url/gurl.h" 37 #include "url/gurl.h"
37 38
38 namespace net { 39 namespace net {
39 class URLFetcher; 40 class URLFetcher;
40 class URLRequestContextGetter; 41 class URLRequestContextGetter;
41 } // namespace net 42 } // namespace net
42 43
43 namespace safe_browsing { 44 namespace safe_browsing {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 void OnURLFetchComplete(const net::URLFetcher* source) override; 80 void OnURLFetchComplete(const net::URLFetcher* source) override;
80 81
81 // Retrieve the full hash for a set of prefixes, and invoke the callback 82 // Retrieve the full hash for a set of prefixes, and invoke the callback
82 // argument when the results are retrieved. The callback may be invoked 83 // argument when the results are retrieved. The callback may be invoked
83 // synchronously. 84 // synchronously.
84 virtual void GetFullHash(const std::vector<SBPrefix>& prefixes, 85 virtual void GetFullHash(const std::vector<SBPrefix>& prefixes,
85 FullHashCallback callback, 86 FullHashCallback callback,
86 bool is_download, 87 bool is_download,
87 bool is_extended_reporting); 88 bool is_extended_reporting);
88 89
90 // Retrieve the full hash for a set of prefixes, and invoke the callback
91 // argument when the results are retrieved. The callback may be invoked
92 // synchronously. Uses the V4 Safe Browsing protocol.
93 virtual void GetV4FullHashes(const std::vector<SBPrefix>& prefixes,
94 ThreatType threat_type,
95 FullHashCallback callback);
96
97 // Retrieve the full hash and API metadata for a set of prefixes, and invoke
98 // the callback argument when the results are retrieved. The callback may be
99 // invoked synchronously. Uses the V4 Safe Browsing protocol.
100 virtual void GetFullHashesWithApis(const std::vector<SBPrefix>& prefixes,
101 FullHashCallback callback);
102
89 // Forces the start of next update after |interval| time. 103 // Forces the start of next update after |interval| time.
90 void ForceScheduleNextUpdate(base::TimeDelta interval); 104 void ForceScheduleNextUpdate(base::TimeDelta interval);
91 105
92 // Scheduled update callback. 106 // Scheduled update callback.
93 void GetNextUpdate(); 107 void GetNextUpdate();
94 108
95 // Called by the SafeBrowsingService when our request for a list of all chunks 109 // Called by the SafeBrowsingService when our request for a list of all chunks
96 // for each list is done. If database_error is true, that means the protocol 110 // for each list is done. If database_error is true, that means the protocol
97 // manager shouldn't fetch updates since they can't be written to disk. It 111 // manager shouldn't fetch updates since they can't be written to disk. It
98 // should try again later to open the database. 112 // should try again later to open the database.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 SafeBrowsingProtocolManager( 195 SafeBrowsingProtocolManager(
182 SafeBrowsingProtocolManagerDelegate* delegate, 196 SafeBrowsingProtocolManagerDelegate* delegate,
183 net::URLRequestContextGetter* request_context_getter, 197 net::URLRequestContextGetter* request_context_getter,
184 const SafeBrowsingProtocolConfig& config); 198 const SafeBrowsingProtocolConfig& config);
185 199
186 private: 200 private:
187 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); 201 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes);
188 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); 202 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings);
189 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); 203 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl);
190 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 204 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
205 TestGetV4HashUrl);
206 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
207 TestGetV4HashRequest);
208 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
191 TestGetHashBackOffTimes); 209 TestGetHashBackOffTimes);
192 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); 210 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl);
193 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); 211 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl);
194 friend class SafeBrowsingServerTest; 212 friend class SafeBrowsingServerTest;
195 friend class SBProtocolManagerFactoryImpl; 213 friend class SBProtocolManagerFactoryImpl;
196 214
197 // Internal API for fetching information from the SafeBrowsing servers. The 215 // Internal API for fetching information from the SafeBrowsing servers. The
198 // GetHash requests are higher priority since they can block user requests 216 // GetHash requests are higher priority since they can block user requests
199 // so are handled separately. 217 // so are handled separately.
200 enum SafeBrowsingRequestType { 218 enum SafeBrowsingRequestType {
(...skipping 15 matching lines...) Expand all
216 GURL UpdateUrl(bool is_extended_reporting) const; 234 GURL UpdateUrl(bool is_extended_reporting) const;
217 235
218 // Generates backup Update URL for querying about the latest set of chunk 236 // Generates backup Update URL for querying about the latest set of chunk
219 // updates. |url_prefix| is the base prefix to use. 237 // updates. |url_prefix| is the base prefix to use.
220 GURL BackupUpdateUrl(BackupUpdateReason reason) const; 238 GURL BackupUpdateUrl(BackupUpdateReason reason) const;
221 239
222 // Generates GetHash request URL for retrieving full hashes. 240 // Generates GetHash request URL for retrieving full hashes.
223 GURL GetHashUrl(bool is_extended_reporting) const; 241 GURL GetHashUrl(bool is_extended_reporting) const;
224 // Generates URL for reporting safe browsing hits for UMA users. 242 // Generates URL for reporting safe browsing hits for UMA users.
225 243
244 // Generates GetHashWithApis Pver4 request URL for retrieving full hashes.
245 // |request_base64| is the serialized FindFullHashesRequest protocol buffer
246 // encoded in base 64.
247 GURL GetV4HashUrl(const std::string& request_base64) const;
248
249 // Fills a FindFullHashesRequest protocol buffer for an API_ABUSE request.
250 // Returns the serialized and base 64 encoded request as a string.
251 std::string GetV4HashRequest(const std::vector<SBPrefix>& prefixes,
252 ThreatType threat_type);
253
226 // Composes a ChunkUrl based on input string. 254 // Composes a ChunkUrl based on input string.
227 GURL NextChunkUrl(const std::string& input) const; 255 GURL NextChunkUrl(const std::string& input) const;
228 256
229 // Returns the time for the next update request. If |back_off| is true, 257 // Returns the time for the next update request. If |back_off| is true,
230 // the time returned will increment an error count and return the appriate 258 // the time returned will increment an error count and return the appriate
231 // next time (see ScheduleNextUpdate below). 259 // next time (see ScheduleNextUpdate below).
232 base::TimeDelta GetNextUpdateInterval(bool back_off); 260 base::TimeDelta GetNextUpdateInterval(bool back_off);
233 261
234 // Worker function for calculating GetHash and Update backoff times (in 262 // Worker function for calculating GetHash and Update backoff times (in
235 // seconds). |multiplier| is doubled for each consecutive error between the 263 // seconds). |multiplier| is doubled for each consecutive error between the
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 base::OneShotTimer update_timer_; 357 base::OneShotTimer update_timer_;
330 358
331 // timeout_timer_ is used to interrupt update requests which are taking 359 // timeout_timer_ is used to interrupt update requests which are taking
332 // too long. 360 // too long.
333 base::OneShotTimer timeout_timer_; 361 base::OneShotTimer timeout_timer_;
334 362
335 // All chunk requests that need to be made. 363 // All chunk requests that need to be made.
336 std::deque<ChunkUrl> chunk_request_urls_; 364 std::deque<ChunkUrl> chunk_request_urls_;
337 365
338 HashRequests hash_requests_; 366 HashRequests hash_requests_;
367 HashRequests v4_hash_requests_;
339 368
340 // True if the service has been given an add/sub chunk but it hasn't been 369 // True if the service has been given an add/sub chunk but it hasn't been
341 // added to the database yet. 370 // added to the database yet.
342 bool chunk_pending_to_write_; 371 bool chunk_pending_to_write_;
343 372
344 // The last time we successfully received an update. 373 // The last time we successfully received an update.
345 base::Time last_update_; 374 base::Time last_update_;
346 375
347 // While in GetHash backoff, we can't make another GetHash until this time. 376 // While in GetHash backoff, we can't make another GetHash until this time.
348 base::Time next_gethash_time_; 377 base::Time next_gethash_time_;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 AddChunksCallback callback) = 0; 470 AddChunksCallback callback) = 0;
442 471
443 // Delete chunks from the database. 472 // Delete chunks from the database.
444 virtual void DeleteChunks( 473 virtual void DeleteChunks(
445 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0; 474 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0;
446 }; 475 };
447 476
448 } // namespace safe_browsing 477 } // namespace safe_browsing
449 478
450 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 479 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698