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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_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/add_incident_callback.h" | 21 #include "chrome/browser/safe_browsing/add_incident_callback.h" |
| 22 #include "chrome/browser/safe_browsing/delayed_analysis_callback.h" |
| 23 #include "chrome/browser/safe_browsing/delayed_callback_runner.h" |
22 #include "chrome/browser/safe_browsing/incident_report_uploader.h" | 24 #include "chrome/browser/safe_browsing/incident_report_uploader.h" |
23 #include "chrome/browser/safe_browsing/last_download_finder.h" | 25 #include "chrome/browser/safe_browsing/last_download_finder.h" |
24 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
26 | 28 |
27 class Profile; | 29 class Profile; |
28 class SafeBrowsingDatabaseManager; | 30 class SafeBrowsingDatabaseManager; |
29 class SafeBrowsingService; | 31 class SafeBrowsingService; |
30 class TrackedPreferenceValidationDelegate; | 32 class TrackedPreferenceValidationDelegate; |
31 | 33 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 AddIncidentCallback GetAddIncidentCallback(Profile* profile); | 78 AddIncidentCallback GetAddIncidentCallback(Profile* profile); |
77 | 79 |
78 // Returns a preference validation delegate that adds incidents to the service | 80 // Returns a preference validation delegate that adds incidents to the service |
79 // for validation failures in |profile|. The delegate may outlive the service, | 81 // for validation failures in |profile|. The delegate may outlive the service, |
80 // but incidents reported by it will no longer have any effect after the | 82 // but incidents reported by it will no longer have any effect after the |
81 // service is deleted. The lifetime of the delegate should not extend beyond | 83 // service is deleted. The lifetime of the delegate should not extend beyond |
82 // that of the profile it services. | 84 // that of the profile it services. |
83 scoped_ptr<TrackedPreferenceValidationDelegate> | 85 scoped_ptr<TrackedPreferenceValidationDelegate> |
84 CreatePreferenceValidationDelegate(Profile* profile); | 86 CreatePreferenceValidationDelegate(Profile* profile); |
85 | 87 |
| 88 // Registers |callback| to be run after some delay following process launch. |
| 89 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback); |
| 90 |
86 protected: | 91 protected: |
87 // A pointer to a function that populates a protobuf with environment data. | 92 // A pointer to a function that populates a protobuf with environment data. |
88 typedef void (*CollectEnvironmentDataFn)( | 93 typedef void (*CollectEnvironmentDataFn)( |
89 ClientIncidentReport_EnvironmentData*); | 94 ClientIncidentReport_EnvironmentData*); |
90 | 95 |
91 // Sets the function called by the service to collect environment data and the | 96 // Sets the function called by the service to collect environment data and the |
92 // task runner on which it is called. Used by unit tests to provide a fake | 97 // task runner on which it is called. Used by unit tests to provide a fake |
93 // environment data collector. | 98 // environment data collector. |
94 void SetCollectEnvironmentHook( | 99 void SetCollectEnvironmentHook( |
95 CollectEnvironmentDataFn collect_environment_data_hook, | 100 CollectEnvironmentDataFn collect_environment_data_hook, |
(...skipping 28 matching lines...) Expand all Loading... |
124 // Returns the context for |profile|, creating it if it does not exist. | 129 // Returns the context for |profile|, creating it if it does not exist. |
125 ProfileContext* GetOrCreateProfileContext(Profile* profile); | 130 ProfileContext* GetOrCreateProfileContext(Profile* profile); |
126 | 131 |
127 // Returns the context for |profile|, or NULL if it is unknown. | 132 // Returns the context for |profile|, or NULL if it is unknown. |
128 ProfileContext* GetProfileContext(Profile* profile); | 133 ProfileContext* GetProfileContext(Profile* profile); |
129 | 134 |
130 // Handles the destruction of a profile. Incidents reported for the profile | 135 // Handles the destruction of a profile. Incidents reported for the profile |
131 // but not yet uploaded are dropped. | 136 // but not yet uploaded are dropped. |
132 void OnProfileDestroyed(Profile* profile); | 137 void OnProfileDestroyed(Profile* profile); |
133 | 138 |
| 139 // Returns an initialized profile that participates in safe browsing. Profiles |
| 140 // participating in extended safe browsing are preferred. |
| 141 Profile* FindEligibleProfile() const; |
| 142 |
134 // Adds |incident_data| to the service. The incident_time_msec field is | 143 // Adds |incident_data| to the service. The incident_time_msec field is |
135 // populated with the current time if the caller has not already done so. | 144 // populated with the current time if the caller has not already done so. |
136 void AddIncident(Profile* profile, | 145 void AddIncident(Profile* profile, |
137 scoped_ptr<ClientIncidentReport_IncidentData> incident_data); | 146 scoped_ptr<ClientIncidentReport_IncidentData> incident_data); |
138 | 147 |
139 // Starts a task to collect environment data in the blocking pool. | 148 // Starts a task to collect environment data in the blocking pool. |
140 void BeginEnvironmentCollection(); | 149 void BeginEnvironmentCollection(); |
141 | 150 |
142 // Returns true if the environment collection task is outstanding. | 151 // Returns true if the environment collection task is outstanding. |
143 bool WaitingForEnvironmentCollection(); | 152 bool WaitingForEnvironmentCollection(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 263 |
255 // The time at which environmental data collection was initiated. | 264 // The time at which environmental data collection was initiated. |
256 base::TimeTicks environment_collection_begin_; | 265 base::TimeTicks environment_collection_begin_; |
257 | 266 |
258 // The time at which download collection was initiated. | 267 // The time at which download collection was initiated. |
259 base::TimeTicks last_download_begin_; | 268 base::TimeTicks last_download_begin_; |
260 | 269 |
261 // Context data for all on-the-record profiles. | 270 // Context data for all on-the-record profiles. |
262 ProfileContextCollection profiles_; | 271 ProfileContextCollection profiles_; |
263 | 272 |
| 273 // Callbacks registered for performing delayed analysis. |
| 274 DelayedCallbackRunner delayed_analysis_callbacks_; |
| 275 |
264 // The collection of uploads in progress. | 276 // The collection of uploads in progress. |
265 ScopedVector<UploadContext> uploads_; | 277 ScopedVector<UploadContext> uploads_; |
266 | 278 |
267 // An object that asynchronously searches for the most recent binary download. | 279 // An object that asynchronously searches for the most recent binary download. |
268 // Non-NULL while such a search is outstanding. | 280 // Non-NULL while such a search is outstanding. |
269 scoped_ptr<LastDownloadFinder> last_download_finder_; | 281 scoped_ptr<LastDownloadFinder> last_download_finder_; |
270 | 282 |
271 // A factory for handing out weak pointers for AddIncident callbacks. | 283 // A factory for handing out weak pointers for AddIncident callbacks. |
272 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; | 284 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; |
273 | 285 |
274 // A factory for handing out weak pointers for internal asynchronous tasks | 286 // A factory for handing out weak pointers for internal asynchronous tasks |
275 // that are posted during normal processing (e.g., environment collection, | 287 // that are posted during normal processing (e.g., environment collection, |
276 // safe browsing database checks, and report uploads). | 288 // safe browsing database checks, and report uploads). |
277 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; | 289 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; |
278 | 290 |
279 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); | 291 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); |
280 }; | 292 }; |
281 | 293 |
282 } // namespace safe_browsing | 294 } // namespace safe_browsing |
283 | 295 |
284 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_ | 296 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_ |
OLD | NEW |