| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_SAFE_BROWSING_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <deque> | 12 #include <deque> |
| 13 #include <map> |
| 13 #include <set> | 14 #include <set> |
| 14 #include <string> | 15 #include <string> |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 #include "base/hash_tables.h" | 18 #include "base/hash_tables.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 21 #include "base/task.h" | 22 #include "base/task.h" |
| 22 #include "base/time.h" | 23 #include "base/time.h" |
| 23 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 24 #include "content/common/notification_observer.h" | 25 #include "content/common/notification_observer.h" |
| 25 #include "content/common/notification_registrar.h" | 26 #include "content/common/notification_registrar.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 | 28 |
| 28 class MalwareDetails; | 29 class MalwareDetails; |
| 30 class PrefChangeRegistrar; |
| 29 class PrefService; | 31 class PrefService; |
| 30 class SafeBrowsingDatabase; | 32 class SafeBrowsingDatabase; |
| 31 class SafeBrowsingProtocolManager; | 33 class SafeBrowsingProtocolManager; |
| 32 class SafeBrowsingServiceFactory; | 34 class SafeBrowsingServiceFactory; |
| 33 | 35 |
| 34 namespace base { | 36 namespace base { |
| 35 class Thread; | 37 class Thread; |
| 36 } | 38 } |
| 37 | 39 |
| 38 namespace net { | 40 namespace net { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 222 |
| 221 // The blocking page on the UI thread has completed. | 223 // The blocking page on the UI thread has completed. |
| 222 void OnBlockingPageDone(const std::vector<UnsafeResource>& resources, | 224 void OnBlockingPageDone(const std::vector<UnsafeResource>& resources, |
| 223 bool proceed); | 225 bool proceed); |
| 224 | 226 |
| 225 // Called on the UI thread when the SafeBrowsingProtocolManager has received | 227 // Called on the UI thread when the SafeBrowsingProtocolManager has received |
| 226 // updated MAC keys. | 228 // updated MAC keys. |
| 227 void OnNewMacKeys(const std::string& client_key, | 229 void OnNewMacKeys(const std::string& client_key, |
| 228 const std::string& wrapped_key); | 230 const std::string& wrapped_key); |
| 229 | 231 |
| 230 // Notification on the UI thread from the advanced options UI. | |
| 231 void OnEnable(bool enabled); | |
| 232 | |
| 233 bool enabled() const { return enabled_; } | 232 bool enabled() const { return enabled_; } |
| 234 | 233 |
| 235 bool download_protection_enabled() const { | 234 bool download_protection_enabled() const { |
| 236 return enabled_ && enable_download_protection_; | 235 return enabled_ && enable_download_protection_; |
| 237 } | 236 } |
| 238 | 237 |
| 239 // Preference handling. | 238 // Preference handling. |
| 240 static void RegisterPrefs(PrefService* prefs); | 239 static void RegisterPrefs(PrefService* prefs); |
| 241 | 240 |
| 242 // Called on the IO thread to reset the database. | 241 // Called on the IO thread to reset the database. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 int64 timeout_ms); | 410 int64 timeout_ms); |
| 412 | 411 |
| 413 // Adds the given entry to the whitelist. Called on the UI thread. | 412 // Adds the given entry to the whitelist. Called on the UI thread. |
| 414 void UpdateWhitelist(const UnsafeResource& resource); | 413 void UpdateWhitelist(const UnsafeResource& resource); |
| 415 | 414 |
| 416 // NotificationObserver override | 415 // NotificationObserver override |
| 417 virtual void Observe(int type, | 416 virtual void Observe(int type, |
| 418 const NotificationSource& source, | 417 const NotificationSource& source, |
| 419 const NotificationDetails& details) OVERRIDE; | 418 const NotificationDetails& details) OVERRIDE; |
| 420 | 419 |
| 420 // Starts following the safe browsing preference on |pref_service|. |
| 421 void AddPrefService(PrefService* pref_service); |
| 422 |
| 423 // Stop following the safe browsing preference on |pref_service|. |
| 424 void RemovePrefService(PrefService* pref_service); |
| 425 |
| 426 // Checks if any profile is currently using the safe browsing service, and |
| 427 // starts or stops the service accordingly. |
| 428 void RefreshState(); |
| 429 |
| 421 // The factory used to instanciate a SafeBrowsingService object. | 430 // The factory used to instanciate a SafeBrowsingService object. |
| 422 // Useful for tests, so they can provide their own implementation of | 431 // Useful for tests, so they can provide their own implementation of |
| 423 // SafeBrowsingService. | 432 // SafeBrowsingService. |
| 424 static SafeBrowsingServiceFactory* factory_; | 433 static SafeBrowsingServiceFactory* factory_; |
| 425 | 434 |
| 426 CurrentChecks checks_; | 435 CurrentChecks checks_; |
| 427 | 436 |
| 428 // Used for issuing only one GetHash request for a given prefix. | 437 // Used for issuing only one GetHash request for a given prefix. |
| 429 GetHashRequests gethash_requests_; | 438 GetHashRequests gethash_requests_; |
| 430 | 439 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 482 |
| 474 std::deque<QueuedCheck> queued_checks_; | 483 std::deque<QueuedCheck> queued_checks_; |
| 475 | 484 |
| 476 // When download url check takes this long, client's callback will be called | 485 // When download url check takes this long, client's callback will be called |
| 477 // without waiting for the result. | 486 // without waiting for the result. |
| 478 int64 download_urlcheck_timeout_ms_; | 487 int64 download_urlcheck_timeout_ms_; |
| 479 | 488 |
| 480 // Similar to |download_urlcheck_timeout_ms_|, but for download hash checks. | 489 // Similar to |download_urlcheck_timeout_ms_|, but for download hash checks. |
| 481 int64 download_hashcheck_timeout_ms_; | 490 int64 download_hashcheck_timeout_ms_; |
| 482 | 491 |
| 492 // Used to track purge memory notifications. Lives on the IO thread. |
| 483 NotificationRegistrar registrar_; | 493 NotificationRegistrar registrar_; |
| 484 | 494 |
| 495 // Tracks existing PrefServices, and the safe browsing preference on each. |
| 496 // This is used to determine if any profile is currently using the safe |
| 497 // browsing service, and to start it up or shut it down accordingly. |
| 498 std::map<PrefService*, PrefChangeRegistrar*> prefs_map_; |
| 499 |
| 500 // Used to track creation and destruction of profiles on the UI thread. |
| 501 NotificationRegistrar prefs_registrar_; |
| 502 |
| 485 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); | 503 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |
| 486 }; | 504 }; |
| 487 | 505 |
| 488 // Factory for creating SafeBrowsingService. Useful for tests. | 506 // Factory for creating SafeBrowsingService. Useful for tests. |
| 489 class SafeBrowsingServiceFactory { | 507 class SafeBrowsingServiceFactory { |
| 490 public: | 508 public: |
| 491 SafeBrowsingServiceFactory() { } | 509 SafeBrowsingServiceFactory() { } |
| 492 virtual ~SafeBrowsingServiceFactory() { } | 510 virtual ~SafeBrowsingServiceFactory() { } |
| 493 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; | 511 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; |
| 494 private: | 512 private: |
| 495 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); | 513 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); |
| 496 }; | 514 }; |
| 497 | 515 |
| 498 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 516 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| OLD | NEW |