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/download_protection_service.h" |
22 #include "chrome/browser/safe_browsing/incident_reporting/add_incident_callback.
h" | |
23 #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" |
24 #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" |
25 #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" |
26 #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" |
27 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" | 26 #include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h
" |
28 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
30 | 29 |
31 class Profile; | 30 class Profile; |
32 class SafeBrowsingDatabaseManager; | 31 class SafeBrowsingDatabaseManager; |
(...skipping 14 matching lines...) Expand all Loading... |
47 class URLRequestContextGetter; | 46 class URLRequestContextGetter; |
48 } | 47 } |
49 | 48 |
50 namespace safe_browsing { | 49 namespace safe_browsing { |
51 | 50 |
52 class ClientDownloadRequest; | 51 class ClientDownloadRequest; |
53 class ClientIncidentReport; | 52 class ClientIncidentReport; |
54 class ClientIncidentReport_DownloadDetails; | 53 class ClientIncidentReport_DownloadDetails; |
55 class ClientIncidentReport_EnvironmentData; | 54 class ClientIncidentReport_EnvironmentData; |
56 class ClientIncidentReport_IncidentData; | 55 class ClientIncidentReport_IncidentData; |
| 56 class Incident; |
| 57 class IncidentReceiver; |
57 | 58 |
58 // A class that manages the collection of incidents and submission of incident | 59 // A class that manages the collection of incidents and submission of incident |
59 // reports to the safe browsing client-side detection service. The service | 60 // reports to the safe browsing client-side detection service. The service |
60 // begins operation when an incident is reported via the AddIncident method. | 61 // begins operation when an incident is reported via the AddIncident method. |
61 // Incidents reported from a profile that is loading are held until the profile | 62 // Incidents reported from a profile that is loading are held until the profile |
62 // is fully created. Incidents originating from profiles that do not participate | 63 // is fully created. Incidents originating from profiles that do not participate |
63 // in safe browsing are dropped. Process-wide incidents are affiliated with a | 64 // in safe browsing are dropped. Process-wide incidents are affiliated with a |
64 // profile that participates in safe browsing when one becomes available. | 65 // profile that participates in safe browsing when one becomes available. |
65 // Following the addition of an incident that is not dropped, the service | 66 // Following the addition of an incident that is not dropped, the service |
66 // collects environmental data, finds the most recent binary download, and waits | 67 // collects environmental data, finds the most recent binary download, and waits |
67 // a bit. Additional incidents that arrive during this time are collated with | 68 // a bit. Additional incidents that arrive during this time are collated with |
68 // the initial incident. Finally, already-reported incidents are pruned and any | 69 // the initial incident. Finally, already-reported incidents are pruned and any |
69 // remaining are uploaded in an incident report. | 70 // remaining are uploaded in an incident report. |
70 class IncidentReportingService : public content::NotificationObserver { | 71 class IncidentReportingService : public content::NotificationObserver { |
71 public: | 72 public: |
72 IncidentReportingService(SafeBrowsingService* safe_browsing_service, | 73 IncidentReportingService(SafeBrowsingService* safe_browsing_service, |
73 const scoped_refptr<net::URLRequestContextGetter>& | 74 const scoped_refptr<net::URLRequestContextGetter>& |
74 request_context_getter); | 75 request_context_getter); |
75 | 76 |
76 // All incident collection, data collection, and uploads in progress are | 77 // All incident collection, data collection, and uploads in progress are |
77 // dropped at destruction. | 78 // dropped at destruction. |
78 ~IncidentReportingService() override; | 79 ~IncidentReportingService() override; |
79 | 80 |
80 // Returns a callback by which external components can add an incident to the | 81 // Returns an object by which external components can add an incident to the |
81 // service on behalf of |profile|. The callback may outlive the service, but | 82 // service. The object may outlive the service, but will no longer have any |
82 // will no longer have any effect after the service is deleted. The callback | 83 // effect after the service is deleted. |
83 // must not be run after |profile| has been destroyed. | 84 scoped_ptr<IncidentReceiver> GetIncidentReceiver(); |
84 AddIncidentCallback GetAddIncidentCallback(Profile* profile); | |
85 | 85 |
86 // Returns a preference validation delegate that adds incidents to the service | 86 // Returns a preference validation delegate that adds incidents to the service |
87 // for validation failures in |profile|. The delegate may outlive the service, | 87 // for validation failures in |profile|. The delegate may outlive the service, |
88 // 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 |
89 // service is deleted. The lifetime of the delegate should not extend beyond | 89 // service is deleted. |
90 // that of the profile it services. | |
91 scoped_ptr<TrackedPreferenceValidationDelegate> | 90 scoped_ptr<TrackedPreferenceValidationDelegate> |
92 CreatePreferenceValidationDelegate(Profile* profile); | 91 CreatePreferenceValidationDelegate(Profile* profile); |
93 | 92 |
94 // Registers |callback| to be run after some delay following process launch. | 93 // Registers |callback| to be run after some delay following process launch. |
95 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback); | 94 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback); |
96 | 95 |
97 // Adds |download_manager| to the set monitored for client download request | 96 // Adds |download_manager| to the set monitored for client download request |
98 // storage. | 97 // storage. |
99 void AddDownloadManager(content::DownloadManager* download_manager); | 98 void AddDownloadManager(content::DownloadManager* download_manager); |
100 | 99 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const IncidentReportUploader::OnResultCallback& callback, | 135 const IncidentReportUploader::OnResultCallback& callback, |
137 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 136 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
138 const ClientIncidentReport& report); | 137 const ClientIncidentReport& report); |
139 | 138 |
140 // Returns true if a report is currently being processed. | 139 // Returns true if a report is currently being processed. |
141 bool IsProcessingReport() const; | 140 bool IsProcessingReport() const; |
142 | 141 |
143 private: | 142 private: |
144 struct ProfileContext; | 143 struct ProfileContext; |
145 class UploadContext; | 144 class UploadContext; |
| 145 class Receiver; |
146 | 146 |
147 // A mapping of profiles to contexts holding state about received incidents. | 147 // A mapping of profiles to contexts holding state about received incidents. |
148 typedef std::map<Profile*, ProfileContext*> ProfileContextCollection; | 148 typedef std::map<Profile*, ProfileContext*> ProfileContextCollection; |
149 | 149 |
150 // Returns the context for |profile|, creating it if it does not exist. | 150 // Returns the context for |profile|, creating it if it does not exist. |
151 ProfileContext* GetOrCreateProfileContext(Profile* profile); | 151 ProfileContext* GetOrCreateProfileContext(Profile* profile); |
152 | 152 |
153 // Returns the context for |profile|, or NULL if it is unknown. | 153 // Returns the context for |profile|, or NULL if it is unknown. |
154 ProfileContext* GetProfileContext(Profile* profile); | 154 ProfileContext* GetProfileContext(Profile* profile); |
155 | 155 |
156 // Handles the destruction of a profile. Incidents reported for the profile | 156 // Handles the destruction of a profile. Incidents reported for the profile |
157 // but not yet uploaded are dropped. | 157 // but not yet uploaded are dropped. |
158 void OnProfileDestroyed(Profile* profile); | 158 void OnProfileDestroyed(Profile* profile); |
159 | 159 |
160 // Returns an initialized profile that participates in safe browsing. Profiles | 160 // Returns an initialized profile that participates in safe browsing. Profiles |
161 // participating in extended safe browsing are preferred. | 161 // participating in extended safe browsing are preferred. |
162 Profile* FindEligibleProfile() const; | 162 Profile* FindEligibleProfile() const; |
163 | 163 |
164 // Adds |incident_data| to the service. The incident_time_msec field is | 164 // Adds |incident_data| relating to the optional |profile| to the service. |
165 // populated with the current time if the caller has not already done so. | |
166 void AddIncident(Profile* profile, scoped_ptr<Incident> incident); | 165 void AddIncident(Profile* profile, scoped_ptr<Incident> incident); |
167 | 166 |
168 // Begins processing a report. If processing is already underway, ensures that | 167 // Begins processing a report. If processing is already underway, ensures that |
169 // collection tasks have completed or are running. | 168 // collection tasks have completed or are running. |
170 void BeginReportProcessing(); | 169 void BeginReportProcessing(); |
171 | 170 |
172 // Begins the process of collating incidents by waiting for incidents to | 171 // Begins the process of collating incidents by waiting for incidents to |
173 // arrive. This function is idempotent. | 172 // arrive. This function is idempotent. |
174 void BeginIncidentCollation(); | 173 void BeginIncidentCollation(); |
175 | 174 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 313 |
315 DownloadMetadataManager download_metadata_manager_; | 314 DownloadMetadataManager download_metadata_manager_; |
316 | 315 |
317 // The collection of uploads in progress. | 316 // The collection of uploads in progress. |
318 ScopedVector<UploadContext> uploads_; | 317 ScopedVector<UploadContext> uploads_; |
319 | 318 |
320 // An object that asynchronously searches for the most recent binary download. | 319 // An object that asynchronously searches for the most recent binary download. |
321 // Non-NULL while such a search is outstanding. | 320 // Non-NULL while such a search is outstanding. |
322 scoped_ptr<LastDownloadFinder> last_download_finder_; | 321 scoped_ptr<LastDownloadFinder> last_download_finder_; |
323 | 322 |
324 // A factory for handing out weak pointers for AddIncident callbacks. | 323 // A factory for handing out weak pointers for IncidentReceiver objects. |
325 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; | 324 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; |
326 | 325 |
327 // A factory for handing out weak pointers for internal asynchronous tasks | 326 // A factory for handing out weak pointers for internal asynchronous tasks |
328 // that are posted during normal processing (e.g., environment collection, | 327 // that are posted during normal processing (e.g., environment collection, |
329 // safe browsing database checks, and report uploads). | 328 // safe browsing database checks, and report uploads). |
330 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; | 329 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; |
331 | 330 |
332 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); | 331 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); |
333 }; | 332 }; |
334 | 333 |
335 } // namespace safe_browsing | 334 } // namespace safe_browsing |
336 | 335 |
337 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE
RVICE_H_ | 336 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE
RVICE_H_ |
OLD | NEW |