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