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* |
119 safe_browsing_detection_service() const { | 118 safe_browsing_detection_service() const { |
mattm
2015/11/12 00:36:05
Will this fit on a single line?
vakh (old account. dont use)
2015/11/12 09:27:42
Done.
| |
120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
121 return csd_service_.get(); | 120 return csd_service_.get(); |
122 } | 121 } |
123 | 122 |
124 // The DownloadProtectionService is not valid after the SafeBrowsingService | 123 // The DownloadProtectionService is not valid after the SafeBrowsingService |
125 // is destroyed. | 124 // is destroyed. |
126 safe_browsing::DownloadProtectionService* | 125 DownloadProtectionService* |
127 download_protection_service() const { | 126 download_protection_service() const { |
mattm
2015/11/12 00:36:05
Will this fit on a single line?
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 127 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
129 return download_service_.get(); | 128 return download_service_.get(); |
130 } | 129 } |
131 | 130 |
132 net::URLRequestContextGetter* url_request_context(); | 131 net::URLRequestContextGetter* url_request_context(); |
133 | 132 |
134 const scoped_refptr<SafeBrowsingUIManager>& ui_manager() const; | 133 const scoped_refptr<SafeBrowsingUIManager>& ui_manager() const; |
135 | 134 |
136 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager() const; | 135 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager() const; |
137 | 136 |
138 SafeBrowsingProtocolManager* protocol_manager() const; | 137 SafeBrowsingProtocolManager* protocol_manager() const; |
139 | 138 |
140 SafeBrowsingPingManager* ping_manager() const; | 139 SafeBrowsingPingManager* ping_manager() const; |
141 | 140 |
142 // Returns a preference validation delegate that adds incidents to the | 141 // Returns a preference validation delegate that adds incidents to the |
143 // incident reporting service for validation failures. Returns NULL if the | 142 // incident reporting service for validation failures. Returns NULL if the |
144 // service is not applicable for the given profile. | 143 // service is not applicable for the given profile. |
145 scoped_ptr<TrackedPreferenceValidationDelegate> | 144 scoped_ptr<TrackedPreferenceValidationDelegate> |
146 CreatePreferenceValidationDelegate(Profile* profile) const; | 145 CreatePreferenceValidationDelegate(Profile* profile) const; |
147 | 146 |
148 #if defined(FULL_SAFE_BROWSING) | 147 #if defined(FULL_SAFE_BROWSING) |
149 // Registers |callback| to be run after some delay following process launch. | 148 // Registers |callback| to be run after some delay following process launch. |
150 // |callback| will be dropped if the service is not applicable for the | 149 // |callback| will be dropped if the service is not applicable for the |
151 // process. | 150 // process. |
152 void RegisterDelayedAnalysisCallback( | 151 void RegisterDelayedAnalysisCallback( |
153 const safe_browsing::DelayedAnalysisCallback& callback); | 152 const DelayedAnalysisCallback& callback); |
mattm
2015/11/12 00:36:05
Will this fit on a single line?
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
154 #endif | 153 #endif |
155 | 154 |
156 // Adds |download_manager| to the set monitored by safe browsing. | 155 // Adds |download_manager| to the set monitored by safe browsing. |
157 void AddDownloadManager(content::DownloadManager* download_manager); | 156 void AddDownloadManager(content::DownloadManager* download_manager); |
158 | 157 |
159 // Observes resource requests made by the renderer and reports suspicious | 158 // Observes resource requests made by the renderer and reports suspicious |
160 // activity. | 159 // activity. |
161 void OnResourceRequest(const net::URLRequest* request); | 160 void OnResourceRequest(const net::URLRequest* request); |
162 | 161 |
163 // Type for subscriptions to SafeBrowsing service state. | 162 // Type for subscriptions to SafeBrowsing service state. |
164 typedef base::CallbackList<void(void)>::Subscription StateSubscription; | 163 typedef base::CallbackList<void(void)>::Subscription StateSubscription; |
165 | 164 |
166 // Adds a listener for when SafeBrowsing preferences might have changed. | 165 // Adds a listener for when SafeBrowsing preferences might have changed. |
167 // To get the current state, the callback should call enabled_by_prefs(). | 166 // To get the current state, the callback should call enabled_by_prefs(). |
168 // Should only be called on the UI thread. | 167 // Should only be called on the UI thread. |
169 scoped_ptr<StateSubscription> RegisterStateCallback( | 168 scoped_ptr<StateSubscription> RegisterStateCallback( |
170 const base::Callback<void(void)>& callback); | 169 const base::Callback<void(void)>& callback); |
171 | 170 |
172 protected: | 171 protected: |
173 // Creates the safe browsing service. Need to initialize before using. | 172 // Creates the safe browsing service. Need to initialize before using. |
174 SafeBrowsingService(); | 173 SafeBrowsingService(); |
175 | 174 |
176 ~SafeBrowsingService() override; | 175 ~SafeBrowsingService() override; |
177 | 176 |
178 virtual SafeBrowsingDatabaseManager* CreateDatabaseManager(); | 177 virtual SafeBrowsingDatabaseManager* CreateDatabaseManager(); |
179 | 178 |
180 virtual SafeBrowsingUIManager* CreateUIManager(); | 179 virtual SafeBrowsingUIManager* CreateUIManager(); |
181 | 180 |
182 #if defined(FULL_SAFE_BROWSING) | 181 #if defined(FULL_SAFE_BROWSING) |
183 virtual safe_browsing::IncidentReportingService* | 182 virtual IncidentReportingService* |
184 CreateIncidentReportingService(); | 183 CreateIncidentReportingService(); |
mattm
2015/11/12 00:36:05
This should fit on a single line
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
185 #endif | 184 #endif |
186 | 185 |
187 // Registers all the delayed analysis with the incident reporting service. | 186 // Registers all the delayed analysis with the incident reporting service. |
188 // This is where you register your process-wide, profile-independent analysis. | 187 // This is where you register your process-wide, profile-independent analysis. |
189 virtual void RegisterAllDelayedAnalysis(); | 188 virtual void RegisterAllDelayedAnalysis(); |
190 | 189 |
191 // Return a ptr to DatabaseManager's delegate, or NULL if it doesn't have one. | 190 // Return a ptr to DatabaseManager's delegate, or NULL if it doesn't have one. |
192 virtual SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate(); | 191 virtual SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate(); |
193 | 192 |
194 private: | 193 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. | 279 // Used to track creation and destruction of profiles on the UI thread. |
281 content::NotificationRegistrar prefs_registrar_; | 280 content::NotificationRegistrar prefs_registrar_; |
282 | 281 |
283 // Callbacks when SafeBrowsing state might have changed. | 282 // Callbacks when SafeBrowsing state might have changed. |
284 // Should only be accessed on the UI thread. | 283 // Should only be accessed on the UI thread. |
285 base::CallbackList<void(void)> state_callback_list_; | 284 base::CallbackList<void(void)> state_callback_list_; |
286 | 285 |
287 // The ClientSideDetectionService is managed by the SafeBrowsingService, | 286 // The ClientSideDetectionService is managed by the SafeBrowsingService, |
288 // since its running state and lifecycle depends on SafeBrowsingService's. | 287 // since its running state and lifecycle depends on SafeBrowsingService's. |
289 // Accessed on UI thread. | 288 // Accessed on UI thread. |
290 scoped_ptr<safe_browsing::ClientSideDetectionService> csd_service_; | 289 scoped_ptr<ClientSideDetectionService> csd_service_; |
291 | 290 |
292 // The DownloadProtectionService is managed by the SafeBrowsingService, | 291 // The DownloadProtectionService is managed by the SafeBrowsingService, |
293 // since its running state and lifecycle depends on SafeBrowsingService's. | 292 // since its running state and lifecycle depends on SafeBrowsingService's. |
294 // Accessed on UI thread. | 293 // Accessed on UI thread. |
295 scoped_ptr<safe_browsing::DownloadProtectionService> download_service_; | 294 scoped_ptr<DownloadProtectionService> download_service_; |
296 | 295 |
297 #if defined(FULL_SAFE_BROWSING) | 296 #if defined(FULL_SAFE_BROWSING) |
298 scoped_ptr<safe_browsing::IncidentReportingService> incident_service_; | 297 scoped_ptr<IncidentReportingService> incident_service_; |
299 #endif | 298 #endif |
300 | 299 |
301 // The UI manager handles showing interstitials. Accessed on both UI and IO | 300 // The UI manager handles showing interstitials. Accessed on both UI and IO |
302 // thread. | 301 // thread. |
303 scoped_refptr<SafeBrowsingUIManager> ui_manager_; | 302 scoped_refptr<SafeBrowsingUIManager> ui_manager_; |
304 | 303 |
305 // The database manager handles the database and download logic. Accessed on | 304 // The database manager handles the database and download logic. Accessed on |
306 // both UI and IO thread. | 305 // both UI and IO thread. |
307 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 306 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
308 | 307 |
309 #if defined(FULL_SAFE_BROWSING) | 308 #if defined(FULL_SAFE_BROWSING) |
310 scoped_ptr<safe_browsing::OffDomainInclusionDetector> | 309 scoped_ptr<OffDomainInclusionDetector> off_domain_inclusion_detector_; |
311 off_domain_inclusion_detector_; | |
312 | 310 |
313 scoped_ptr<safe_browsing::ResourceRequestDetector> resource_request_detector_; | 311 scoped_ptr<ResourceRequestDetector> resource_request_detector_; |
314 #endif | 312 #endif |
315 | 313 |
316 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); | 314 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |
317 }; | 315 }; |
318 | 316 |
319 // Factory for creating SafeBrowsingService. Useful for tests. | 317 // Factory for creating SafeBrowsingService. Useful for tests. |
320 class SafeBrowsingServiceFactory { | 318 class SafeBrowsingServiceFactory { |
321 public: | 319 public: |
322 SafeBrowsingServiceFactory() { } | 320 SafeBrowsingServiceFactory() { } |
323 virtual ~SafeBrowsingServiceFactory() { } | 321 virtual ~SafeBrowsingServiceFactory() { } |
324 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; | 322 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; |
325 private: | 323 private: |
326 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); | 324 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); |
327 }; | 325 }; |
328 | 326 |
327 } // namespace safe_browsing | |
328 | |
329 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 329 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
OLD | NEW |