| OLD | NEW |
| 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_GET_HASH_PROTOCOL_MANAGER_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_GET_HASH_PROTOCOL_MANAGER_H_ |
| 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_GET_HASH_PROTOCOL_MANAGER_H_ | 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_GET_HASH_PROTOCOL_MANAGER_H_ |
| 7 | 7 |
| 8 // A class that implements Chrome's interface with the SafeBrowsing V4 protocol. | 8 // A class that implements Chrome's interface with the SafeBrowsing V4 protocol. |
| 9 // | 9 // |
| 10 // The V4GetHashProtocolManager handles formatting and making requests of, and | 10 // The V4GetHashProtocolManager handles formatting and making requests of, and |
| 11 // handling responses from, Google's SafeBrowsing servers. The purpose of this | 11 // handling responses from, Google's SafeBrowsing servers. The purpose of this |
| 12 // class is to get full hash matches from the SB server for the given set of | 12 // class is to get full hash matches from the SB server for the given set of |
| 13 // hash prefixes. | 13 // hash prefixes. |
| 14 | 14 |
| 15 #include <memory> | 15 #include <memory> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <unordered_map> | 17 #include <unordered_map> |
| 18 #include <utility> | 18 #include <utility> |
| 19 #include <vector> | 19 #include <vector> |
| 20 | 20 |
| 21 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
| 22 #include "base/macros.h" | 22 #include "base/macros.h" |
| 23 #include "base/threading/non_thread_safe.h" | 23 #include "base/sequence_checker.h" |
| 24 #include "base/time/default_clock.h" | 24 #include "base/time/default_clock.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 "components/safe_browsing_db/safebrowsing.pb.h" | 27 #include "components/safe_browsing_db/safebrowsing.pb.h" |
| 28 #include "components/safe_browsing_db/util.h" | 28 #include "components/safe_browsing_db/util.h" |
| 29 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 29 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 30 #include "net/url_request/url_fetcher_delegate.h" | 30 #include "net/url_request/url_fetcher_delegate.h" |
| 31 | 31 |
| 32 class GURL; | 32 class GURL; |
| 33 | 33 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 base::Time network_start_time; | 132 base::Time network_start_time; |
| 133 | 133 |
| 134 // The prefixes that were requested from the server. | 134 // The prefixes that were requested from the server. |
| 135 std::vector<HashPrefix> prefixes_requested; | 135 std::vector<HashPrefix> prefixes_requested; |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 // ---------------------------------------------------------------- | 138 // ---------------------------------------------------------------- |
| 139 | 139 |
| 140 class V4GetHashProtocolManagerFactory; | 140 class V4GetHashProtocolManagerFactory; |
| 141 | 141 |
| 142 class V4GetHashProtocolManager : public net::URLFetcherDelegate, | 142 class V4GetHashProtocolManager : public net::URLFetcherDelegate { |
| 143 public base::NonThreadSafe { | |
| 144 public: | 143 public: |
| 145 // Invoked when GetFullHashesWithApis completes. | 144 // Invoked when GetFullHashesWithApis completes. |
| 146 // Parameters: | 145 // Parameters: |
| 147 // - The API threat metadata for the given URL. | 146 // - The API threat metadata for the given URL. |
| 148 typedef base::Callback<void(const ThreatMetadata& md)> | 147 typedef base::Callback<void(const ThreatMetadata& md)> |
| 149 ThreatMetadataForApiCallback; | 148 ThreatMetadataForApiCallback; |
| 150 | 149 |
| 151 ~V4GetHashProtocolManager() override; | 150 ~V4GetHashProtocolManager() override; |
| 152 | 151 |
| 153 // Create an instance of the safe browsing v4 protocol manager. | 152 // Create an instance of the safe browsing v4 protocol manager. |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // The clock used to vend times. | 333 // The clock used to vend times. |
| 335 std::unique_ptr<base::Clock> clock_; | 334 std::unique_ptr<base::Clock> clock_; |
| 336 | 335 |
| 337 // The following sets represent the combination of lists that we would always | 336 // The following sets represent the combination of lists that we would always |
| 338 // request from the server, irrespective of which list we found the hash | 337 // request from the server, irrespective of which list we found the hash |
| 339 // prefix match in. | 338 // prefix match in. |
| 340 std::vector<PlatformType> platform_types_; | 339 std::vector<PlatformType> platform_types_; |
| 341 std::vector<ThreatEntryType> threat_entry_types_; | 340 std::vector<ThreatEntryType> threat_entry_types_; |
| 342 std::vector<ThreatType> threat_types_; | 341 std::vector<ThreatType> threat_types_; |
| 343 | 342 |
| 343 SEQUENCE_CHECKER(sequence_checker_); |
| 344 |
| 344 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManager); | 345 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManager); |
| 345 }; | 346 }; |
| 346 | 347 |
| 347 // Interface of a factory to create V4GetHashProtocolManager. Useful for tests. | 348 // Interface of a factory to create V4GetHashProtocolManager. Useful for tests. |
| 348 class V4GetHashProtocolManagerFactory { | 349 class V4GetHashProtocolManagerFactory { |
| 349 public: | 350 public: |
| 350 V4GetHashProtocolManagerFactory() {} | 351 V4GetHashProtocolManagerFactory() {} |
| 351 virtual ~V4GetHashProtocolManagerFactory() {} | 352 virtual ~V4GetHashProtocolManagerFactory() {} |
| 352 virtual std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( | 353 virtual std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( |
| 353 net::URLRequestContextGetter* request_context_getter, | 354 net::URLRequestContextGetter* request_context_getter, |
| 354 const StoresToCheck& stores_to_check, | 355 const StoresToCheck& stores_to_check, |
| 355 const V4ProtocolConfig& config) = 0; | 356 const V4ProtocolConfig& config) = 0; |
| 356 | 357 |
| 357 private: | 358 private: |
| 358 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManagerFactory); | 359 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManagerFactory); |
| 359 }; | 360 }; |
| 360 | 361 |
| 361 #ifndef NDEBUG | 362 #ifndef NDEBUG |
| 362 std::ostream& operator<<(std::ostream& os, const FullHashInfo& id); | 363 std::ostream& operator<<(std::ostream& os, const FullHashInfo& id); |
| 363 #endif | 364 #endif |
| 364 | 365 |
| 365 } // namespace safe_browsing | 366 } // namespace safe_browsing |
| 366 | 367 |
| 367 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_GET_HASH_PROTOCOL_MANAGER_H_ | 368 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_GET_HASH_PROTOCOL_MANAGER_H_ |
| OLD | NEW |