| 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 // Safe Browsing Database Manager implementation that manages a local | 5 // Safe Browsing Database Manager implementation that manages a local |
| 6 // database. This is used by Desktop Chromium. | 6 // database. This is used by Desktop Chromium. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 namespace safe_browsing { | 40 namespace safe_browsing { |
| 41 | 41 |
| 42 class SafeBrowsingService; | 42 class SafeBrowsingService; |
| 43 class SafeBrowsingDatabase; | 43 class SafeBrowsingDatabase; |
| 44 class ClientSideDetectionService; | 44 class ClientSideDetectionService; |
| 45 class DownloadProtectionService; | 45 class DownloadProtectionService; |
| 46 struct V4ProtocolConfig; | 46 struct V4ProtocolConfig; |
| 47 | 47 |
| 48 // Implemetation that manages a local database on disk. | 48 // Implementation that manages a local database on disk. |
| 49 // | 49 // |
| 50 // Construction needs to happen on the main thread. | 50 // Construction needs to happen on the main thread. |
| 51 class LocalSafeBrowsingDatabaseManager | 51 class LocalSafeBrowsingDatabaseManager |
| 52 : public SafeBrowsingDatabaseManager, | 52 : public SafeBrowsingDatabaseManager, |
| 53 public SafeBrowsingProtocolManagerDelegate { | 53 public SafeBrowsingProtocolManagerDelegate { |
| 54 public: | 54 public: |
| 55 // Bundle of SafeBrowsing state while performing a URL or hash prefix check. | 55 // Bundle of SafeBrowsing state while performing a URL or hash prefix check. |
| 56 struct SafeBrowsingCheck { | 56 struct SafeBrowsingCheck { |
| 57 // |check_type| should correspond to the type of item that is being | 57 // |check_type| should correspond to the type of item that is being |
| 58 // checked, either a URL or a binary hash/URL. We store this for two | 58 // checked, either a URL or a binary hash/URL. We store this for two |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 friend class base::RefCountedThreadSafe<LocalSafeBrowsingDatabaseManager>; | 152 friend class base::RefCountedThreadSafe<LocalSafeBrowsingDatabaseManager>; |
| 153 friend class SafeBrowsingServerTest; | 153 friend class SafeBrowsingServerTest; |
| 154 friend class SafeBrowsingServiceTest; | 154 friend class SafeBrowsingServiceTest; |
| 155 friend class SafeBrowsingServiceTestHelper; | 155 friend class SafeBrowsingServiceTestHelper; |
| 156 friend class LocalDatabaseManagerTest; | 156 friend class LocalDatabaseManagerTest; |
| 157 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest, GetUrlSeverestThreatType); | 157 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest, GetUrlSeverestThreatType); |
| 158 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest, | 158 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest, |
| 159 ServiceStopWithPendingChecks); | 159 ServiceStopWithPendingChecks); |
| 160 | 160 |
| 161 typedef std::set<SafeBrowsingCheck*> CurrentChecks; | |
| 162 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; | 161 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; |
| 163 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; | 162 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; |
| 164 | 163 |
| 165 // Clients that we've queued up for checking later once the database is ready. | 164 // Clients that we've queued up for checking later once the database is ready. |
| 166 struct QueuedCheck { | 165 struct QueuedCheck { |
| 167 QueuedCheck(const ListType check_type, | 166 QueuedCheck(const ListType check_type, |
| 168 Client* client, | 167 Client* client, |
| 169 const GURL& url, | 168 const GURL& url, |
| 170 const std::vector<SBThreatType>& expected_threats, | 169 const std::vector<SBThreatType>& expected_threats, |
| 171 const base::TimeTicks& start); | 170 const base::TimeTicks& start); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 std::vector<SBPrefix> CheckResourceUrlOnSBThread( | 296 std::vector<SBPrefix> CheckResourceUrlOnSBThread( |
| 298 const std::vector<SBPrefix>& prefixes); | 297 const std::vector<SBPrefix>& prefixes); |
| 299 | 298 |
| 300 // Helper function that calls safe browsing client and cleans up |checks_|. | 299 // Helper function that calls safe browsing client and cleans up |checks_|. |
| 301 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); | 300 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); |
| 302 | 301 |
| 303 // Helper function to set |check| with default values and start a safe | 302 // Helper function to set |check| with default values and start a safe |
| 304 // browsing check with timeout of |timeout|. |task| will be called on | 303 // browsing check with timeout of |timeout|. |task| will be called on |
| 305 // success, otherwise TimeoutCallback will be called. | 304 // success, otherwise TimeoutCallback will be called. |
| 306 void StartSafeBrowsingCheck( | 305 void StartSafeBrowsingCheck( |
| 307 SafeBrowsingCheck* check, | 306 std::unique_ptr<SafeBrowsingCheck> check, |
| 308 const base::Callback<std::vector<SBPrefix>(void)>& task); | 307 const base::Callback<std::vector<SBPrefix>(void)>& task); |
| 309 | 308 |
| 310 // SafeBrowsingProtocolManageDelegate override | 309 // SafeBrowsingProtocolManageDelegate override |
| 311 void ResetDatabase() override; | 310 void ResetDatabase() override; |
| 312 void UpdateStarted() override; | 311 void UpdateStarted() override; |
| 313 void UpdateFinished(bool success) override; | 312 void UpdateFinished(bool success) override; |
| 314 void GetChunks(GetChunksCallback callback) override; | 313 void GetChunks(GetChunksCallback callback) override; |
| 315 void AddChunks( | 314 void AddChunks( |
| 316 const std::string& list, | 315 const std::string& list, |
| 317 std::unique_ptr<std::vector<std::unique_ptr<SBChunkData>>> chunks, | 316 std::unique_ptr<std::vector<std::unique_ptr<SBChunkData>>> chunks, |
| 318 AddChunksCallback callback) override; | 317 AddChunksCallback callback) override; |
| 319 void DeleteChunks( | 318 void DeleteChunks( |
| 320 std::unique_ptr<std::vector<SBChunkDelete>> chunk_deletes) override; | 319 std::unique_ptr<std::vector<SBChunkDelete>> chunk_deletes) override; |
| 321 | 320 |
| 322 scoped_refptr<SafeBrowsingService> sb_service_; | 321 scoped_refptr<SafeBrowsingService> sb_service_; |
| 323 | 322 |
| 324 CurrentChecks checks_; | 323 std::map<SafeBrowsingCheck*, std::unique_ptr<SafeBrowsingCheck>> checks_; |
| 325 | 324 |
| 326 // Used for issuing only one GetHash request for a given prefix. | 325 // Used for issuing only one GetHash request for a given prefix. |
| 327 GetHashRequests gethash_requests_; | 326 GetHashRequests gethash_requests_; |
| 328 | 327 |
| 329 // The persistent database. We don't use a std::unique_ptr because it | 328 // The persistent database. We don't use a std::unique_ptr because it |
| 330 // needs to be destroyed on a different thread than this object. | 329 // needs to be destroyed on a different thread than this object. |
| 331 SafeBrowsingDatabase* database_; | 330 SafeBrowsingDatabase* database_; |
| 332 | 331 |
| 333 // Lock used to prevent possible data races due to compiler optimizations. | 332 // Lock used to prevent possible data races due to compiler optimizations. |
| 334 mutable base::Lock database_lock_; | 333 mutable base::Lock database_lock_; |
| 335 | 334 |
| 336 // Whether the service is running. 'enabled_' is used by the | 335 // Whether the service is running. 'enabled_' is used by the |
| 337 // SafeBrowsingDatabaseManager on the IO thread during normal operations. | 336 // SafeBrowsingDatabaseManager on the IO thread during normal operations. |
| 338 bool enabled_; | 337 bool enabled_; |
| 339 | 338 |
| 340 // Indicate if download_protection is enabled by command switch | 339 // Indicate if download_protection is enabled by command switch |
| 341 // so we allow this feature to be exersized. | 340 // so we allow this feature to be exercised. |
| 342 bool enable_download_protection_; | 341 bool enable_download_protection_; |
| 343 | 342 |
| 344 // Indicate if client-side phishing detection whitelist should be enabled | 343 // Indicate if client-side phishing detection whitelist should be enabled |
| 345 // or not. | 344 // or not. |
| 346 bool enable_csd_whitelist_; | 345 bool enable_csd_whitelist_; |
| 347 | 346 |
| 348 // Indicate if the download whitelist should be enabled or not. | 347 // Indicate if the download whitelist should be enabled or not. |
| 349 bool enable_download_whitelist_; | 348 bool enable_download_whitelist_; |
| 350 | 349 |
| 351 // Indicate if the extension blacklist should be enabled. | 350 // Indicate if the extension blacklist should be enabled. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 378 | 377 |
| 379 // Timeout to use for safe browsing checks. | 378 // Timeout to use for safe browsing checks. |
| 380 base::TimeDelta check_timeout_; | 379 base::TimeDelta check_timeout_; |
| 381 | 380 |
| 382 DISALLOW_COPY_AND_ASSIGN(LocalSafeBrowsingDatabaseManager); | 381 DISALLOW_COPY_AND_ASSIGN(LocalSafeBrowsingDatabaseManager); |
| 383 }; // class LocalSafeBrowsingDatabaseManager | 382 }; // class LocalSafeBrowsingDatabaseManager |
| 384 | 383 |
| 385 } // namespace safe_browsing | 384 } // namespace safe_browsing |
| 386 | 385 |
| 387 #endif // CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ | 386 #endif // CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ |
| OLD | NEW |