| 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> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/safe_browsing/download_protection_service.h" | 21 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 22 #include "chrome/browser/safe_browsing/incident_reporting/delayed_analysis_callb
ack.h" | 22 #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" | 23 #include "chrome/browser/safe_browsing/incident_reporting/delayed_callback_runne
r.h" |
| 24 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" | 24 #include "chrome/browser/safe_browsing/incident_reporting/download_metadata_mana
ger.h" |
| 25 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er.h" | 25 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er.h" |
| 26 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" | 26 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" |
| 27 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
| 29 | 29 |
| 30 class Profile; | 30 class Profile; |
| 31 class SafeBrowsingDatabaseManager; | |
| 32 class SafeBrowsingService; | |
| 33 class TrackedPreferenceValidationDelegate; | 31 class TrackedPreferenceValidationDelegate; |
| 34 | 32 |
| 35 namespace base { | 33 namespace base { |
| 36 class TaskRunner; | 34 class TaskRunner; |
| 37 } | 35 } |
| 38 | 36 |
| 39 namespace content { | 37 namespace content { |
| 40 class DownloadManager; | 38 class DownloadManager; |
| 41 class NotificationDetails; | 39 class NotificationDetails; |
| 42 class NotificationSource; | 40 class NotificationSource; |
| 43 } | 41 } |
| 44 | 42 |
| 45 namespace net { | 43 namespace net { |
| 46 class URLRequestContextGetter; | 44 class URLRequestContextGetter; |
| 47 } | 45 } |
| 48 | 46 |
| 49 namespace safe_browsing { | 47 namespace safe_browsing { |
| 50 | 48 |
| 51 class ClientDownloadRequest; | 49 class ClientDownloadRequest; |
| 52 class ClientIncidentReport; | 50 class ClientIncidentReport; |
| 53 class ClientIncidentReport_DownloadDetails; | 51 class ClientIncidentReport_DownloadDetails; |
| 54 class ClientIncidentReport_EnvironmentData; | 52 class ClientIncidentReport_EnvironmentData; |
| 55 class ClientIncidentReport_ExtensionData; | 53 class ClientIncidentReport_ExtensionData; |
| 56 class ClientIncidentReport_IncidentData; | 54 class ClientIncidentReport_IncidentData; |
| 57 class Incident; | 55 class Incident; |
| 58 class IncidentReceiver; | 56 class IncidentReceiver; |
| 57 class SafeBrowsingDatabaseManager; |
| 58 class SafeBrowsingService; |
| 59 | 59 |
| 60 // A class that manages the collection of incidents and submission of incident | 60 // A class that manages the collection of incidents and submission of incident |
| 61 // reports to the safe browsing client-side detection service. The service | 61 // reports to the safe browsing client-side detection service. The service |
| 62 // begins operation when an incident is reported via the AddIncident method. | 62 // begins operation when an incident is reported via the AddIncident method. |
| 63 // Incidents reported from a profile that is loading are held until the profile | 63 // Incidents reported from a profile that is loading are held until the profile |
| 64 // is fully created. Incidents originating from profiles that do not participate | 64 // is fully created. Incidents originating from profiles that do not participate |
| 65 // in safe browsing are dropped. Process-wide incidents are affiliated with a | 65 // in safe browsing are dropped. Process-wide incidents are affiliated with a |
| 66 // profile that participates in safe browsing when one becomes available. | 66 // profile that participates in safe browsing when one becomes available. |
| 67 // Following the addition of an incident that is not dropped, the service | 67 // Following the addition of an incident that is not dropped, the service |
| 68 // collects environmental data, finds the most recent binary download, and waits | 68 // collects environmental data, finds the most recent binary download, and waits |
| 69 // a bit. Additional incidents that arrive during this time are collated with | 69 // a bit. Additional incidents that arrive during this time are collated with |
| 70 // the initial incident. Finally, already-reported incidents are pruned and any | 70 // the initial incident. Finally, already-reported incidents are pruned and any |
| 71 // remaining are uploaded in an incident report. | 71 // remaining are uploaded in an incident report. |
| 72 class IncidentReportingService : public content::NotificationObserver { | 72 class IncidentReportingService : public content::NotificationObserver { |
| 73 public: | 73 public: |
| 74 IncidentReportingService(SafeBrowsingService* safe_browsing_service, | 74 IncidentReportingService( |
| 75 const scoped_refptr<net::URLRequestContextGetter>& | 75 safe_browsing::SafeBrowsingService* safe_browsing_service, |
| 76 request_context_getter); | 76 const scoped_refptr<net::URLRequestContextGetter>& |
| 77 request_context_getter); |
| 77 | 78 |
| 78 // All incident collection, data collection, and uploads in progress are | 79 // All incident collection, data collection, and uploads in progress are |
| 79 // dropped at destruction. | 80 // dropped at destruction. |
| 80 ~IncidentReportingService() override; | 81 ~IncidentReportingService() override; |
| 81 | 82 |
| 82 // Returns true if incident reporting is enabled for the given profile. | 83 // Returns true if incident reporting is enabled for the given profile. |
| 83 static bool IsEnabledForProfile(Profile* profile); | 84 static bool IsEnabledForProfile(Profile* profile); |
| 84 | 85 |
| 85 // Returns an object by which external components can add an incident to the | 86 // Returns an object by which external components can add an incident to the |
| 86 // service. The object may outlive the service, but will no longer have any | 87 // service. The object may outlive the service, but will no longer have any |
| (...skipping 15 matching lines...) Expand all Loading... |
| 102 void AddDownloadManager(content::DownloadManager* download_manager); | 103 void AddDownloadManager(content::DownloadManager* download_manager); |
| 103 | 104 |
| 104 protected: | 105 protected: |
| 105 // A pointer to a function that populates a protobuf with environment data. | 106 // A pointer to a function that populates a protobuf with environment data. |
| 106 typedef void (*CollectEnvironmentDataFn)( | 107 typedef void (*CollectEnvironmentDataFn)( |
| 107 ClientIncidentReport_EnvironmentData*); | 108 ClientIncidentReport_EnvironmentData*); |
| 108 | 109 |
| 109 // For testing so that the TaskRunner used for delayed analysis callbacks can | 110 // For testing so that the TaskRunner used for delayed analysis callbacks can |
| 110 // be specified. | 111 // be specified. |
| 111 IncidentReportingService( | 112 IncidentReportingService( |
| 112 SafeBrowsingService* safe_browsing_service, | 113 safe_browsing::SafeBrowsingService* safe_browsing_service, |
| 113 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 114 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 114 base::TimeDelta delayed_task_interval, | 115 base::TimeDelta delayed_task_interval, |
| 115 const scoped_refptr<base::TaskRunner>& delayed_task_runner); | 116 const scoped_refptr<base::TaskRunner>& delayed_task_runner); |
| 116 | 117 |
| 117 // Sets the function called by the service to collect environment data and the | 118 // Sets the function called by the service to collect environment data and the |
| 118 // task runner on which it is called. Used by unit tests to provide a fake | 119 // task runner on which it is called. Used by unit tests to provide a fake |
| 119 // environment data collector. | 120 // environment data collector. |
| 120 void SetCollectEnvironmentHook( | 121 void SetCollectEnvironmentHook( |
| 121 CollectEnvironmentDataFn collect_environment_data_hook, | 122 CollectEnvironmentDataFn collect_environment_data_hook, |
| 122 const scoped_refptr<base::TaskRunner>& task_runner); | 123 const scoped_refptr<base::TaskRunner>& task_runner); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 263 |
| 263 // content::NotificationObserver methods. | 264 // content::NotificationObserver methods. |
| 264 void Observe(int type, | 265 void Observe(int type, |
| 265 const content::NotificationSource& source, | 266 const content::NotificationSource& source, |
| 266 const content::NotificationDetails& details) override; | 267 const content::NotificationDetails& details) override; |
| 267 | 268 |
| 268 base::ThreadChecker thread_checker_; | 269 base::ThreadChecker thread_checker_; |
| 269 | 270 |
| 270 // The safe browsing database manager, through which the whitelist killswitch | 271 // The safe browsing database manager, through which the whitelist killswitch |
| 271 // is checked. | 272 // is checked. |
| 272 scoped_refptr<SafeBrowsingDatabaseManager> database_manager_; | 273 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_; |
| 273 | 274 |
| 274 // Accessor for an URL context with which reports will be sent. | 275 // Accessor for an URL context with which reports will be sent. |
| 275 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 276 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 276 | 277 |
| 277 // A pointer to a function that collects environment data. The function will | 278 // A pointer to a function that collects environment data. The function will |
| 278 // be run by |environment_collection_task_runner_|. This is ordinarily | 279 // be run by |environment_collection_task_runner_|. This is ordinarily |
| 279 // CollectEnvironmentData, but may be overridden by tests; see | 280 // CollectEnvironmentData, but may be overridden by tests; see |
| 280 // SetCollectEnvironmentHook. | 281 // SetCollectEnvironmentHook. |
| 281 CollectEnvironmentDataFn collect_environment_data_fn_; | 282 CollectEnvironmentDataFn collect_environment_data_fn_; |
| 282 | 283 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // that are posted during normal processing (e.g., environment collection, | 350 // that are posted during normal processing (e.g., environment collection, |
| 350 // safe browsing database checks, and report uploads). | 351 // safe browsing database checks, and report uploads). |
| 351 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; | 352 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; |
| 352 | 353 |
| 353 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); | 354 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); |
| 354 }; | 355 }; |
| 355 | 356 |
| 356 } // namespace safe_browsing | 357 } // namespace safe_browsing |
| 357 | 358 |
| 358 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE
RVICE_H_ | 359 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE
RVICE_H_ |
| OLD | NEW |