Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting_service.h

Issue 379563006: Merge 281089 "Include the latest binary download info in safe br..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2062/src/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/incident_report_uploader.h" 22 #include "chrome/browser/safe_browsing/incident_report_uploader.h"
23 #include "chrome/browser/safe_browsing/last_download_finder.h"
23 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
25 26
26 class Profile; 27 class Profile;
27 class SafeBrowsingDatabaseManager; 28 class SafeBrowsingDatabaseManager;
28 class SafeBrowsingService; 29 class SafeBrowsingService;
29 class TrackedPreferenceValidationDelegate; 30 class TrackedPreferenceValidationDelegate;
30 31
31 namespace base { 32 namespace base {
32 class TaskRunner; 33 class TaskRunner;
(...skipping 14 matching lines...) Expand all
47 class ClientIncidentReport_DownloadDetails; 48 class ClientIncidentReport_DownloadDetails;
48 class ClientIncidentReport_EnvironmentData; 49 class ClientIncidentReport_EnvironmentData;
49 class ClientIncidentReport_IncidentData; 50 class ClientIncidentReport_IncidentData;
50 51
51 // A class that manages the collection of incidents and submission of incident 52 // A class that manages the collection of incidents and submission of incident
52 // reports to the safe browsing client-side detection service. The service 53 // reports to the safe browsing client-side detection service. The service
53 // begins operation when an incident is reported via the AddIncident method. 54 // begins operation when an incident is reported via the AddIncident method.
54 // Incidents reported from a profile that is loading are held until the profile 55 // Incidents reported from a profile that is loading are held until the profile
55 // is fully created. Incidents originating from profiles that do not participate 56 // is fully created. Incidents originating from profiles that do not participate
56 // in safe browsing are dropped. Following the addition of an incident that is 57 // in safe browsing are dropped. Following the addition of an incident that is
57 // not dropped, the service collects environmental data and waits a bit. 58 // not dropped, the service collects environmental data, finds the most recent
58 // Additional incidents that arrive during this time are collated with the 59 // binary download, and waits a bit. Additional incidents that arrive during
59 // initial incident. Finally, already-reported incidents are pruned and any 60 // this time are collated with the initial incident. Finally, already-reported
60 // remaining are uploaded in an incident report. 61 // incidents are pruned and any remaining are uploaded in an incident report.
61 class IncidentReportingService : public content::NotificationObserver { 62 class IncidentReportingService : public content::NotificationObserver {
62 public: 63 public:
63 IncidentReportingService(SafeBrowsingService* safe_browsing_service, 64 IncidentReportingService(SafeBrowsingService* safe_browsing_service,
64 const scoped_refptr<net::URLRequestContextGetter>& 65 const scoped_refptr<net::URLRequestContextGetter>&
65 request_context_getter); 66 request_context_getter);
66 67
67 // All incident collection, data collection, and uploads in progress are 68 // All incident collection, data collection, and uploads in progress are
68 // dropped at destruction. 69 // dropped at destruction.
69 virtual ~IncidentReportingService(); 70 virtual ~IncidentReportingService();
70 71
(...skipping 16 matching lines...) Expand all
87 typedef void (*CollectEnvironmentDataFn)( 88 typedef void (*CollectEnvironmentDataFn)(
88 ClientIncidentReport_EnvironmentData*); 89 ClientIncidentReport_EnvironmentData*);
89 90
90 // Sets the function called by the service to collect environment data and the 91 // Sets the function called by the service to collect environment data and the
91 // task runner on which it is called. Used by unit tests to provide a fake 92 // task runner on which it is called. Used by unit tests to provide a fake
92 // environment data collector. 93 // environment data collector.
93 void SetCollectEnvironmentHook( 94 void SetCollectEnvironmentHook(
94 CollectEnvironmentDataFn collect_environment_data_hook, 95 CollectEnvironmentDataFn collect_environment_data_hook,
95 const scoped_refptr<base::TaskRunner>& task_runner); 96 const scoped_refptr<base::TaskRunner>& task_runner);
96 97
97 // Handles the creation of a new profile. Creates a new context for |profile| 98 // Handles the addition of a new profile to the ProfileManager. Creates a new
98 // if one does not exist, and drops any received incidents for the profile if 99 // context for |profile| if one does not exist, drops any received incidents
99 // the profile is not participating in safe browsing. Overridden by unit tests 100 // for the profile if the profile is not participating in safe browsing, and
101 // initiates a new search for the most recent download if a report is being
102 // assembled and the most recent has not been found. Overridden by unit tests
100 // to inject incidents prior to creation. 103 // to inject incidents prior to creation.
101 virtual void OnProfileCreated(Profile* profile); 104 virtual void OnProfileAdded(Profile* profile);
105
106 // Initiates a search for the most recent binary download. Overriden by unit
107 // tests to provide a fake finder.
108 virtual scoped_ptr<LastDownloadFinder> CreateDownloadFinder(
109 const LastDownloadFinder::LastDownloadCallback& callback);
102 110
103 // Initiates an upload. Overridden by unit tests to provide a fake uploader. 111 // Initiates an upload. Overridden by unit tests to provide a fake uploader.
104 virtual scoped_ptr<IncidentReportUploader> StartReportUpload( 112 virtual scoped_ptr<IncidentReportUploader> StartReportUpload(
105 const IncidentReportUploader::OnResultCallback& callback, 113 const IncidentReportUploader::OnResultCallback& callback,
106 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 114 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
107 const ClientIncidentReport& report); 115 const ClientIncidentReport& report);
108 116
109 private: 117 private:
110 struct ProfileContext; 118 struct ProfileContext;
111 class UploadContext; 119 class UploadContext;
(...skipping 12 matching lines...) Expand all
124 void OnProfileDestroyed(Profile* profile); 132 void OnProfileDestroyed(Profile* profile);
125 133
126 // Adds |incident_data| to the service. The incident_time_msec field is 134 // Adds |incident_data| to the service. The incident_time_msec field is
127 // populated with the current time if the caller has not already done so. 135 // populated with the current time if the caller has not already done so.
128 void AddIncident(Profile* profile, 136 void AddIncident(Profile* profile,
129 scoped_ptr<ClientIncidentReport_IncidentData> incident_data); 137 scoped_ptr<ClientIncidentReport_IncidentData> incident_data);
130 138
131 // Starts a task to collect environment data in the blocking pool. 139 // Starts a task to collect environment data in the blocking pool.
132 void BeginEnvironmentCollection(); 140 void BeginEnvironmentCollection();
133 141
142 // Returns true if the environment collection task is outstanding.
143 bool WaitingForEnvironmentCollection();
144
134 // Cancels any pending environment collection task and drops any data that has 145 // Cancels any pending environment collection task and drops any data that has
135 // already been collected. 146 // already been collected.
136 void CancelEnvironmentCollection(); 147 void CancelEnvironmentCollection();
137 148
138 // A callback invoked on the UI thread when environment data collection is 149 // A callback invoked on the UI thread when environment data collection is
139 // complete. Incident report processing continues, either by waiting for the 150 // complete. Incident report processing continues, either by waiting for the
140 // collection timeout or by sending an incident report. 151 // collection timeout or by sending an incident report.
141 void OnEnvironmentDataCollected( 152 void OnEnvironmentDataCollected(
142 scoped_ptr<ClientIncidentReport_EnvironmentData> environment_data); 153 scoped_ptr<ClientIncidentReport_EnvironmentData> environment_data);
143 154
155 // Returns true if the service is waiting for additional incidents before
156 // uploading a report.
157 bool WaitingToCollateIncidents();
158
144 // Cancels the collection timeout. 159 // Cancels the collection timeout.
145 void CancelIncidentCollection(); 160 void CancelIncidentCollection();
146 161
147 // A callback invoked on the UI thread after which incident collection has 162 // A callback invoked on the UI thread after which incident collection has
148 // completed. Incident report processing continues, either by waiting for 163 // completed. Incident report processing continues, either by waiting for
149 // environment data to arrive or by sending an incident report. 164 // environment data to arrive or by sending an incident report.
150 void OnCollectionTimeout(); 165 void OnCollectionTimeout();
151 166
152 // Populates |download_details| with information about the most recent 167 // Starts the asynchronous process of finding the most recent executable
153 // download. 168 // download if one is not currently being search for and/or has not already
154 void CollectDownloadDetails( 169 // been found.
155 ClientIncidentReport_DownloadDetails* download_details); 170 void BeginDownloadCollection();
171
172 // True if the service is waiting to discover the most recent download either
173 // because a task to do so is outstanding, or because one or more profiles
174 // have yet to be added to the ProfileManager.
175 bool WaitingForMostRecentDownload();
176
177 // Cancels the search for the most recent executable download.
178 void CancelDownloadCollection();
179
180 // A callback invoked on the UI thread by the last download finder when the
181 // search for the most recent binary download is complete.
182 void OnLastDownloadFound(
183 scoped_ptr<ClientIncidentReport_DownloadDetails> last_download);
156 184
157 // Uploads an incident report if all data collection is complete. Incidents 185 // Uploads an incident report if all data collection is complete. Incidents
158 // originating from profiles that do not participate in safe browsing are 186 // originating from profiles that do not participate in safe browsing are
159 // dropped. 187 // dropped.
160 void UploadIfCollectionComplete(); 188 void UploadIfCollectionComplete();
161 189
162 // Cancels all uploads, discarding all reports and responses in progress. 190 // Cancels all uploads, discarding all reports and responses in progress.
163 void CancelAllReportUploads(); 191 void CancelAllReportUploads();
164 192
165 // Continues an upload after checking for the CSD whitelist killswitch. 193 // Continues an upload after checking for the CSD whitelist killswitch.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 248
221 // The time at which the initial incident is reported. 249 // The time at which the initial incident is reported.
222 base::Time first_incident_time_; 250 base::Time first_incident_time_;
223 251
224 // The time at which the last incident is reported. 252 // The time at which the last incident is reported.
225 base::TimeTicks last_incident_time_; 253 base::TimeTicks last_incident_time_;
226 254
227 // The time at which environmental data collection was initiated. 255 // The time at which environmental data collection was initiated.
228 base::TimeTicks environment_collection_begin_; 256 base::TimeTicks environment_collection_begin_;
229 257
258 // The time at which download collection was initiated.
259 base::TimeTicks last_download_begin_;
260
230 // Context data for all on-the-record profiles. 261 // Context data for all on-the-record profiles.
231 ProfileContextCollection profiles_; 262 ProfileContextCollection profiles_;
232 263
233 // The collection of uploads in progress. 264 // The collection of uploads in progress.
234 ScopedVector<UploadContext> uploads_; 265 ScopedVector<UploadContext> uploads_;
235 266
267 // An object that asynchronously searches for the most recent binary download.
268 // Non-NULL while such a search is outstanding.
269 scoped_ptr<LastDownloadFinder> last_download_finder_;
270
236 // A factory for handing out weak pointers for AddIncident callbacks. 271 // A factory for handing out weak pointers for AddIncident callbacks.
237 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; 272 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_;
238 273
239 // A factory for handing out weak pointers for internal asynchronous tasks 274 // A factory for handing out weak pointers for internal asynchronous tasks
240 // that are posted during normal processing (e.g., environment collection, 275 // that are posted during normal processing (e.g., environment collection,
241 // safe browsing database checks, and report uploads). 276 // safe browsing database checks, and report uploads).
242 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; 277 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_;
243 278
244 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); 279 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService);
245 }; 280 };
246 281
247 } // namespace safe_browsing 282 } // namespace safe_browsing
248 283
249 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_ 284 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/incident_report_uploader.h ('k') | chrome/browser/safe_browsing/incident_reporting_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698