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 // The Safe Browsing service is responsible for downloading anti-phishing and | 5 // The Safe Browsing service is responsible for downloading anti-phishing and |
6 // anti-malware tables and checking urls against them. | 6 // anti-malware tables and checking urls against them. |
7 | 7 |
8 #ifndef COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ | 8 #ifndef COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ |
9 #define COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ | 9 #define COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ |
10 | 10 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 237 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
238 ResultsAreNotCachedOnNull); | 238 ResultsAreNotCachedOnNull); |
239 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 239 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
240 GetCachedResults); | 240 GetCachedResults); |
241 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 241 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
242 CachedResultsMerged); | 242 CachedResultsMerged); |
243 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 243 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
244 CachedResultsAreEvicted); | 244 CachedResultsAreEvicted); |
245 | 245 |
246 typedef std::set<SafeBrowsingApiCheck*> ApiCheckSet; | 246 typedef std::set<SafeBrowsingApiCheck*> ApiCheckSet; |
247 typedef std::map<SBPrefix, SBCachedFullHashResult> PrefixToFullHashResultsMap; | |
248 typedef std::map<SBThreatType, PrefixToFullHashResultsMap> | |
249 ThreatTypeToResultsMap; | |
250 | 247 |
251 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received | 248 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received |
252 // the full hash and api results for prefixes of the |url| argument in | 249 // the full hash and api results for prefixes of the |url| argument in |
253 // CheckApiBlacklistUrl. | 250 // CheckApiBlacklistUrl. |
254 virtual void HandleGetHashesWithApisResults( | 251 virtual void HandleGetHashesWithApisResults( |
255 SafeBrowsingApiCheck* check, | 252 SafeBrowsingApiCheck* check, |
256 const std::vector<SBFullHashResult>& full_hash_results, | 253 const std::vector<SBFullHashResult>& full_hash_results, |
257 const base::Time& negative_cache_expire); | 254 const base::Time& negative_cache_expire); |
258 | 255 |
259 // Looks up the cached results for |threat_type|. Fills |prefixes| with the | |
260 // prefixes that need a request. Fills |cached_results| with the cached | |
261 // results. | |
262 void GetFullHashCachedResults(const SBThreatType& threat_type, | |
263 const std::vector<SBFullHash>& full_hashes, | |
264 base::Time now, | |
265 std::vector<SBPrefix>* prefixes, | |
266 std::vector<SBFullHashResult>* cached_results); | |
267 | |
268 // Populates |md| with permission api metadata from all results that have a | 256 // Populates |md| with permission api metadata from all results that have a |
269 // match in |full_hashes|. Returns |true| if any of the results have a match | 257 // match in |full_hashes|. Returns |true| if any of the results have a match |
270 // in |full_hashes|. | 258 // in |full_hashes|. |
271 bool PopulateApiMetadataResult(const std::vector<SBFullHashResult>& results, | 259 bool PopulateApiMetadataResult(const std::vector<SBFullHashResult>& results, |
272 const std::vector<SBFullHash>& full_hashes, | 260 const std::vector<SBFullHash>& full_hashes, |
273 ThreatMetadata* md); | 261 ThreatMetadata* md); |
274 | 262 |
275 // In-progress checks. This set owns the SafeBrowsingApiCheck pointers and is | 263 // In-progress checks. This set owns the SafeBrowsingApiCheck pointers and is |
276 // responsible for deleting them when removing from the set. | 264 // responsible for deleting them when removing from the set. |
277 ApiCheckSet api_checks_; | 265 ApiCheckSet api_checks_; |
278 | 266 |
279 // A cache of V4 full hash results for api checks. | |
280 // TODO(kcarattini): Look into moving all caching logic to | |
281 // V4GetHashProtocolManager. | |
282 ThreatTypeToResultsMap v4_full_hash_cache_; | |
283 | |
284 // Created and destroyed via StartOnIOThread/StopOnIOThread. | 267 // Created and destroyed via StartOnIOThread/StopOnIOThread. |
285 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; | 268 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; |
286 | 269 |
287 private: | 270 private: |
288 // Returns an iterator to the pending API check with the given |client|. | 271 // Returns an iterator to the pending API check with the given |client|. |
289 ApiCheckSet::iterator FindClientApiCheck(Client* client); | 272 ApiCheckSet::iterator FindClientApiCheck(Client* client); |
290 }; // class SafeBrowsingDatabaseManager | 273 }; // class SafeBrowsingDatabaseManager |
291 | 274 |
292 } // namespace safe_browsing | 275 } // namespace safe_browsing |
293 | 276 |
294 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ | 277 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ |
OLD | NEW |