Chromium Code Reviews| 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 <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/hash_tables.h" | 17 #include "base/hash_tables.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/observer_list.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; |
| 29 class PrefService; | 30 class PrefService; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // this class. | 98 // this class. |
| 98 // TODO(lzheng): We should consider to use this time out check | 99 // TODO(lzheng): We should consider to use this time out check |
| 99 // for browsing too (instead of implementin in | 100 // for browsing too (instead of implementin in |
| 100 // safe_browsing_resource_handler.cc). | 101 // safe_browsing_resource_handler.cc). |
| 101 CancelableTask* timeout_task; | 102 CancelableTask* timeout_task; |
| 102 | 103 |
| 103 private: | 104 private: |
| 104 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingCheck); | 105 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingCheck); |
| 105 }; | 106 }; |
| 106 | 107 |
| 108 // Observer class can be used to get notified when a SafeBrowsing hit | |
| 109 // was found. | |
| 110 class Observer { | |
| 111 public: | |
| 112 Observer() {} | |
|
Brian Ryner
2011/07/19 21:27:10
Since this should always be subclassed, make the c
noelutz
2011/07/19 22:28:08
Done.
| |
| 113 virtual ~Observer() {} | |
| 114 // The |resource| must not be accessed after OnSafeBrowsingHit returns. | |
| 115 // This method will be called on the UI thread. | |
| 116 virtual void OnSafeBrowsingHit(const UnsafeResource& resource) = 0; | |
| 117 | |
| 118 private: | |
| 119 DISALLOW_COPY_AND_ASSIGN(Observer); | |
| 120 }; | |
| 121 | |
| 107 class Client { | 122 class Client { |
| 108 public: | 123 public: |
| 109 virtual ~Client() {} | 124 virtual ~Client() {} |
| 110 | 125 |
| 111 void OnSafeBrowsingResult(const SafeBrowsingCheck& check); | 126 void OnSafeBrowsingResult(const SafeBrowsingCheck& check); |
| 112 | 127 |
| 113 // Called when the user has made a decision about how to handle the | 128 // Called when the user has made a decision about how to handle the |
| 114 // SafeBrowsing interstitial page. | 129 // SafeBrowsing interstitial page. |
| 115 virtual void OnBlockingPageComplete(bool proceed) {} | 130 virtual void OnBlockingPageComplete(bool proceed) {} |
| 116 | 131 |
| 117 protected: | 132 protected: |
| 118 // Called when the result of checking a browse URL is known. | 133 // Called when the result of checking a browse URL is known. |
| 119 virtual void OnBrowseUrlCheckResult(const GURL& url, | 134 virtual void OnBrowseUrlCheckResult(const GURL& url, |
| 120 UrlCheckResult result) {} | 135 UrlCheckResult result) {} |
| 121 | 136 |
| 122 // Called when the result of checking a download URL is known. | 137 // Called when the result of checking a download URL is known. |
| 123 virtual void OnDownloadUrlCheckResult(const std::vector<GURL>& url_chain, | 138 virtual void OnDownloadUrlCheckResult(const std::vector<GURL>& url_chain, |
| 124 UrlCheckResult result) {} | 139 UrlCheckResult result) {} |
| 125 | 140 |
| 126 // Called when the result of checking a download binary hash is known. | 141 // Called when the result of checking a download binary hash is known. |
| 127 virtual void OnDownloadHashCheckResult(const std::string& hash, | 142 virtual void OnDownloadHashCheckResult(const std::string& hash, |
| 128 UrlCheckResult result) {} | 143 UrlCheckResult result) {} |
| 129 }; | 144 }; |
| 130 | 145 |
| 131 | |
| 132 // Makes the passed |factory| the factory used to instanciate | 146 // Makes the passed |factory| the factory used to instanciate |
| 133 // a SafeBrowsingService. Useful for tests. | 147 // a SafeBrowsingService. Useful for tests. |
| 134 static void RegisterFactory(SafeBrowsingServiceFactory* factory) { | 148 static void RegisterFactory(SafeBrowsingServiceFactory* factory) { |
| 135 factory_ = factory; | 149 factory_ = factory; |
| 136 } | 150 } |
| 137 | 151 |
| 138 // Create an instance of the safe browsing service. | 152 // Create an instance of the safe browsing service. |
| 139 static SafeBrowsingService* CreateSafeBrowsingService(); | 153 static SafeBrowsingService* CreateSafeBrowsingService(); |
| 140 | 154 |
| 141 // Called on the UI thread to initialize the service. | 155 // Called on the UI thread to initialize the service. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 // Report hits to the unsafe contents (malware, phishing, unsafe download URL) | 269 // Report hits to the unsafe contents (malware, phishing, unsafe download URL) |
| 256 // to the server. Can only be called on UI thread. If |post_data| is | 270 // to the server. Can only be called on UI thread. If |post_data| is |
| 257 // non-empty, the request will be sent as a POST instead of a GET. | 271 // non-empty, the request will be sent as a POST instead of a GET. |
| 258 virtual void ReportSafeBrowsingHit(const GURL& malicious_url, | 272 virtual void ReportSafeBrowsingHit(const GURL& malicious_url, |
| 259 const GURL& page_url, | 273 const GURL& page_url, |
| 260 const GURL& referrer_url, | 274 const GURL& referrer_url, |
| 261 bool is_subresource, | 275 bool is_subresource, |
| 262 UrlCheckResult threat_type, | 276 UrlCheckResult threat_type, |
| 263 const std::string& post_data); | 277 const std::string& post_data); |
| 264 | 278 |
| 279 // Add and remove observers. These methods must be invoked on the UI thread. | |
| 280 void AddObserver(Observer* observer); | |
| 281 void RemoveObserver(Observer* remove); | |
| 282 | |
| 265 protected: | 283 protected: |
| 266 // Creates the safe browsing service. Need to initialize before using. | 284 // Creates the safe browsing service. Need to initialize before using. |
| 267 SafeBrowsingService(); | 285 SafeBrowsingService(); |
| 268 | 286 |
| 269 virtual ~SafeBrowsingService(); | 287 virtual ~SafeBrowsingService(); |
| 270 | 288 |
| 271 private: | 289 private: |
| 272 friend class SafeBrowsingServiceFactoryImpl; | 290 friend class SafeBrowsingServiceFactoryImpl; |
| 273 | 291 |
| 274 typedef std::set<SafeBrowsingCheck*> CurrentChecks; | 292 typedef std::set<SafeBrowsingCheck*> CurrentChecks; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 | 491 |
| 474 std::deque<QueuedCheck> queued_checks_; | 492 std::deque<QueuedCheck> queued_checks_; |
| 475 | 493 |
| 476 // When download url check takes this long, client's callback will be called | 494 // When download url check takes this long, client's callback will be called |
| 477 // without waiting for the result. | 495 // without waiting for the result. |
| 478 int64 download_urlcheck_timeout_ms_; | 496 int64 download_urlcheck_timeout_ms_; |
| 479 | 497 |
| 480 // Similar to |download_urlcheck_timeout_ms_|, but for download hash checks. | 498 // Similar to |download_urlcheck_timeout_ms_|, but for download hash checks. |
| 481 int64 download_hashcheck_timeout_ms_; | 499 int64 download_hashcheck_timeout_ms_; |
| 482 | 500 |
| 501 ObserverList<Observer> observer_list_; | |
| 483 NotificationRegistrar registrar_; | 502 NotificationRegistrar registrar_; |
| 484 | 503 |
| 485 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); | 504 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |
| 486 }; | 505 }; |
| 487 | 506 |
| 488 // Factory for creating SafeBrowsingService. Useful for tests. | 507 // Factory for creating SafeBrowsingService. Useful for tests. |
| 489 class SafeBrowsingServiceFactory { | 508 class SafeBrowsingServiceFactory { |
| 490 public: | 509 public: |
| 491 SafeBrowsingServiceFactory() { } | 510 SafeBrowsingServiceFactory() { } |
| 492 virtual ~SafeBrowsingServiceFactory() { } | 511 virtual ~SafeBrowsingServiceFactory() { } |
| 493 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; | 512 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; |
| 494 private: | 513 private: |
| 495 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); | 514 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); |
| 496 }; | 515 }; |
| 497 | 516 |
| 498 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 517 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| OLD | NEW |