| 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 CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| 10 | 10 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 209 |
| 210 // protected for tests. | 210 // protected for tests. |
| 211 void NotifyDatabaseUpdateFinished(bool update_succeeded); | 211 void NotifyDatabaseUpdateFinished(bool update_succeeded); |
| 212 | 212 |
| 213 private: | 213 private: |
| 214 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; | 214 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; |
| 215 friend class SafeBrowsingServerTest; | 215 friend class SafeBrowsingServerTest; |
| 216 friend class SafeBrowsingServiceTest; | 216 friend class SafeBrowsingServiceTest; |
| 217 friend class SafeBrowsingServiceTestHelper; | 217 friend class SafeBrowsingServiceTestHelper; |
| 218 friend class SafeBrowsingDatabaseManagerTest; | 218 friend class SafeBrowsingDatabaseManagerTest; |
| 219 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, GetUrlThreatType); | 219 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 220 GetUrlSeverestThreatType); |
| 220 | 221 |
| 221 typedef std::set<SafeBrowsingCheck*> CurrentChecks; | 222 typedef std::set<SafeBrowsingCheck*> CurrentChecks; |
| 222 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; | 223 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; |
| 223 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; | 224 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; |
| 224 | 225 |
| 225 // Clients that we've queued up for checking later once the database is ready. | 226 // Clients that we've queued up for checking later once the database is ready. |
| 226 struct QueuedCheck { | 227 struct QueuedCheck { |
| 227 QueuedCheck(const safe_browsing_util::ListType check_type, | 228 QueuedCheck(const safe_browsing_util::ListType check_type, |
| 228 Client* client, | 229 Client* client, |
| 229 const GURL& url, | 230 const GURL& url, |
| 230 const std::vector<SBThreatType>& expected_threats, | 231 const std::vector<SBThreatType>& expected_threats, |
| 231 const base::TimeTicks& start); | 232 const base::TimeTicks& start); |
| 232 ~QueuedCheck(); | 233 ~QueuedCheck(); |
| 233 safe_browsing_util::ListType check_type; | 234 safe_browsing_util::ListType check_type; |
| 234 Client* client; | 235 Client* client; |
| 235 GURL url; | 236 GURL url; |
| 236 std::vector<SBThreatType> expected_threats; | 237 std::vector<SBThreatType> expected_threats; |
| 237 base::TimeTicks start; // When check was queued. | 238 base::TimeTicks start; // When check was queued. |
| 238 }; | 239 }; |
| 239 | 240 |
| 240 // Return the threat type from the first result in |full_hashes| which matches | 241 // Return the threat type of the severest entry in |full_hashes| which matches |
| 241 // |hash|, or SAFE if none match. | 242 // |hash|, or SAFE if none match. |
| 242 static SBThreatType GetHashThreatType( | 243 static SBThreatType GetHashSeverestThreatType( |
| 243 const SBFullHash& hash, | 244 const SBFullHash& hash, |
| 244 const std::vector<SBFullHashResult>& full_hashes); | 245 const std::vector<SBFullHashResult>& full_hashes); |
| 245 | 246 |
| 246 // Given a URL, compare all the possible host + path full hashes to the set of | 247 // Given a URL, compare all the possible host + path full hashes to the set of |
| 247 // provided full hashes. Returns the threat type of the matching result from | 248 // provided full hashes. Returns the threat type of the severest matching |
| 248 // |full_hashes|, or SAFE if none match. | 249 // result from |full_hashes|, or SAFE if none match. |
| 249 static SBThreatType GetUrlThreatType( | 250 static SBThreatType GetUrlSeverestThreatType( |
| 250 const GURL& url, | 251 const GURL& url, |
| 251 const std::vector<SBFullHashResult>& full_hashes, | 252 const std::vector<SBFullHashResult>& full_hashes, |
| 252 size_t* index); | 253 size_t* index); |
| 253 | 254 |
| 254 // Called to stop operations on the io_thread. This may be called multiple | 255 // Called to stop operations on the io_thread. This may be called multiple |
| 255 // times during the life of the DatabaseManager. Should be called on IO | 256 // times during the life of the DatabaseManager. Should be called on IO |
| 256 // thread. | 257 // thread. |
| 257 void DoStopOnIOThread(); | 258 void DoStopOnIOThread(); |
| 258 | 259 |
| 259 // Returns whether |database_| exists and is accessible. | 260 // Returns whether |database_| exists and is accessible. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 383 |
| 383 // Indicate if the extension blacklist should be enabled. | 384 // Indicate if the extension blacklist should be enabled. |
| 384 bool enable_extension_blacklist_; | 385 bool enable_extension_blacklist_; |
| 385 | 386 |
| 386 // Indicate if the side effect free whitelist should be enabled. | 387 // Indicate if the side effect free whitelist should be enabled. |
| 387 bool enable_side_effect_free_whitelist_; | 388 bool enable_side_effect_free_whitelist_; |
| 388 | 389 |
| 389 // Indicate if the csd malware IP blacklist should be enabled. | 390 // Indicate if the csd malware IP blacklist should be enabled. |
| 390 bool enable_ip_blacklist_; | 391 bool enable_ip_blacklist_; |
| 391 | 392 |
| 393 // Indicate if the unwanted software blacklist should be enabled. |
| 394 bool enable_unwanted_software_blacklist_; |
| 395 |
| 392 // The SafeBrowsing thread that runs database operations. | 396 // The SafeBrowsing thread that runs database operations. |
| 393 // | 397 // |
| 394 // Note: Functions that run on this thread should run synchronously and return | 398 // Note: Functions that run on this thread should run synchronously and return |
| 395 // to the IO thread, not post additional tasks back to this thread, lest we | 399 // to the IO thread, not post additional tasks back to this thread, lest we |
| 396 // cause a race condition at shutdown time that leads to a database leak. | 400 // cause a race condition at shutdown time that leads to a database leak. |
| 397 scoped_ptr<base::Thread> safe_browsing_thread_; | 401 scoped_ptr<base::Thread> safe_browsing_thread_; |
| 398 | 402 |
| 399 // Indicates if we're currently in an update cycle. | 403 // Indicates if we're currently in an update cycle. |
| 400 bool update_in_progress_; | 404 bool update_in_progress_; |
| 401 | 405 |
| 402 // When true, newly fetched chunks may not in the database yet since the | 406 // When true, newly fetched chunks may not in the database yet since the |
| 403 // database is still updating. | 407 // database is still updating. |
| 404 bool database_update_in_progress_; | 408 bool database_update_in_progress_; |
| 405 | 409 |
| 406 // Indicates if we're in the midst of trying to close the database. If this | 410 // Indicates if we're in the midst of trying to close the database. If this |
| 407 // is true, nothing on the IO thread should access the database. | 411 // is true, nothing on the IO thread should access the database. |
| 408 bool closing_database_; | 412 bool closing_database_; |
| 409 | 413 |
| 410 std::deque<QueuedCheck> queued_checks_; | 414 std::deque<QueuedCheck> queued_checks_; |
| 411 | 415 |
| 412 // Timeout to use for safe browsing checks. | 416 // Timeout to use for safe browsing checks. |
| 413 base::TimeDelta check_timeout_; | 417 base::TimeDelta check_timeout_; |
| 414 | 418 |
| 415 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager); | 419 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager); |
| 416 }; | 420 }; |
| 417 | 421 |
| 418 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ | 422 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ |
| OLD | NEW |