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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 void OnURLFetchComplete(const net::URLFetcher* source) override; | 76 void OnURLFetchComplete(const net::URLFetcher* source) override; |
77 | 77 |
78 // Retrieve the full hash for a set of prefixes, and invoke the callback | 78 // 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 | 79 // argument when the results are retrieved. The callback may be invoked |
80 // synchronously. | 80 // synchronously. |
81 virtual void GetFullHash(const std::vector<SBPrefix>& prefixes, | 81 virtual void GetFullHash(const std::vector<SBPrefix>& prefixes, |
82 FullHashCallback callback, | 82 FullHashCallback callback, |
83 bool is_download, | 83 bool is_download, |
84 bool is_extended_reporting); | 84 bool is_extended_reporting); |
85 | 85 |
| 86 // Retrieve the full hash for a set of prefixes, and invoke the callback |
| 87 // argument when the results are retrieved. The callback may be invoked |
| 88 // synchronously. |
| 89 virtual void GetFullHashWithApis(const std::vector<SBPrefix>& prefixes, |
| 90 FullHashCallback callback); |
| 91 |
86 // Forces the start of next update after |interval| time. | 92 // Forces the start of next update after |interval| time. |
87 void ForceScheduleNextUpdate(base::TimeDelta interval); | 93 void ForceScheduleNextUpdate(base::TimeDelta interval); |
88 | 94 |
89 // Scheduled update callback. | 95 // Scheduled update callback. |
90 void GetNextUpdate(); | 96 void GetNextUpdate(); |
91 | 97 |
92 // Called by the SafeBrowsingService when our request for a list of all chunks | 98 // 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 | 99 // 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 | 100 // manager shouldn't fetch updates since they can't be written to disk. It |
95 // should try again later to open the database. | 101 // should try again later to open the database. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 SafeBrowsingProtocolManager( | 184 SafeBrowsingProtocolManager( |
179 SafeBrowsingProtocolManagerDelegate* delegate, | 185 SafeBrowsingProtocolManagerDelegate* delegate, |
180 net::URLRequestContextGetter* request_context_getter, | 186 net::URLRequestContextGetter* request_context_getter, |
181 const SafeBrowsingProtocolConfig& config); | 187 const SafeBrowsingProtocolConfig& config); |
182 | 188 |
183 private: | 189 private: |
184 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); | 190 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); |
185 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); | 191 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); |
186 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); | 192 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); |
187 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | 193 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
| 194 TestGetHashWithApisUrl); |
| 195 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
| 196 TestGetHashWithApisRequest); |
| 197 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
188 TestGetHashBackOffTimes); | 198 TestGetHashBackOffTimes); |
189 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); | 199 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); |
190 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); | 200 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); |
191 friend class SafeBrowsingServerTest; | 201 friend class SafeBrowsingServerTest; |
192 friend class SBProtocolManagerFactoryImpl; | 202 friend class SBProtocolManagerFactoryImpl; |
193 | 203 |
194 // Internal API for fetching information from the SafeBrowsing servers. The | 204 // Internal API for fetching information from the SafeBrowsing servers. The |
195 // GetHash requests are higher priority since they can block user requests | 205 // GetHash requests are higher priority since they can block user requests |
196 // so are handled separately. | 206 // so are handled separately. |
197 enum SafeBrowsingRequestType { | 207 enum SafeBrowsingRequestType { |
(...skipping 15 matching lines...) Expand all Loading... |
213 GURL UpdateUrl(bool is_extended_reporting) const; | 223 GURL UpdateUrl(bool is_extended_reporting) const; |
214 | 224 |
215 // Generates backup Update URL for querying about the latest set of chunk | 225 // Generates backup Update URL for querying about the latest set of chunk |
216 // updates. |url_prefix| is the base prefix to use. | 226 // updates. |url_prefix| is the base prefix to use. |
217 GURL BackupUpdateUrl(BackupUpdateReason reason) const; | 227 GURL BackupUpdateUrl(BackupUpdateReason reason) const; |
218 | 228 |
219 // Generates GetHash request URL for retrieving full hashes. | 229 // Generates GetHash request URL for retrieving full hashes. |
220 GURL GetHashUrl(bool is_extended_reporting) const; | 230 GURL GetHashUrl(bool is_extended_reporting) const; |
221 // Generates URL for reporting safe browsing hits for UMA users. | 231 // Generates URL for reporting safe browsing hits for UMA users. |
222 | 232 |
| 233 // Generates GetHashWithApis Pver4 request URL for retrieving full hashes. |
| 234 // |request_base64| is the serialized FindFullHashesRequest protocol buffer |
| 235 // encoded in base 64. |
| 236 GURL GetHashWithApisUrl(const std::string& request_base64) const; |
| 237 |
| 238 // Fills a FindFullHashesRequest protocol buffer for an API_ABUSE request. |
| 239 // Returns the serialized and base 64 encoded request as a string. |
| 240 std::string GetHashWithApisRequest(const std::vector<SBPrefix>& prefixes); |
| 241 |
223 // Composes a ChunkUrl based on input string. | 242 // Composes a ChunkUrl based on input string. |
224 GURL NextChunkUrl(const std::string& input) const; | 243 GURL NextChunkUrl(const std::string& input) const; |
225 | 244 |
226 // Returns the time for the next update request. If |back_off| is true, | 245 // 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 | 246 // the time returned will increment an error count and return the appriate |
228 // next time (see ScheduleNextUpdate below). | 247 // next time (see ScheduleNextUpdate below). |
229 base::TimeDelta GetNextUpdateInterval(bool back_off); | 248 base::TimeDelta GetNextUpdateInterval(bool back_off); |
230 | 249 |
231 // Worker function for calculating GetHash and Update backoff times (in | 250 // Worker function for calculating GetHash and Update backoff times (in |
232 // seconds). |multiplier| is doubled for each consecutive error between the | 251 // 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_; | 345 base::OneShotTimer update_timer_; |
327 | 346 |
328 // timeout_timer_ is used to interrupt update requests which are taking | 347 // timeout_timer_ is used to interrupt update requests which are taking |
329 // too long. | 348 // too long. |
330 base::OneShotTimer timeout_timer_; | 349 base::OneShotTimer timeout_timer_; |
331 | 350 |
332 // All chunk requests that need to be made. | 351 // All chunk requests that need to be made. |
333 std::deque<ChunkUrl> chunk_request_urls_; | 352 std::deque<ChunkUrl> chunk_request_urls_; |
334 | 353 |
335 HashRequests hash_requests_; | 354 HashRequests hash_requests_; |
| 355 HashRequests hash_api_requests_; |
336 | 356 |
337 // True if the service has been given an add/sub chunk but it hasn't been | 357 // True if the service has been given an add/sub chunk but it hasn't been |
338 // added to the database yet. | 358 // added to the database yet. |
339 bool chunk_pending_to_write_; | 359 bool chunk_pending_to_write_; |
340 | 360 |
341 // The last time we successfully received an update. | 361 // The last time we successfully received an update. |
342 base::Time last_update_; | 362 base::Time last_update_; |
343 | 363 |
344 // While in GetHash backoff, we can't make another GetHash until this time. | 364 // While in GetHash backoff, we can't make another GetHash until this time. |
345 base::Time next_gethash_time_; | 365 base::Time next_gethash_time_; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 AddChunksCallback callback) = 0; | 458 AddChunksCallback callback) = 0; |
439 | 459 |
440 // Delete chunks from the database. | 460 // Delete chunks from the database. |
441 virtual void DeleteChunks( | 461 virtual void DeleteChunks( |
442 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0; | 462 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0; |
443 }; | 463 }; |
444 | 464 |
445 } // namespace safe_browsing | 465 } // namespace safe_browsing |
446 | 466 |
447 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 467 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
OLD | NEW |