| 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. |
| 11 // | 11 // |
| 12 // The SafeBrowsingProtocolManager handles formatting and making requests of, | 12 // The SafeBrowsingProtocolManager handles formatting and making requests of, |
| 13 // and handling responses from, Google's SafeBrowsing servers. This class uses | 13 // and handling responses from, Google's SafeBrowsing servers. This class uses |
| 14 // The SafeBrowsingProtocolParser class to do the actual parsing. | 14 // The SafeBrowsingProtocolParser class to do the actual parsing. |
| 15 | 15 |
| 16 #include <stddef.h> | 16 #include <stddef.h> |
| 17 | 17 |
| 18 #include <algorithm> |
| 18 #include <deque> | 19 #include <deque> |
| 19 #include <memory> | 20 #include <memory> |
| 20 #include <set> | 21 #include <set> |
| 21 #include <string> | 22 #include <string> |
| 22 #include <vector> | 23 #include <vector> |
| 23 | 24 |
| 24 #include "base/containers/hash_tables.h" | 25 #include "base/containers/hash_tables.h" |
| 25 #include "base/gtest_prod_util.h" | 26 #include "base/gtest_prod_util.h" |
| 26 #include "base/macros.h" | 27 #include "base/macros.h" |
| 27 #include "base/time/time.h" | 28 #include "base/time/time.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // Map of GetHash requests to parameters which created it. | 284 // Map of GetHash requests to parameters which created it. |
| 284 struct FullHashDetails { | 285 struct FullHashDetails { |
| 285 FullHashDetails(); | 286 FullHashDetails(); |
| 286 FullHashDetails(FullHashCallback callback, bool is_download); | 287 FullHashDetails(FullHashCallback callback, bool is_download); |
| 287 FullHashDetails(const FullHashDetails& other); | 288 FullHashDetails(const FullHashDetails& other); |
| 288 ~FullHashDetails(); | 289 ~FullHashDetails(); |
| 289 | 290 |
| 290 FullHashCallback callback; | 291 FullHashCallback callback; |
| 291 bool is_download; | 292 bool is_download; |
| 292 }; | 293 }; |
| 293 using HashRequests = base::hash_map<const net::URLFetcher*, FullHashDetails>; | |
| 294 | 294 |
| 295 // The factory that controls the creation of SafeBrowsingProtocolManager. | 295 // The factory that controls the creation of SafeBrowsingProtocolManager. |
| 296 // This is used by tests. | 296 // This is used by tests. |
| 297 static SBProtocolManagerFactory* factory_; | 297 static SBProtocolManagerFactory* factory_; |
| 298 | 298 |
| 299 // Our delegate. | 299 // Our delegate. |
| 300 SafeBrowsingProtocolManagerDelegate* delegate_; | 300 SafeBrowsingProtocolManagerDelegate* delegate_; |
| 301 | 301 |
| 302 // Current active request (in case we need to cancel) for updates or chunks | 302 // Current active request (in case we need to cancel) for updates or chunks |
| 303 // from the SafeBrowsing service. We can only have one of these outstanding | 303 // from the SafeBrowsing service. We can only have one of these outstanding |
| (...skipping 23 matching lines...) Expand all Loading... |
| 327 base::TimeDelta next_update_interval_; | 327 base::TimeDelta next_update_interval_; |
| 328 base::OneShotTimer update_timer_; | 328 base::OneShotTimer update_timer_; |
| 329 | 329 |
| 330 // timeout_timer_ is used to interrupt update requests which are taking | 330 // timeout_timer_ is used to interrupt update requests which are taking |
| 331 // too long. | 331 // too long. |
| 332 base::OneShotTimer timeout_timer_; | 332 base::OneShotTimer timeout_timer_; |
| 333 | 333 |
| 334 // All chunk requests that need to be made. | 334 // All chunk requests that need to be made. |
| 335 std::deque<ChunkUrl> chunk_request_urls_; | 335 std::deque<ChunkUrl> chunk_request_urls_; |
| 336 | 336 |
| 337 HashRequests hash_requests_; | 337 base::hash_map<const net::URLFetcher*, |
| 338 std::pair<std::unique_ptr<net::URLFetcher>, FullHashDetails>> |
| 339 hash_requests_; |
| 338 | 340 |
| 339 // True if the service has been given an add/sub chunk but it hasn't been | 341 // True if the service has been given an add/sub chunk but it hasn't been |
| 340 // added to the database yet. | 342 // added to the database yet. |
| 341 bool chunk_pending_to_write_; | 343 bool chunk_pending_to_write_; |
| 342 | 344 |
| 343 // The last time we successfully received an update. | 345 // The last time we successfully received an update. |
| 344 base::Time last_update_; | 346 base::Time last_update_; |
| 345 | 347 |
| 346 // While in GetHash backoff, we can't make another GetHash until this time. | 348 // While in GetHash backoff, we can't make another GetHash until this time. |
| 347 base::Time next_gethash_time_; | 349 base::Time next_gethash_time_; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 AddChunksCallback callback) = 0; | 440 AddChunksCallback callback) = 0; |
| 439 | 441 |
| 440 // Delete chunks from the database. | 442 // Delete chunks from the database. |
| 441 virtual void DeleteChunks( | 443 virtual void DeleteChunks( |
| 442 std::unique_ptr<std::vector<SBChunkDelete>> chunk_deletes) = 0; | 444 std::unique_ptr<std::vector<SBChunkDelete>> chunk_deletes) = 0; |
| 443 }; | 445 }; |
| 444 | 446 |
| 445 } // namespace safe_browsing | 447 } // namespace safe_browsing |
| 446 | 448 |
| 447 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 449 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
| OLD | NEW |