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. | |
robertshield
2014/08/04 01:35:12
Mention that it returns the most opted-in profile
grt (UTC plus 2)
2014/08/04 14:15:33
Done.
| |
140 Profile* FindEligibleProfile() const; | |
141 | |
134 // Adds |incident_data| to the service. The incident_time_msec field is | 142 // 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. | 143 // populated with the current time if the caller has not already done so. |
136 void AddIncident(Profile* profile, | 144 void AddIncident(Profile* profile, |
137 scoped_ptr<ClientIncidentReport_IncidentData> incident_data); | 145 scoped_ptr<ClientIncidentReport_IncidentData> incident_data); |
138 | 146 |
139 // Starts a task to collect environment data in the blocking pool. | 147 // Starts a task to collect environment data in the blocking pool. |
140 void BeginEnvironmentCollection(); | 148 void BeginEnvironmentCollection(); |
141 | 149 |
142 // Returns true if the environment collection task is outstanding. | 150 // Returns true if the environment collection task is outstanding. |
143 bool WaitingForEnvironmentCollection(); | 151 bool WaitingForEnvironmentCollection(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 | 262 |
255 // The time at which environmental data collection was initiated. | 263 // The time at which environmental data collection was initiated. |
256 base::TimeTicks environment_collection_begin_; | 264 base::TimeTicks environment_collection_begin_; |
257 | 265 |
258 // The time at which download collection was initiated. | 266 // The time at which download collection was initiated. |
259 base::TimeTicks last_download_begin_; | 267 base::TimeTicks last_download_begin_; |
260 | 268 |
261 // Context data for all on-the-record profiles. | 269 // Context data for all on-the-record profiles. |
262 ProfileContextCollection profiles_; | 270 ProfileContextCollection profiles_; |
263 | 271 |
272 // Callbacks registered for performing delayed analysis. | |
273 DelayedCallbackRunner delayed_analysis_callbacks_; | |
274 | |
264 // The collection of uploads in progress. | 275 // The collection of uploads in progress. |
265 ScopedVector<UploadContext> uploads_; | 276 ScopedVector<UploadContext> uploads_; |
266 | 277 |
267 // An object that asynchronously searches for the most recent binary download. | 278 // An object that asynchronously searches for the most recent binary download. |
268 // Non-NULL while such a search is outstanding. | 279 // Non-NULL while such a search is outstanding. |
269 scoped_ptr<LastDownloadFinder> last_download_finder_; | 280 scoped_ptr<LastDownloadFinder> last_download_finder_; |
270 | 281 |
271 // A factory for handing out weak pointers for AddIncident callbacks. | 282 // A factory for handing out weak pointers for AddIncident callbacks. |
272 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; | 283 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; |
273 | 284 |
274 // A factory for handing out weak pointers for internal asynchronous tasks | 285 // A factory for handing out weak pointers for internal asynchronous tasks |
275 // that are posted during normal processing (e.g., environment collection, | 286 // that are posted during normal processing (e.g., environment collection, |
276 // safe browsing database checks, and report uploads). | 287 // safe browsing database checks, and report uploads). |
277 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; | 288 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; |
278 | 289 |
279 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); | 290 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); |
280 }; | 291 }; |
281 | 292 |
282 } // namespace safe_browsing | 293 } // namespace safe_browsing |
283 | 294 |
284 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_ | 295 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_ |
OLD | NEW |