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 <map> |
14 #include <set> | 14 #include <set> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/hash_tables.h" | 18 #include "base/hash_tables.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
22 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
23 #include "base/task.h" | 23 #include "base/task.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 26 #include "content/browser/browser_thread.h" |
26 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
27 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
29 | 30 |
30 class MalwareDetails; | 31 class MalwareDetails; |
31 class PrefChangeRegistrar; | 32 class PrefChangeRegistrar; |
32 class PrefService; | 33 class PrefService; |
33 class SafeBrowsingDatabase; | 34 class SafeBrowsingDatabase; |
34 class SafeBrowsingProtocolManager; | 35 class SafeBrowsingProtocolManager; |
35 class SafeBrowsingServiceFactory; | 36 class SafeBrowsingServiceFactory; |
36 | 37 |
37 namespace base { | 38 namespace base { |
38 class Thread; | 39 class Thread; |
39 } | 40 } |
40 | 41 |
41 namespace net { | 42 namespace net { |
42 class URLRequestContextGetter; | 43 class URLRequestContextGetter; |
43 } | 44 } |
44 | 45 |
45 namespace safe_browsing { | 46 namespace safe_browsing { |
46 class ClientSideDetectionService; | 47 class ClientSideDetectionService; |
47 class DownloadProtectionService; | 48 class DownloadProtectionService; |
48 } | 49 } |
49 | 50 |
50 // Construction needs to happen on the main thread. | 51 // Construction needs to happen on the main thread. |
51 class SafeBrowsingService | 52 class SafeBrowsingService |
52 : public base::RefCountedThreadSafe<SafeBrowsingService>, | 53 : public base::RefCountedThreadSafe<SafeBrowsingService, |
| 54 BrowserThread::DeleteOnUIThread>, |
53 public content::NotificationObserver { | 55 public content::NotificationObserver { |
54 public: | 56 public: |
55 class Client; | 57 class Client; |
56 // Users of this service implement this interface to be notified | 58 // Users of this service implement this interface to be notified |
57 // asynchronously of the result. | 59 // asynchronously of the result. |
58 enum UrlCheckResult { | 60 enum UrlCheckResult { |
59 SAFE, | 61 SAFE, |
60 URL_PHISHING, | 62 URL_PHISHING, |
61 URL_MALWARE, | 63 URL_MALWARE, |
62 BINARY_MALWARE_URL, // Binary url leads to a malware. | 64 BINARY_MALWARE_URL, // Binary url leads to a malware. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 262 |
261 bool download_protection_enabled() const { | 263 bool download_protection_enabled() const { |
262 return enabled_ && enable_download_protection_; | 264 return enabled_ && enable_download_protection_; |
263 } | 265 } |
264 | 266 |
265 safe_browsing::ClientSideDetectionService* | 267 safe_browsing::ClientSideDetectionService* |
266 safe_browsing_detection_service() const { | 268 safe_browsing_detection_service() const { |
267 return csd_service_.get(); | 269 return csd_service_.get(); |
268 } | 270 } |
269 | 271 |
| 272 // The DownloadProtectionService is not valid after the SafeBrowsingService |
| 273 // is destroyed. |
270 safe_browsing::DownloadProtectionService* | 274 safe_browsing::DownloadProtectionService* |
271 download_protection_service() const { | 275 download_protection_service() const { |
272 return download_service_.get(); | 276 return download_service_.get(); |
273 } | 277 } |
274 | 278 |
275 // Preference handling. | 279 // Preference handling. |
276 static void RegisterPrefs(PrefService* prefs); | 280 static void RegisterPrefs(PrefService* prefs); |
277 | 281 |
278 // Called on the IO thread to reset the database. | 282 // Called on the IO thread to reset the database. |
279 void ResetDatabase(); | 283 void ResetDatabase(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Used for whitelisting a render view when the user ignores our warning. | 322 // Used for whitelisting a render view when the user ignores our warning. |
319 struct WhiteListedEntry; | 323 struct WhiteListedEntry; |
320 | 324 |
321 // Clients that we've queued up for checking later once the database is ready. | 325 // Clients that we've queued up for checking later once the database is ready. |
322 struct QueuedCheck { | 326 struct QueuedCheck { |
323 Client* client; | 327 Client* client; |
324 GURL url; | 328 GURL url; |
325 base::TimeTicks start; // When check was queued. | 329 base::TimeTicks start; // When check was queued. |
326 }; | 330 }; |
327 | 331 |
328 friend class base::RefCountedThreadSafe<SafeBrowsingService>; | 332 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 333 friend class DeleteTask<SafeBrowsingService>; |
329 friend class SafeBrowsingServiceTest; | 334 friend class SafeBrowsingServiceTest; |
330 | 335 |
331 // Called to initialize objects that are used on the io_thread. | 336 // Called to initialize objects that are used on the io_thread. |
332 void OnIOInitialize(const std::string& client_key, | 337 void OnIOInitialize(const std::string& client_key, |
333 const std::string& wrapped_key, | 338 const std::string& wrapped_key, |
334 net::URLRequestContextGetter* request_context_getter); | 339 net::URLRequestContextGetter* request_context_getter); |
335 | 340 |
336 // Called to shutdown operations on the io_thread. | 341 // Called to shutdown operations on the io_thread. |
337 void OnIOShutdown(); | 342 void OnIOShutdown(); |
338 | 343 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 554 |
550 // Used to track creation and destruction of profiles on the UI thread. | 555 // Used to track creation and destruction of profiles on the UI thread. |
551 content::NotificationRegistrar prefs_registrar_; | 556 content::NotificationRegistrar prefs_registrar_; |
552 | 557 |
553 // The ClientSideDetectionService is managed by the SafeBrowsingService, | 558 // The ClientSideDetectionService is managed by the SafeBrowsingService, |
554 // since its running state and lifecycle depends on SafeBrowsingService's. | 559 // since its running state and lifecycle depends on SafeBrowsingService's. |
555 scoped_ptr<safe_browsing::ClientSideDetectionService> csd_service_; | 560 scoped_ptr<safe_browsing::ClientSideDetectionService> csd_service_; |
556 | 561 |
557 // The DownloadProtectionService is managed by the SafeBrowsingService, | 562 // The DownloadProtectionService is managed by the SafeBrowsingService, |
558 // since its running state and lifecycle depends on SafeBrowsingService's. | 563 // since its running state and lifecycle depends on SafeBrowsingService's. |
559 scoped_refptr<safe_browsing::DownloadProtectionService> download_service_; | 564 scoped_ptr<safe_browsing::DownloadProtectionService> download_service_; |
560 | 565 |
561 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); | 566 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |
562 }; | 567 }; |
563 | 568 |
564 // Factory for creating SafeBrowsingService. Useful for tests. | 569 // Factory for creating SafeBrowsingService. Useful for tests. |
565 class SafeBrowsingServiceFactory { | 570 class SafeBrowsingServiceFactory { |
566 public: | 571 public: |
567 SafeBrowsingServiceFactory() { } | 572 SafeBrowsingServiceFactory() { } |
568 virtual ~SafeBrowsingServiceFactory() { } | 573 virtual ~SafeBrowsingServiceFactory() { } |
569 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; | 574 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; |
570 private: | 575 private: |
571 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); | 576 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); |
572 }; | 577 }; |
573 | 578 |
574 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 579 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
OLD | NEW |