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

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

Issue 1870003002: Convert //chrome/browser/safe_browsing from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments Created 4 years, 8 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
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_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 #include <memory>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.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/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 "
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // All incident collection, data collection, and uploads in progress are 79 // All incident collection, data collection, and uploads in progress are
80 // dropped at destruction. 80 // dropped at destruction.
81 ~IncidentReportingService() override; 81 ~IncidentReportingService() override;
82 82
83 // Returns true if incident reporting is enabled for the given profile. 83 // Returns true if incident reporting is enabled for the given profile.
84 static bool IsEnabledForProfile(Profile* profile); 84 static bool IsEnabledForProfile(Profile* profile);
85 85
86 // 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
87 // 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
88 // effect after the service is deleted. 88 // effect after the service is deleted.
89 scoped_ptr<IncidentReceiver> GetIncidentReceiver(); 89 std::unique_ptr<IncidentReceiver> GetIncidentReceiver();
90 90
91 // Returns a preference validation delegate that adds incidents to the service 91 // Returns a preference validation delegate that adds incidents to the service
92 // for validation failures in |profile|. The delegate may outlive the service, 92 // for validation failures in |profile|. The delegate may outlive the service,
93 // but incidents reported by it will no longer have any effect after the 93 // but incidents reported by it will no longer have any effect after the
94 // service is deleted. 94 // service is deleted.
95 scoped_ptr<TrackedPreferenceValidationDelegate> 95 std::unique_ptr<TrackedPreferenceValidationDelegate>
96 CreatePreferenceValidationDelegate(Profile* profile); 96 CreatePreferenceValidationDelegate(Profile* profile);
97 97
98 // Registers |callback| to be run after some delay following process launch. 98 // Registers |callback| to be run after some delay following process launch.
99 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback); 99 void RegisterDelayedAnalysisCallback(const DelayedAnalysisCallback& callback);
100 100
101 // Registers |callback| to be run after some delay following process launch if 101 // Registers |callback| to be run after some delay following process launch if
102 // a profile participating in extended reporting is found. 102 // a profile participating in extended reporting is found.
103 void RegisterExtendedReportingOnlyDelayedAnalysisCallback( 103 void RegisterExtendedReportingOnlyDelayedAnalysisCallback(
104 const DelayedAnalysisCallback& callback); 104 const DelayedAnalysisCallback& callback);
105 105
106 // Adds |download_manager| to the set monitored for client download request 106 // Adds |download_manager| to the set monitored for client download request
(...skipping 28 matching lines...) Expand all
135 // Handles the addition of a new profile to the ProfileManager. Creates a new 135 // Handles the addition of a new profile to the ProfileManager. Creates a new
136 // context for |profile| if one does not exist, drops any received incidents 136 // context for |profile| if one does not exist, drops any received incidents
137 // for the profile if the profile is not participating in safe browsing, and 137 // for the profile if the profile is not participating in safe browsing, and
138 // initiates a new search for the most recent download if a report is being 138 // initiates a new search for the most recent download if a report is being
139 // assembled and the most recent has not been found. Overridden by unit tests 139 // assembled and the most recent has not been found. Overridden by unit tests
140 // to inject incidents prior to creation. 140 // to inject incidents prior to creation.
141 virtual void OnProfileAdded(Profile* profile); 141 virtual void OnProfileAdded(Profile* profile);
142 142
143 // Initiates a search for the most recent binary download. Overriden by unit 143 // Initiates a search for the most recent binary download. Overriden by unit
144 // tests to provide a fake finder. 144 // tests to provide a fake finder.
145 virtual scoped_ptr<LastDownloadFinder> CreateDownloadFinder( 145 virtual std::unique_ptr<LastDownloadFinder> CreateDownloadFinder(
146 const LastDownloadFinder::LastDownloadCallback& callback); 146 const LastDownloadFinder::LastDownloadCallback& callback);
147 147
148 // Initiates an upload. Overridden by unit tests to provide a fake uploader. 148 // Initiates an upload. Overridden by unit tests to provide a fake uploader.
149 virtual scoped_ptr<IncidentReportUploader> StartReportUpload( 149 virtual std::unique_ptr<IncidentReportUploader> StartReportUpload(
150 const IncidentReportUploader::OnResultCallback& callback, 150 const IncidentReportUploader::OnResultCallback& callback,
151 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 151 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
152 const ClientIncidentReport& report); 152 const ClientIncidentReport& report);
153 153
154 // Returns true if a report is currently being processed. 154 // Returns true if a report is currently being processed.
155 bool IsProcessingReport() const; 155 bool IsProcessingReport() const;
156 156
157 private: 157 private:
158 struct ProfileContext; 158 struct ProfileContext;
159 class UploadContext; 159 class UploadContext;
(...skipping 10 matching lines...) Expand all
170 170
171 // Handles the destruction of a profile. Incidents reported for the profile 171 // Handles the destruction of a profile. Incidents reported for the profile
172 // but not yet uploaded are dropped. 172 // but not yet uploaded are dropped.
173 void OnProfileDestroyed(Profile* profile); 173 void OnProfileDestroyed(Profile* profile);
174 174
175 // Returns an initialized profile that participates in safe browsing. Profiles 175 // Returns an initialized profile that participates in safe browsing. Profiles
176 // participating in extended safe browsing are preferred. 176 // participating in extended safe browsing are preferred.
177 Profile* FindEligibleProfile() const; 177 Profile* FindEligibleProfile() const;
178 178
179 // Adds |incident_data| relating to the optional |profile| to the service. 179 // Adds |incident_data| relating to the optional |profile| to the service.
180 void AddIncident(Profile* profile, scoped_ptr<Incident> incident); 180 void AddIncident(Profile* profile, std::unique_ptr<Incident> incident);
181 181
182 // Clears all data associated with the |incident| relating to the optional 182 // Clears all data associated with the |incident| relating to the optional
183 // |profile|. 183 // |profile|.
184 void ClearIncident(Profile* profile, scoped_ptr<Incident> incident); 184 void ClearIncident(Profile* profile, std::unique_ptr<Incident> incident);
185 185
186 // Returns true if there are incidents waiting to be sent. 186 // Returns true if there are incidents waiting to be sent.
187 bool HasIncidentsToUpload() const; 187 bool HasIncidentsToUpload() const;
188 188
189 // Begins processing a report. If processing is already underway, ensures that 189 // Begins processing a report. If processing is already underway, ensures that
190 // collection tasks have completed or are running. 190 // collection tasks have completed or are running.
191 void BeginReportProcessing(); 191 void BeginReportProcessing();
192 192
193 // Begins the process of collating incidents by waiting for incidents to 193 // Begins the process of collating incidents by waiting for incidents to
194 // arrive. This function is idempotent. 194 // arrive. This function is idempotent.
(...skipping 19 matching lines...) Expand all
214 bool WaitingForEnvironmentCollection(); 214 bool WaitingForEnvironmentCollection();
215 215
216 // Cancels any pending environment collection task and drops any data that has 216 // Cancels any pending environment collection task and drops any data that has
217 // already been collected. 217 // already been collected.
218 void CancelEnvironmentCollection(); 218 void CancelEnvironmentCollection();
219 219
220 // A callback invoked on the UI thread when environment data collection is 220 // A callback invoked on the UI thread when environment data collection is
221 // complete. Incident report processing continues, either by waiting for the 221 // complete. Incident report processing continues, either by waiting for the
222 // collection timeout or by sending an incident report. 222 // collection timeout or by sending an incident report.
223 void OnEnvironmentDataCollected( 223 void OnEnvironmentDataCollected(
224 scoped_ptr<ClientIncidentReport_EnvironmentData> environment_data); 224 std::unique_ptr<ClientIncidentReport_EnvironmentData> environment_data);
225 225
226 // Starts the asynchronous process of finding the most recent executable 226 // Starts the asynchronous process of finding the most recent executable
227 // download if one is not currently being search for and/or has not already 227 // download if one is not currently being search for and/or has not already
228 // been found. 228 // been found.
229 void BeginDownloadCollection(); 229 void BeginDownloadCollection();
230 230
231 // True if the service is waiting to discover the most recent download either 231 // True if the service is waiting to discover the most recent download either
232 // because a task to do so is outstanding, or because one or more profiles 232 // because a task to do so is outstanding, or because one or more profiles
233 // have yet to be added to the ProfileManager. 233 // have yet to be added to the ProfileManager.
234 bool WaitingForMostRecentDownload(); 234 bool WaitingForMostRecentDownload();
235 235
236 // Cancels the search for the most recent executable download. 236 // Cancels the search for the most recent executable download.
237 void CancelDownloadCollection(); 237 void CancelDownloadCollection();
238 238
239 // A callback invoked on the UI thread by the last download finder when the 239 // A callback invoked on the UI thread by the last download finder when the
240 // search for the most recent binary download and most recent non-binary 240 // search for the most recent binary download and most recent non-binary
241 // download is complete. 241 // download is complete.
242 void OnLastDownloadFound( 242 void OnLastDownloadFound(
243 scoped_ptr<ClientIncidentReport_DownloadDetails> last_binary_download, 243 std::unique_ptr<ClientIncidentReport_DownloadDetails>
244 scoped_ptr<ClientIncidentReport_NonBinaryDownloadDetails> 244 last_binary_download,
245 std::unique_ptr<ClientIncidentReport_NonBinaryDownloadDetails>
245 last_non_binary_download); 246 last_non_binary_download);
246 247
247 // Processes all received incidents once all data collection is 248 // Processes all received incidents once all data collection is
248 // complete. Incidents originating from profiles that do not participate in 249 // complete. Incidents originating from profiles that do not participate in
249 // safe browsing are dropped, incidents that have already been reported are 250 // safe browsing are dropped, incidents that have already been reported are
250 // pruned, and prune state is cleared for incidents that are now clear. Report 251 // pruned, and prune state is cleared for incidents that are now clear. Report
251 // upload is started if any incidents remain. 252 // upload is started if any incidents remain.
252 void ProcessIncidentsIfCollectionComplete(); 253 void ProcessIncidentsIfCollectionComplete();
253 254
254 // Cancels all uploads, discarding all reports and responses in progress. 255 // Cancels all uploads, discarding all reports and responses in progress.
255 void CancelAllReportUploads(); 256 void CancelAllReportUploads();
256 257
257 // Continues an upload after checking for the CSD whitelist killswitch. 258 // Continues an upload after checking for the CSD whitelist killswitch.
258 void OnKillSwitchResult(UploadContext* context, bool is_killswitch_on); 259 void OnKillSwitchResult(UploadContext* context, bool is_killswitch_on);
259 260
260 // Performs processing for a report after succesfully receiving a response. 261 // Performs processing for a report after succesfully receiving a response.
261 void HandleResponse(const UploadContext& context); 262 void HandleResponse(const UploadContext& context);
262 263
263 // IncidentReportUploader::OnResultCallback implementation. 264 // IncidentReportUploader::OnResultCallback implementation.
264 void OnReportUploadResult(UploadContext* context, 265 void OnReportUploadResult(UploadContext* context,
265 IncidentReportUploader::Result result, 266 IncidentReportUploader::Result result,
266 scoped_ptr<ClientIncidentResponse> response); 267 std::unique_ptr<ClientIncidentResponse> response);
267 268
268 // DownloadProtectionService::ClientDownloadRequestCallback implementation. 269 // DownloadProtectionService::ClientDownloadRequestCallback implementation.
269 void OnClientDownloadRequest(content::DownloadItem* download, 270 void OnClientDownloadRequest(content::DownloadItem* download,
270 const ClientDownloadRequest* request); 271 const ClientDownloadRequest* request);
271 272
272 // content::NotificationObserver methods. 273 // content::NotificationObserver methods.
273 void Observe(int type, 274 void Observe(int type,
274 const content::NotificationSource& source, 275 const content::NotificationSource& source,
275 const content::NotificationDetails& details) override; 276 const content::NotificationDetails& details) override;
276 277
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // collation_timer_ to fire. 311 // collation_timer_ to fire.
311 bool collation_timeout_pending_; 312 bool collation_timeout_pending_;
312 313
313 // A timer upon the firing of which the service will report received 314 // A timer upon the firing of which the service will report received
314 // incidents. 315 // incidents.
315 base::DelayTimer collation_timer_; 316 base::DelayTimer collation_timer_;
316 317
317 // The report currently being assembled. This becomes non-NULL when an initial 318 // The report currently being assembled. This becomes non-NULL when an initial
318 // incident is reported, and returns to NULL when the report is sent for 319 // incident is reported, and returns to NULL when the report is sent for
319 // upload. 320 // upload.
320 scoped_ptr<ClientIncidentReport> report_; 321 std::unique_ptr<ClientIncidentReport> report_;
321 322
322 // The time at which the initial incident is reported. 323 // The time at which the initial incident is reported.
323 base::Time first_incident_time_; 324 base::Time first_incident_time_;
324 325
325 // The time at which the last incident is reported. 326 // The time at which the last incident is reported.
326 base::TimeTicks last_incident_time_; 327 base::TimeTicks last_incident_time_;
327 328
328 // The time at which environmental data collection was initiated. 329 // The time at which environmental data collection was initiated.
329 base::TimeTicks environment_collection_begin_; 330 base::TimeTicks environment_collection_begin_;
330 331
331 // The time at which download collection was initiated. 332 // The time at which download collection was initiated.
332 base::TimeTicks last_download_begin_; 333 base::TimeTicks last_download_begin_;
333 334
334 // Context data for all on-the-record profiles plus the process-wide (NULL) 335 // Context data for all on-the-record profiles plus the process-wide (NULL)
335 // context. 336 // context.
336 ProfileContextCollection profiles_; 337 ProfileContextCollection profiles_;
337 338
338 // Callbacks registered for performing delayed analysis. 339 // Callbacks registered for performing delayed analysis.
339 DelayedCallbackRunner delayed_analysis_callbacks_; 340 DelayedCallbackRunner delayed_analysis_callbacks_;
340 341
341 // Callbacks registered for performing delayed analysis that should only 342 // Callbacks registered for performing delayed analysis that should only
342 // be executed for safebrowsing extended reporting users. 343 // be executed for safebrowsing extended reporting users.
343 DelayedCallbackRunner extended_reporting_only_delayed_analysis_callbacks_; 344 DelayedCallbackRunner extended_reporting_only_delayed_analysis_callbacks_;
344 345
345 DownloadMetadataManager download_metadata_manager_; 346 DownloadMetadataManager download_metadata_manager_;
346 347
347 // The collection of uploads in progress. 348 // The collection of uploads in progress.
348 std::vector<scoped_ptr<UploadContext>> uploads_; 349 std::vector<std::unique_ptr<UploadContext>> uploads_;
349 350
350 // An object that asynchronously searches for the most recent binary download. 351 // An object that asynchronously searches for the most recent binary download.
351 // Non-NULL while such a search is outstanding. 352 // Non-NULL while such a search is outstanding.
352 scoped_ptr<LastDownloadFinder> last_download_finder_; 353 std::unique_ptr<LastDownloadFinder> last_download_finder_;
353 354
354 // True if IncidentReportingService is enabled at the process level, by a 355 // True if IncidentReportingService is enabled at the process level, by a
355 // field trial. 356 // field trial.
356 bool enabled_by_field_trial_; 357 bool enabled_by_field_trial_;
357 358
358 // A factory for handing out weak pointers for IncidentReceiver objects. 359 // A factory for handing out weak pointers for IncidentReceiver objects.
359 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_; 360 base::WeakPtrFactory<IncidentReportingService> receiver_weak_ptr_factory_;
360 361
361 // A factory for handing out weak pointers for internal asynchronous tasks 362 // A factory for handing out weak pointers for internal asynchronous tasks
362 // that are posted during normal processing (e.g., environment collection, 363 // that are posted during normal processing (e.g., environment collection,
363 // safe browsing database checks, and report uploads). 364 // safe browsing database checks, and report uploads).
364 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_; 365 base::WeakPtrFactory<IncidentReportingService> weak_ptr_factory_;
365 366
366 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService); 367 DISALLOW_COPY_AND_ASSIGN(IncidentReportingService);
367 }; 368 };
368 369
369 } // namespace safe_browsing 370 } // namespace safe_browsing
370 371
371 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE RVICE_H_ 372 #endif // CHROME_BROWSER_SAFE_BROWSING_INCIDENT_REPORTING_INCIDENT_REPORTING_SE RVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698