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 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // Parameters: | 140 // Parameters: |
141 // - The API threat metadata for the given URL. | 141 // - The API threat metadata for the given URL. |
142 typedef base::Callback<void(const ThreatMetadata& md)> | 142 typedef base::Callback<void(const ThreatMetadata& md)> |
143 ThreatMetadataForApiCallback; | 143 ThreatMetadataForApiCallback; |
144 | 144 |
145 ~V4GetHashProtocolManager() override; | 145 ~V4GetHashProtocolManager() override; |
146 | 146 |
147 // Create an instance of the safe browsing v4 protocol manager. | 147 // Create an instance of the safe browsing v4 protocol manager. |
148 static std::unique_ptr<V4GetHashProtocolManager> Create( | 148 static std::unique_ptr<V4GetHashProtocolManager> Create( |
149 net::URLRequestContextGetter* request_context_getter, | 149 net::URLRequestContextGetter* request_context_getter, |
150 const base::hash_set<UpdateListIdentifier>& stores_to_request, | 150 const std::unordered_set<UpdateListIdentifier>& stores_to_request, |
151 const V4ProtocolConfig& config); | 151 const V4ProtocolConfig& config); |
152 | 152 |
153 // Makes the passed |factory| the factory used to instantiate | 153 // Makes the passed |factory| the factory used to instantiate |
154 // a V4GetHashProtocolManager. Useful for tests. | 154 // a V4GetHashProtocolManager. Useful for tests. |
155 static void RegisterFactory( | 155 static void RegisterFactory( |
156 std::unique_ptr<V4GetHashProtocolManagerFactory> factory); | 156 std::unique_ptr<V4GetHashProtocolManagerFactory> factory); |
157 | 157 |
158 // Empties the cache. | 158 // Empties the cache. |
159 void ClearCache(); | 159 void ClearCache(); |
160 | 160 |
(...skipping 19 matching lines...) Expand all Loading... |
180 ThreatMetadataForApiCallback api_callback); | 180 ThreatMetadataForApiCallback api_callback); |
181 | 181 |
182 // net::URLFetcherDelegate interface. | 182 // net::URLFetcherDelegate interface. |
183 void OnURLFetchComplete(const net::URLFetcher* source) override; | 183 void OnURLFetchComplete(const net::URLFetcher* source) override; |
184 | 184 |
185 protected: | 185 protected: |
186 // Constructs a V4GetHashProtocolManager that issues | 186 // Constructs a V4GetHashProtocolManager that issues |
187 // network requests using |request_context_getter|. | 187 // network requests using |request_context_getter|. |
188 V4GetHashProtocolManager( | 188 V4GetHashProtocolManager( |
189 net::URLRequestContextGetter* request_context_getter, | 189 net::URLRequestContextGetter* request_context_getter, |
190 const base::hash_set<UpdateListIdentifier>& stores_to_request, | 190 const std::unordered_set<UpdateListIdentifier>& stores_to_request, |
191 const V4ProtocolConfig& config); | 191 const V4ProtocolConfig& config); |
192 | 192 |
193 private: | 193 private: |
194 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, TestGetHashRequest); | 194 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, TestGetHashRequest); |
195 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, TestParseHashResponse); | 195 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, TestParseHashResponse); |
196 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, | 196 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, |
197 TestParseHashResponseWrongThreatEntryType); | 197 TestParseHashResponseWrongThreatEntryType); |
198 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, | 198 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, |
199 TestParseHashThreatPatternType); | 199 TestParseHashThreatPatternType); |
200 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, | 200 FRIEND_TEST_ALL_PREFIXES(V4GetHashProtocolManagerTest, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // results that the client did not ask for. | 248 // results that the client did not ask for. |
249 void MergeResults(const FullHashToStoreAndHashPrefixesMap& | 249 void MergeResults(const FullHashToStoreAndHashPrefixesMap& |
250 full_hash_to_store_and_hash_prefixes, | 250 full_hash_to_store_and_hash_prefixes, |
251 const std::vector<FullHashInfo>& full_hash_infos, | 251 const std::vector<FullHashInfo>& full_hash_infos, |
252 std::vector<FullHashInfo>* merged_full_hash_infos); | 252 std::vector<FullHashInfo>* merged_full_hash_infos); |
253 | 253 |
254 // Calls |api_callback| with an object of ThreatMetadata that contains | 254 // Calls |api_callback| with an object of ThreatMetadata that contains |
255 // permission API metadata for full hashes in those |full_hash_infos| that | 255 // permission API metadata for full hashes in those |full_hash_infos| that |
256 // have a full hash in |full_hashes|. | 256 // have a full hash in |full_hashes|. |
257 void OnFullHashForApi(const ThreatMetadataForApiCallback& api_callback, | 257 void OnFullHashForApi(const ThreatMetadataForApiCallback& api_callback, |
258 const base::hash_set<FullHash>& full_hashes, | 258 const std::unordered_set<FullHash>& full_hashes, |
259 const std::vector<FullHashInfo>& full_hash_infos); | 259 const std::vector<FullHashInfo>& full_hash_infos); |
260 | 260 |
261 // Parses a FindFullHashesResponse protocol buffer and fills the results in | 261 // Parses a FindFullHashesResponse protocol buffer and fills the results in |
262 // |full_hash_infos| and |negative_cache_expire|. |response_data| is a | 262 // |full_hash_infos| and |negative_cache_expire|. |response_data| is a |
263 // serialized FindFullHashes protocol buffer. |negative_cache_expire| is the | 263 // serialized FindFullHashes protocol buffer. |negative_cache_expire| is the |
264 // cache expiry time of the hash prefixes that were requested. Returns true if | 264 // cache expiry time of the hash prefixes that were requested. Returns true if |
265 // parsing is successful; false otherwise. | 265 // parsing is successful; false otherwise. |
266 bool ParseHashResponse(const std::string& response_data, | 266 bool ParseHashResponse(const std::string& response_data, |
267 std::vector<FullHashInfo>* full_hash_infos, | 267 std::vector<FullHashInfo>* full_hash_infos, |
268 base::Time* negative_cache_expire); | 268 base::Time* negative_cache_expire); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 // The clock used to vend times. | 325 // The clock used to vend times. |
326 std::unique_ptr<base::Clock> clock_; | 326 std::unique_ptr<base::Clock> clock_; |
327 | 327 |
328 // A cache of full hash results. | 328 // A cache of full hash results. |
329 FullHashCache full_hash_cache_; | 329 FullHashCache full_hash_cache_; |
330 | 330 |
331 // The following sets represent the combination of lists that we would always | 331 // The following sets represent the combination of lists that we would always |
332 // request from the server, irrespective of which list we found the hash | 332 // request from the server, irrespective of which list we found the hash |
333 // prefix match in. | 333 // prefix match in. |
334 base::hash_set<PlatformType> platform_types_; | 334 std::unordered_set<PlatformType> platform_types_; |
335 base::hash_set<ThreatEntryType> threat_entry_types_; | 335 std::unordered_set<ThreatEntryType> threat_entry_types_; |
336 base::hash_set<ThreatType> threat_types_; | 336 std::unordered_set<ThreatType> threat_types_; |
337 | 337 |
338 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManager); | 338 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManager); |
339 }; | 339 }; |
340 | 340 |
341 // Interface of a factory to create V4GetHashProtocolManager. Useful for tests. | 341 // Interface of a factory to create V4GetHashProtocolManager. Useful for tests. |
342 class V4GetHashProtocolManagerFactory { | 342 class V4GetHashProtocolManagerFactory { |
343 public: | 343 public: |
344 V4GetHashProtocolManagerFactory() {} | 344 V4GetHashProtocolManagerFactory() {} |
345 virtual ~V4GetHashProtocolManagerFactory() {} | 345 virtual ~V4GetHashProtocolManagerFactory() {} |
346 virtual std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( | 346 virtual std::unique_ptr<V4GetHashProtocolManager> CreateProtocolManager( |
347 net::URLRequestContextGetter* request_context_getter, | 347 net::URLRequestContextGetter* request_context_getter, |
348 const base::hash_set<UpdateListIdentifier>& stores_to_request, | 348 const std::unordered_set<UpdateListIdentifier>& stores_to_request, |
349 const V4ProtocolConfig& config) = 0; | 349 const V4ProtocolConfig& config) = 0; |
350 | 350 |
351 private: | 351 private: |
352 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManagerFactory); | 352 DISALLOW_COPY_AND_ASSIGN(V4GetHashProtocolManagerFactory); |
353 }; | 353 }; |
354 | 354 |
355 #ifndef NDEBUG | 355 #ifndef NDEBUG |
356 std::ostream& operator<<(std::ostream& os, const FullHashInfo& id); | 356 std::ostream& operator<<(std::ostream& os, const FullHashInfo& id); |
357 #endif | 357 #endif |
358 | 358 |
359 } // namespace safe_browsing | 359 } // namespace safe_browsing |
360 | 360 |
361 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_GET_HASH_PROTOCOL_MANAGER_H_ | 361 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_GET_HASH_PROTOCOL_MANAGER_H_ |
OLD | NEW |