| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SERVI
CE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SERVI
CE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SERVI
CE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SERVI
CE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
| 21 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 21 #include "chrome/browser/safe_browsing/incident_reporting/add_incident_callback.
h" | 22 #include "chrome/browser/safe_browsing/incident_reporting/add_incident_callback.
h" |
| 22 #include "chrome/browser/safe_browsing/incident_reporting/delayed_analysis_callb
ack.h" | 23 #include "chrome/browser/safe_browsing/incident_reporting/delayed_analysis_callb
ack.h" |
| 23 #include "chrome/browser/safe_browsing/incident_reporting/delayed_callback_runne
r.h" | 24 #include "chrome/browser/safe_browsing/incident_reporting/delayed_callback_runne
r.h" |
| 25 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" |
| 24 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er.h" | 26 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er.h" |
| 25 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" | 27 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" |
| 26 #include "content/public/browser/notification_observer.h" | 28 #include "content/public/browser/notification_observer.h" |
| 27 #include "content/public/browser/notification_registrar.h" | 29 #include "content/public/browser/notification_registrar.h" |
| 28 | 30 |
| 29 class Profile; | 31 class Profile; |
| 30 class SafeBrowsingDatabaseManager; | 32 class SafeBrowsingDatabaseManager; |
| 31 class SafeBrowsingService; | 33 class SafeBrowsingService; |
| 32 class TrackedPreferenceValidationDelegate; | 34 class TrackedPreferenceValidationDelegate; |
| 33 | 35 |
| 34 namespace base { | 36 namespace base { |
| 35 class TaskRunner; | 37 class TaskRunner; |
| 36 } | 38 } |
| 37 | 39 |
| 38 namespace content { | 40 namespace content { |
| 41 class DownloadManager; |
| 39 class NotificationDetails; | 42 class NotificationDetails; |
| 40 class NotificationSource; | 43 class NotificationSource; |
| 41 } | 44 } |
| 42 | 45 |
| 43 namespace net { | 46 namespace net { |
| 44 class URLRequestContextGetter; | 47 class URLRequestContextGetter; |
| 45 } | 48 } |
| 46 | 49 |
| 47 namespace safe_browsing { | 50 namespace safe_browsing { |
| 48 | 51 |
| 52 class ClientDownloadRequest; |
| 49 class ClientIncidentReport; | 53 class ClientIncidentReport; |
| 50 class ClientIncidentReport_DownloadDetails; | 54 class ClientIncidentReport_DownloadDetails; |
| 51 class ClientIncidentReport_EnvironmentData; | 55 class ClientIncidentReport_EnvironmentData; |
| 52 class ClientIncidentReport_IncidentData; | 56 class ClientIncidentReport_IncidentData; |
| 53 | 57 |
| 54 // A class that manages the collection of incidents and submission of incident | 58 // A class that manages the collection of incidents and submission of incident |
| 55 // reports to the safe browsing client-side detection service. The service | 59 // reports to the safe browsing client-side detection service. The service |
| 56 // begins operation when an incident is reported via the AddIncident method. | 60 // begins operation when an incident is reported via the AddIncident method. |
| 57 // Incidents reported from a profile that is loading are held until the profile | 61 // Incidents reported from a profile that is loading are held until the profile |
| 58 // is fully created. Incidents originating from profiles that do not participate | 62 // is fully created. Incidents originating from profiles that do not participate |
| (...skipping 24 matching lines...) Expand all Loading... |
| 83 // for validation failures in |profile|. The delegate may outlive the service, | 87 // for validation failures in |profile|. The delegate may outlive the service, |
| 84 // but incidents reported by it will no longer have any effect after the | 88 // but incidents reported by it will no longer have any effect after the |
| 85 // service is deleted. The lifetime of the delegate should not extend beyond | 89 // service is deleted. The lifetime of the delegate should not extend beyond |
| 86 // that of the profile it services. | 90 // that of the profile it services. |
| 87 scoped_ptr<TrackedPreferenceValidationDelegate> | 91 scoped_ptr<TrackedPreferenceValidationDelegate> |
| 88 CreatePreferenceValidationDelegate(Profile* profile); | 92 CreatePreferenceValidationDelegate(Profile* profile); |
| 89 | 93 |
| 90 // Registers |callback| to be run after some delay following process launch. | 94 // Registers |callback| to be run after some delay following process launch. |
| 91 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback); | 95 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback); |
| 92 | 96 |
| 97 // Adds |download_manager| to the set monitored for client download request |
| 98 // storage. |
| 99 void AddDownloadManager(content::DownloadManager* download_manager); |
| 100 |
| 93 protected: | 101 protected: |
| 94 // A pointer to a function that populates a protobuf with environment data. | 102 // A pointer to a function that populates a protobuf with environment data. |
| 95 typedef void (*CollectEnvironmentDataFn)( | 103 typedef void (*CollectEnvironmentDataFn)( |
| 96 ClientIncidentReport_EnvironmentData*); | 104 ClientIncidentReport_EnvironmentData*); |
| 97 | 105 |
| 98 // For testing so that the TaskRunner used for delayed analysis callbacks can | 106 // For testing so that the TaskRunner used for delayed analysis callbacks can |
| 99 // be specified. | 107 // be specified. |
| 100 IncidentReportingService( | 108 IncidentReportingService( |
| 101 SafeBrowsingService* safe_browsing_service, | 109 SafeBrowsingService* safe_browsing_service, |
| 102 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 110 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void OnKillSwitchResult(UploadContext* context, bool is_killswitch_on); | 233 void OnKillSwitchResult(UploadContext* context, bool is_killswitch_on); |
| 226 | 234 |
| 227 // Performs processing for a report after succesfully receiving a response. | 235 // Performs processing for a report after succesfully receiving a response. |
| 228 void HandleResponse(const UploadContext& context); | 236 void HandleResponse(const UploadContext& context); |
| 229 | 237 |
| 230 // IncidentReportUploader::OnResultCallback implementation. | 238 // IncidentReportUploader::OnResultCallback implementation. |
| 231 void OnReportUploadResult(UploadContext* context, | 239 void OnReportUploadResult(UploadContext* context, |
| 232 IncidentReportUploader::Result result, | 240 IncidentReportUploader::Result result, |
| 233 scoped_ptr<ClientIncidentResponse> response); | 241 scoped_ptr<ClientIncidentResponse> response); |
| 234 | 242 |
| 243 // DownloadProtectionService::ClientDownloadRequestCallback implementation. |
| 244 void OnClientDownloadRequest(content::DownloadItem* download, |
| 245 const ClientDownloadRequest* request); |
| 246 |
| 235 // content::NotificationObserver methods. | 247 // content::NotificationObserver methods. |
| 236 virtual void Observe(int type, | 248 virtual void Observe(int type, |
| 237 const content::NotificationSource& source, | 249 const content::NotificationSource& source, |
| 238 const content::NotificationDetails& details) override; | 250 const content::NotificationDetails& details) override; |
| 239 | 251 |
| 240 base::ThreadChecker thread_checker_; | 252 base::ThreadChecker thread_checker_; |
| 241 | 253 |
| 242 // The safe browsing database manager, through which the whitelist killswitch | 254 // The safe browsing database manager, through which the whitelist killswitch |
| 243 // is checked. | 255 // is checked. |
| 244 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 256 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; |
| 245 | 257 |
| 246 // Accessor for an URL context with which reports will be sent. | 258 // Accessor for an URL context with which reports will be sent. |
| 247 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 259 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 248 | 260 |
| 249 // A pointer to a function that collects environment data. The function will | 261 // A pointer to a function that collects environment data. The function will |
| 250 // be run by |environment_collection_task_runner_|. This is ordinarily | 262 // be run by |environment_collection_task_runner_|. This is ordinarily |
| 251 // CollectEnvironmentData, but may be overridden by tests; see | 263 // CollectEnvironmentData, but may be overridden by tests; see |
| 252 // SetCollectEnvironmentHook. | 264 // SetCollectEnvironmentHook. |
| 253 CollectEnvironmentDataFn collect_environment_data_fn_; | 265 CollectEnvironmentDataFn collect_environment_data_fn_; |
| 254 | 266 |
| 255 // The task runner on which environment collection takes place. This is | 267 // The task runner on which environment collection takes place. This is |
| 256 // ordinarily a runner in the browser's blocking pool that will skip the | 268 // ordinarily a runner in the browser's blocking pool that will skip the |
| 257 // collection task at shutdown if it has not yet started. | 269 // collection task at shutdown if it has not yet started. |
| 258 scoped_refptr<base::TaskRunner> environment_collection_task_runner_; | 270 scoped_refptr<base::TaskRunner> environment_collection_task_runner_; |
| 259 | 271 |
| 260 // Registrar for observing profile lifecycle notifications. | 272 // Registrar for observing profile lifecycle notifications. |
| 261 content::NotificationRegistrar notification_registrar_; | 273 content::NotificationRegistrar notification_registrar_; |
| 262 | 274 |
| 275 // A subscription for ClientDownloadRequests, used to persist them for later |
| 276 // use. |
| 277 DownloadProtectionService::ClientDownloadRequestSubscription |
| 278 client_download_request_subscription_; |
| 279 |
| 263 // True when the asynchronous environment collection task has been fired off | 280 // True when the asynchronous environment collection task has been fired off |
| 264 // but has not yet completed. | 281 // but has not yet completed. |
| 265 bool environment_collection_pending_; | 282 bool environment_collection_pending_; |
| 266 | 283 |
| 267 // True when an incident has been received and the service is waiting for the | 284 // True when an incident has been received and the service is waiting for the |
| 268 // collation_timer_ to fire. | 285 // collation_timer_ to fire. |
| 269 bool collation_timeout_pending_; | 286 bool collation_timeout_pending_; |
| 270 | 287 |
| 271 // A timer upon the firing of which the service will report received | 288 // A timer upon the firing of which the service will report received |
| 272 // incidents. | 289 // incidents. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 289 // The time at which download collection was initiated. | 306 // The time at which download collection was initiated. |
| 290 base::TimeTicks last_download_begin_; | 307 base::TimeTicks last_download_begin_; |
| 291 | 308 |
| 292 // Context data for all on-the-record profiles plus the process-wide (NULL) | 309 // Context data for all on-the-record profiles plus the process-wide (NULL) |
| 293 // context. | 310 // context. |
| 294 ProfileContextCollection profiles_; | 311 ProfileContextCollection profiles_; |
| 295 | 312 |
| 296 // Callbacks registered for performing delayed analysis. | 313 // Callbacks registered for performing delayed analysis. |
| 297 DelayedCallbackRunner delayed_analysis_callbacks_; | 314 DelayedCallbackRunner delayed_analysis_callbacks_; |
| 298 | 315 |
| 316 DownloadMetadataManager download_metadata_manager_; |
| 317 |
| 299 // The collection of uploads in progress. | 318 // The collection of uploads in progress. |
| 300 ScopedVector<UploadContext> uploads_; | 319 ScopedVector<UploadContext> uploads_; |
| 301 | 320 |
| 302 // An object that asynchronously searches for the most recent binary download. | 321 // An object that asynchronously searches for the most recent binary download. |
| 303 // Non-NULL while such a search is outstanding. | 322 // Non-NULL while such a search is outstanding. |
| 304 scoped_ptr<LastDownloadFinder> last_download_finder_; | 323 scoped_ptr<LastDownloadFinder> last_download_finder_; |
| 305 | 324 |
| 306 // A factory for handing out weak pointers for AddIncident callbacks. | 325 // A factory for handing out weak pointers for AddIncident callbacks. |
| 307 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; | 326 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; |
| 308 | 327 |
| 309 // A factory for handing out weak pointers for internal asynchronous tasks | 328 // A factory for handing out weak pointers for internal asynchronous tasks |
| 310 // that are posted during normal processing (e.g., environment collection, | 329 // that are posted during normal processing (e.g., environment collection, |
| 311 // safe browsing database checks, and report uploads). | 330 // safe browsing database checks, and report uploads). |
| 312 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; | 331 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; |
| 313 | 332 |
| 314 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); | 333 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); |
| 315 }; | 334 }; |
| 316 | 335 |
| 317 } // namespace safe_browsing | 336 } // namespace safe_browsing |
| 318 | 337 |
| 319 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE
RVICE_H_ | 338 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE
RVICE_H_ |
| OLD | NEW |