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

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

Issue 663023007: Include high-fidelity metadata about a download in incident reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: added DCHECK Created 6 years, 1 month 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 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser vice.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser vice.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 scoped_ptr<ClientIncidentReport> report) 242 scoped_ptr<ClientIncidentReport> report)
243 : report(report.Pass()) { 243 : report(report.Pass()) {
244 } 244 }
245 245
246 IncidentReportingService::UploadContext::~UploadContext() { 246 IncidentReportingService::UploadContext::~UploadContext() {
247 } 247 }
248 248
249 IncidentReportingService::IncidentReportingService( 249 IncidentReportingService::IncidentReportingService(
250 SafeBrowsingService* safe_browsing_service, 250 SafeBrowsingService* safe_browsing_service,
251 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) 251 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter)
252 : database_manager_(safe_browsing_service ? 252 : database_manager_(safe_browsing_service
253 safe_browsing_service->database_manager() : NULL), 253 ? safe_browsing_service->database_manager()
254 : NULL),
254 url_request_context_getter_(request_context_getter), 255 url_request_context_getter_(request_context_getter),
255 collect_environment_data_fn_(&CollectEnvironmentData), 256 collect_environment_data_fn_(&CollectEnvironmentData),
256 environment_collection_task_runner_( 257 environment_collection_task_runner_(
257 content::BrowserThread::GetBlockingPool() 258 content::BrowserThread::GetBlockingPool()
258 ->GetTaskRunnerWithShutdownBehavior( 259 ->GetTaskRunnerWithShutdownBehavior(
259 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), 260 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
260 environment_collection_pending_(), 261 environment_collection_pending_(),
261 collation_timeout_pending_(), 262 collation_timeout_pending_(),
262 collation_timer_(FROM_HERE, 263 collation_timer_(FROM_HERE,
263 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), 264 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs),
264 this, 265 this,
265 &IncidentReportingService::OnCollationTimeout), 266 &IncidentReportingService::OnCollationTimeout),
266 delayed_analysis_callbacks_( 267 delayed_analysis_callbacks_(
267 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), 268 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs),
268 content::BrowserThread::GetBlockingPool() 269 content::BrowserThread::GetBlockingPool()
269 ->GetTaskRunnerWithShutdownBehavior( 270 ->GetTaskRunnerWithShutdownBehavior(
270 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), 271 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
272 download_metadata_manager_(content::BrowserThread::GetBlockingPool()),
271 receiver_weak_ptr_factory_(this), 273 receiver_weak_ptr_factory_(this),
272 weak_ptr_factory_(this) { 274 weak_ptr_factory_(this) {
273 notification_registrar_.Add(this, 275 notification_registrar_.Add(this,
274 chrome::NOTIFICATION_PROFILE_ADDED, 276 chrome::NOTIFICATION_PROFILE_ADDED,
275 content::NotificationService::AllSources()); 277 content::NotificationService::AllSources());
276 notification_registrar_.Add(this, 278 notification_registrar_.Add(this,
277 chrome::NOTIFICATION_PROFILE_DESTROYED, 279 chrome::NOTIFICATION_PROFILE_DESTROYED,
278 content::NotificationService::AllSources()); 280 content::NotificationService::AllSources());
281 DownloadProtectionService* download_protection_service =
282 (safe_browsing_service ?
283 safe_browsing_service->download_protection_service() :
284 NULL);
285 if (download_protection_service) {
286 client_download_request_subscription_ =
287 download_protection_service->RegisterClientDownloadRequestCallback(
288 base::Bind(&IncidentReportingService::OnClientDownloadRequest,
289 base::Unretained(this)));
290 }
279 } 291 }
280 292
281 IncidentReportingService::~IncidentReportingService() { 293 IncidentReportingService::~IncidentReportingService() {
282 CancelIncidentCollection(); 294 CancelIncidentCollection();
283 295
284 // Cancel all internal asynchronous tasks. 296 // Cancel all internal asynchronous tasks.
285 weak_ptr_factory_.InvalidateWeakPtrs(); 297 weak_ptr_factory_.InvalidateWeakPtrs();
286 298
287 CancelEnvironmentCollection(); 299 CancelEnvironmentCollection();
288 CancelDownloadCollection(); 300 CancelDownloadCollection();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 GetAddIncidentCallback(NULL), 338 GetAddIncidentCallback(NULL),
327 base::ThreadTaskRunnerHandle::Get()))); 339 base::ThreadTaskRunnerHandle::Get())));
328 340
329 // Start running the callbacks if any profiles are participating in safe 341 // Start running the callbacks if any profiles are participating in safe
330 // browsing. If none are now, running will commence if/when a participaing 342 // browsing. If none are now, running will commence if/when a participaing
331 // profile is added. 343 // profile is added.
332 if (FindEligibleProfile()) 344 if (FindEligibleProfile())
333 delayed_analysis_callbacks_.Start(); 345 delayed_analysis_callbacks_.Start();
334 } 346 }
335 347
348 void IncidentReportingService::AddDownloadManager(
349 content::DownloadManager* download_manager) {
350 download_metadata_manager_.AddDownloadManager(download_manager);
351 }
352
336 IncidentReportingService::IncidentReportingService( 353 IncidentReportingService::IncidentReportingService(
337 SafeBrowsingService* safe_browsing_service, 354 SafeBrowsingService* safe_browsing_service,
338 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 355 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
339 base::TimeDelta delayed_task_interval, 356 base::TimeDelta delayed_task_interval,
340 const scoped_refptr<base::TaskRunner>& delayed_task_runner) 357 const scoped_refptr<base::TaskRunner>& delayed_task_runner)
341 : database_manager_(safe_browsing_service ? 358 : database_manager_(safe_browsing_service
342 safe_browsing_service->database_manager() : NULL), 359 ? safe_browsing_service->database_manager()
360 : NULL),
343 url_request_context_getter_(request_context_getter), 361 url_request_context_getter_(request_context_getter),
344 collect_environment_data_fn_(&CollectEnvironmentData), 362 collect_environment_data_fn_(&CollectEnvironmentData),
345 environment_collection_task_runner_( 363 environment_collection_task_runner_(
346 content::BrowserThread::GetBlockingPool() 364 content::BrowserThread::GetBlockingPool()
347 ->GetTaskRunnerWithShutdownBehavior( 365 ->GetTaskRunnerWithShutdownBehavior(
348 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), 366 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
349 environment_collection_pending_(), 367 environment_collection_pending_(),
350 collation_timeout_pending_(), 368 collation_timeout_pending_(),
351 collation_timer_(FROM_HERE, 369 collation_timer_(FROM_HERE,
352 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), 370 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs),
353 this, 371 this,
354 &IncidentReportingService::OnCollationTimeout), 372 &IncidentReportingService::OnCollationTimeout),
355 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner), 373 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner),
374 download_metadata_manager_(content::BrowserThread::GetBlockingPool()),
356 receiver_weak_ptr_factory_(this), 375 receiver_weak_ptr_factory_(this),
357 weak_ptr_factory_(this) { 376 weak_ptr_factory_(this) {
358 notification_registrar_.Add(this, 377 notification_registrar_.Add(this,
359 chrome::NOTIFICATION_PROFILE_ADDED, 378 chrome::NOTIFICATION_PROFILE_ADDED,
360 content::NotificationService::AllSources()); 379 content::NotificationService::AllSources());
361 notification_registrar_.Add(this, 380 notification_registrar_.Add(this,
362 chrome::NOTIFICATION_PROFILE_DESTROYED, 381 chrome::NOTIFICATION_PROFILE_DESTROYED,
363 content::NotificationService::AllSources()); 382 content::NotificationService::AllSources());
364 } 383 }
365 384
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 439 }
421 440
422 // Take another stab at finding the most recent download if a report is being 441 // Take another stab at finding the most recent download if a report is being
423 // assembled and one hasn't been found yet (the LastDownloadFinder operates 442 // assembled and one hasn't been found yet (the LastDownloadFinder operates
424 // only on profiles that have been added to the ProfileManager). 443 // only on profiles that have been added to the ProfileManager).
425 BeginDownloadCollection(); 444 BeginDownloadCollection();
426 } 445 }
427 446
428 scoped_ptr<LastDownloadFinder> IncidentReportingService::CreateDownloadFinder( 447 scoped_ptr<LastDownloadFinder> IncidentReportingService::CreateDownloadFinder(
429 const LastDownloadFinder::LastDownloadCallback& callback) { 448 const LastDownloadFinder::LastDownloadCallback& callback) {
430 return LastDownloadFinder::Create(callback).Pass(); 449 return LastDownloadFinder::Create(
450 base::Bind(&DownloadMetadataManager::GetDownloadDetails,
451 base::Unretained(&download_metadata_manager_)),
452 callback).Pass();
431 } 453 }
432 454
433 scoped_ptr<IncidentReportUploader> IncidentReportingService::StartReportUpload( 455 scoped_ptr<IncidentReportUploader> IncidentReportingService::StartReportUpload(
434 const IncidentReportUploader::OnResultCallback& callback, 456 const IncidentReportUploader::OnResultCallback& callback,
435 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 457 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
436 const ClientIncidentReport& report) { 458 const ClientIncidentReport& report) {
437 return IncidentReportUploaderImpl::UploadReport( 459 return IncidentReportUploaderImpl::UploadReport(
438 callback, request_context_getter, report).Pass(); 460 callback, request_context_getter, report).Pass();
439 } 461 }
440 462
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 DCHECK(it != uploads_.end()); 960 DCHECK(it != uploads_.end());
939 scoped_ptr<UploadContext> upload(context); // == *it 961 scoped_ptr<UploadContext> upload(context); // == *it
940 *it = uploads_.back(); 962 *it = uploads_.back();
941 uploads_.weak_erase(uploads_.end() - 1); 963 uploads_.weak_erase(uploads_.end() - 1);
942 964
943 if (result == IncidentReportUploader::UPLOAD_SUCCESS) 965 if (result == IncidentReportUploader::UPLOAD_SUCCESS)
944 HandleResponse(*upload); 966 HandleResponse(*upload);
945 // else retry? 967 // else retry?
946 } 968 }
947 969
970 void IncidentReportingService::OnClientDownloadRequest(
971 content::DownloadItem* download,
972 const ClientDownloadRequest* request) {
973 if (!download->GetBrowserContext()->IsOffTheRecord())
974 download_metadata_manager_.SetRequest(download, request);
975 }
976
948 void IncidentReportingService::Observe( 977 void IncidentReportingService::Observe(
949 int type, 978 int type,
950 const content::NotificationSource& source, 979 const content::NotificationSource& source,
951 const content::NotificationDetails& details) { 980 const content::NotificationDetails& details) {
952 switch (type) { 981 switch (type) {
953 case chrome::NOTIFICATION_PROFILE_ADDED: { 982 case chrome::NOTIFICATION_PROFILE_ADDED: {
954 Profile* profile = content::Source<Profile>(source).ptr(); 983 Profile* profile = content::Source<Profile>(source).ptr();
955 if (!profile->IsOffTheRecord()) 984 if (!profile->IsOffTheRecord())
956 OnProfileAdded(profile); 985 OnProfileAdded(profile);
957 break; 986 break;
958 } 987 }
959 case chrome::NOTIFICATION_PROFILE_DESTROYED: { 988 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
960 Profile* profile = content::Source<Profile>(source).ptr(); 989 Profile* profile = content::Source<Profile>(source).ptr();
961 if (!profile->IsOffTheRecord()) 990 if (!profile->IsOffTheRecord())
962 OnProfileDestroyed(profile); 991 OnProfileDestroyed(profile);
963 break; 992 break;
964 } 993 }
965 default: 994 default:
966 break; 995 break;
967 } 996 }
968 } 997 }
969 998
970 } // namespace safe_browsing 999 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698