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