| 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_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 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 24 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 25 | 25 |
| 26 #if defined(FULL_SAFE_BROWSING) | 26 #if defined(FULL_SAFE_BROWSING) |
| 27 #include "chrome/browser/safe_browsing/incident_reporting/delayed_analysis_callb
ack.h" | 27 #include "chrome/browser/safe_browsing/incident_reporting/delayed_analysis_callb
ack.h" |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 class PrefChangeRegistrar; | 30 class PrefChangeRegistrar; |
| 31 class PrefService; | 31 class PrefService; |
| 32 class Profile; | 32 class Profile; |
| 33 struct SafeBrowsingProtocolConfig; | |
| 34 class SafeBrowsingDatabaseManager; | |
| 35 class SafeBrowsingPingManager; | |
| 36 class SafeBrowsingProtocolManager; | |
| 37 class SafeBrowsingProtocolManagerDelegate; | |
| 38 class SafeBrowsingServiceFactory; | |
| 39 class SafeBrowsingUIManager; | |
| 40 class SafeBrowsingURLRequestContextGetter; | |
| 41 class TrackedPreferenceValidationDelegate; | 33 class TrackedPreferenceValidationDelegate; |
| 42 | 34 |
| 43 namespace base { | 35 namespace base { |
| 44 class Thread; | 36 class Thread; |
| 45 } | 37 } |
| 46 | 38 |
| 47 namespace content { | 39 namespace content { |
| 48 class DownloadManager; | 40 class DownloadManager; |
| 49 } | 41 } |
| 50 | 42 |
| 51 namespace net { | 43 namespace net { |
| 52 class URLRequest; | 44 class URLRequest; |
| 53 class URLRequestContext; | 45 class URLRequestContext; |
| 54 class URLRequestContextGetter; | 46 class URLRequestContextGetter; |
| 55 } | 47 } |
| 56 | 48 |
| 57 namespace safe_browsing { | 49 namespace safe_browsing { |
| 58 class ClientSideDetectionService; | 50 class ClientSideDetectionService; |
| 59 class DownloadProtectionService; | 51 class DownloadProtectionService; |
| 52 struct SafeBrowsingProtocolConfig; |
| 53 class SafeBrowsingDatabaseManager; |
| 54 class SafeBrowsingPingManager; |
| 55 class SafeBrowsingProtocolManager; |
| 56 class SafeBrowsingProtocolManagerDelegate; |
| 57 class SafeBrowsingServiceFactory; |
| 58 class SafeBrowsingUIManager; |
| 59 class SafeBrowsingURLRequestContextGetter; |
| 60 | 60 |
| 61 #if defined(FULL_SAFE_BROWSING) | 61 #if defined(FULL_SAFE_BROWSING) |
| 62 class IncidentReportingService; | 62 class IncidentReportingService; |
| 63 class OffDomainInclusionDetector; | 63 class OffDomainInclusionDetector; |
| 64 class ResourceRequestDetector; | 64 class ResourceRequestDetector; |
| 65 #endif | 65 #endif |
| 66 } // namespace safe_browsing | |
| 67 | 66 |
| 68 // Construction needs to happen on the main thread. | 67 // Construction needs to happen on the main thread. |
| 69 // The SafeBrowsingService owns both the UI and Database managers which do | 68 // The SafeBrowsingService owns both the UI and Database managers which do |
| 70 // the heavylifting of safebrowsing service. Both of these managers stay | 69 // the heavylifting of safebrowsing service. Both of these managers stay |
| 71 // alive until SafeBrowsingService is destroyed, however, they are disabled | 70 // alive until SafeBrowsingService is destroyed, however, they are disabled |
| 72 // permanently when Shutdown method is called. | 71 // permanently when Shutdown method is called. |
| 73 class SafeBrowsingService | 72 class SafeBrowsingService |
| 74 : public base::RefCountedThreadSafe< | 73 : public base::RefCountedThreadSafe< |
| 75 SafeBrowsingService, | 74 SafeBrowsingService, |
| 76 content::BrowserThread::DeleteOnUIThread>, | 75 content::BrowserThread::DeleteOnUIThread>, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 107 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 109 return enabled_; | 108 return enabled_; |
| 110 } | 109 } |
| 111 | 110 |
| 112 // Whether the service is enabled by the current set of profiles. | 111 // Whether the service is enabled by the current set of profiles. |
| 113 bool enabled_by_prefs() const { | 112 bool enabled_by_prefs() const { |
| 114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 113 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 115 return enabled_by_prefs_; | 114 return enabled_by_prefs_; |
| 116 } | 115 } |
| 117 | 116 |
| 118 safe_browsing::ClientSideDetectionService* | 117 ClientSideDetectionService* safe_browsing_detection_service() const { |
| 119 safe_browsing_detection_service() const { | |
| 120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 121 return csd_service_.get(); | 119 return csd_service_.get(); |
| 122 } | 120 } |
| 123 | 121 |
| 124 // The DownloadProtectionService is not valid after the SafeBrowsingService | 122 // The DownloadProtectionService is not valid after the SafeBrowsingService |
| 125 // is destroyed. | 123 // is destroyed. |
| 126 safe_browsing::DownloadProtectionService* | 124 DownloadProtectionService* download_protection_service() const { |
| 127 download_protection_service() const { | |
| 128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 125 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 129 return download_service_.get(); | 126 return download_service_.get(); |
| 130 } | 127 } |
| 131 | 128 |
| 132 net::URLRequestContextGetter* url_request_context(); | 129 net::URLRequestContextGetter* url_request_context(); |
| 133 | 130 |
| 134 const scoped_refptr<SafeBrowsingUIManager>& ui_manager() const; | 131 const scoped_refptr<SafeBrowsingUIManager>& ui_manager() const; |
| 135 | 132 |
| 136 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager() const; | 133 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager() const; |
| 137 | 134 |
| 138 SafeBrowsingProtocolManager* protocol_manager() const; | 135 SafeBrowsingProtocolManager* protocol_manager() const; |
| 139 | 136 |
| 140 SafeBrowsingPingManager* ping_manager() const; | 137 SafeBrowsingPingManager* ping_manager() const; |
| 141 | 138 |
| 142 // Returns a preference validation delegate that adds incidents to the | 139 // Returns a preference validation delegate that adds incidents to the |
| 143 // incident reporting service for validation failures. Returns NULL if the | 140 // incident reporting service for validation failures. Returns NULL if the |
| 144 // service is not applicable for the given profile. | 141 // service is not applicable for the given profile. |
| 145 scoped_ptr<TrackedPreferenceValidationDelegate> | 142 scoped_ptr<TrackedPreferenceValidationDelegate> |
| 146 CreatePreferenceValidationDelegate(Profile* profile) const; | 143 CreatePreferenceValidationDelegate(Profile* profile) const; |
| 147 | 144 |
| 148 #if defined(FULL_SAFE_BROWSING) | 145 #if defined(FULL_SAFE_BROWSING) |
| 149 // Registers |callback| to be run after some delay following process launch. | 146 // Registers |callback| to be run after some delay following process launch. |
| 150 // |callback| will be dropped if the service is not applicable for the | 147 // |callback| will be dropped if the service is not applicable for the |
| 151 // process. | 148 // process. |
| 152 void RegisterDelayedAnalysisCallback( | 149 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback); |
| 153 const safe_browsing::DelayedAnalysisCallback& callback); | |
| 154 #endif | 150 #endif |
| 155 | 151 |
| 156 // Adds |download_manager| to the set monitored by safe browsing. | 152 // Adds |download_manager| to the set monitored by safe browsing. |
| 157 void AddDownloadManager(content::DownloadManager* download_manager); | 153 void AddDownloadManager(content::DownloadManager* download_manager); |
| 158 | 154 |
| 159 // Observes resource requests made by the renderer and reports suspicious | 155 // Observes resource requests made by the renderer and reports suspicious |
| 160 // activity. | 156 // activity. |
| 161 void OnResourceRequest(const net::URLRequest* request); | 157 void OnResourceRequest(const net::URLRequest* request); |
| 162 | 158 |
| 163 // Type for subscriptions to SafeBrowsing service state. | 159 // Type for subscriptions to SafeBrowsing service state. |
| 164 typedef base::CallbackList<void(void)>::Subscription StateSubscription; | 160 typedef base::CallbackList<void(void)>::Subscription StateSubscription; |
| 165 | 161 |
| 166 // Adds a listener for when SafeBrowsing preferences might have changed. | 162 // Adds a listener for when SafeBrowsing preferences might have changed. |
| 167 // To get the current state, the callback should call enabled_by_prefs(). | 163 // To get the current state, the callback should call enabled_by_prefs(). |
| 168 // Should only be called on the UI thread. | 164 // Should only be called on the UI thread. |
| 169 scoped_ptr<StateSubscription> RegisterStateCallback( | 165 scoped_ptr<StateSubscription> RegisterStateCallback( |
| 170 const base::Callback<void(void)>& callback); | 166 const base::Callback<void(void)>& callback); |
| 171 | 167 |
| 172 protected: | 168 protected: |
| 173 // Creates the safe browsing service. Need to initialize before using. | 169 // Creates the safe browsing service. Need to initialize before using. |
| 174 SafeBrowsingService(); | 170 SafeBrowsingService(); |
| 175 | 171 |
| 176 ~SafeBrowsingService() override; | 172 ~SafeBrowsingService() override; |
| 177 | 173 |
| 178 virtual SafeBrowsingDatabaseManager* CreateDatabaseManager(); | 174 virtual SafeBrowsingDatabaseManager* CreateDatabaseManager(); |
| 179 | 175 |
| 180 virtual SafeBrowsingUIManager* CreateUIManager(); | 176 virtual SafeBrowsingUIManager* CreateUIManager(); |
| 181 | 177 |
| 182 #if defined(FULL_SAFE_BROWSING) | 178 #if defined(FULL_SAFE_BROWSING) |
| 183 virtual safe_browsing::IncidentReportingService* | 179 virtual IncidentReportingService* CreateIncidentReportingService(); |
| 184 CreateIncidentReportingService(); | |
| 185 #endif | 180 #endif |
| 186 | 181 |
| 187 // Registers all the delayed analysis with the incident reporting service. | 182 // Registers all the delayed analysis with the incident reporting service. |
| 188 // This is where you register your process-wide, profile-independent analysis. | 183 // This is where you register your process-wide, profile-independent analysis. |
| 189 virtual void RegisterAllDelayedAnalysis(); | 184 virtual void RegisterAllDelayedAnalysis(); |
| 190 | 185 |
| 191 // Return a ptr to DatabaseManager's delegate, or NULL if it doesn't have one. | 186 // Return a ptr to DatabaseManager's delegate, or NULL if it doesn't have one. |
| 192 virtual SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate(); | 187 virtual SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate(); |
| 193 | 188 |
| 194 private: | 189 private: |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Used to track creation and destruction of profiles on the UI thread. | 275 // Used to track creation and destruction of profiles on the UI thread. |
| 281 content::NotificationRegistrar prefs_registrar_; | 276 content::NotificationRegistrar prefs_registrar_; |
| 282 | 277 |
| 283 // Callbacks when SafeBrowsing state might have changed. | 278 // Callbacks when SafeBrowsing state might have changed. |
| 284 // Should only be accessed on the UI thread. | 279 // Should only be accessed on the UI thread. |
| 285 base::CallbackList<void(void)> state_callback_list_; | 280 base::CallbackList<void(void)> state_callback_list_; |
| 286 | 281 |
| 287 // The ClientSideDetectionService is managed by the SafeBrowsingService, | 282 // The ClientSideDetectionService is managed by the SafeBrowsingService, |
| 288 // since its running state and lifecycle depends on SafeBrowsingService's. | 283 // since its running state and lifecycle depends on SafeBrowsingService's. |
| 289 // Accessed on UI thread. | 284 // Accessed on UI thread. |
| 290 scoped_ptr<safe_browsing::ClientSideDetectionService> csd_service_; | 285 scoped_ptr<ClientSideDetectionService> csd_service_; |
| 291 | 286 |
| 292 // The DownloadProtectionService is managed by the SafeBrowsingService, | 287 // The DownloadProtectionService is managed by the SafeBrowsingService, |
| 293 // since its running state and lifecycle depends on SafeBrowsingService's. | 288 // since its running state and lifecycle depends on SafeBrowsingService's. |
| 294 // Accessed on UI thread. | 289 // Accessed on UI thread. |
| 295 scoped_ptr<safe_browsing::DownloadProtectionService> download_service_; | 290 scoped_ptr<DownloadProtectionService> download_service_; |
| 296 | 291 |
| 297 #if defined(FULL_SAFE_BROWSING) | 292 #if defined(FULL_SAFE_BROWSING) |
| 298 scoped_ptr<safe_browsing::IncidentReportingService> incident_service_; | 293 scoped_ptr<IncidentReportingService> incident_service_; |
| 299 #endif | 294 #endif |
| 300 | 295 |
| 301 // The UI manager handles showing interstitials. Accessed on both UI and IO | 296 // The UI manager handles showing interstitials. Accessed on both UI and IO |
| 302 // thread. | 297 // thread. |
| 303 scoped_refptr<SafeBrowsingUIManager> ui_manager_; | 298 scoped_refptr<SafeBrowsingUIManager> ui_manager_; |
| 304 | 299 |
| 305 // The database manager handles the database and download logic. Accessed on | 300 // The database manager handles the database and download logic. Accessed on |
| 306 // both UI and IO thread. | 301 // both UI and IO thread. |
| 307 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 302 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 308 | 303 |
| 309 #if defined(FULL_SAFE_BROWSING) | 304 #if defined(FULL_SAFE_BROWSING) |
| 310 scoped_ptr<safe_browsing::OffDomainInclusionDetector> | 305 scoped_ptr<OffDomainInclusionDetector> off_domain_inclusion_detector_; |
| 311 off_domain_inclusion_detector_; | |
| 312 | 306 |
| 313 scoped_ptr<safe_browsing::ResourceRequestDetector> resource_request_detector_; | 307 scoped_ptr<ResourceRequestDetector> resource_request_detector_; |
| 314 #endif | 308 #endif |
| 315 | 309 |
| 316 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); | 310 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |
| 317 }; | 311 }; |
| 318 | 312 |
| 319 // Factory for creating SafeBrowsingService. Useful for tests. | 313 // Factory for creating SafeBrowsingService. Useful for tests. |
| 320 class SafeBrowsingServiceFactory { | 314 class SafeBrowsingServiceFactory { |
| 321 public: | 315 public: |
| 322 SafeBrowsingServiceFactory() { } | 316 SafeBrowsingServiceFactory() { } |
| 323 virtual ~SafeBrowsingServiceFactory() { } | 317 virtual ~SafeBrowsingServiceFactory() { } |
| 324 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; | 318 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; |
| 325 private: | 319 private: |
| 326 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); | 320 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); |
| 327 }; | 321 }; |
| 328 | 322 |
| 323 } // namespace safe_browsing |
| 324 |
| 329 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 325 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
| OLD | NEW |