| 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 #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 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 collation_timeout_pending_(), | 313 collation_timeout_pending_(), |
| 314 collation_timer_(FROM_HERE, | 314 collation_timer_(FROM_HERE, |
| 315 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), | 315 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), |
| 316 this, | 316 this, |
| 317 &IncidentReportingService::OnCollationTimeout), | 317 &IncidentReportingService::OnCollationTimeout), |
| 318 delayed_analysis_callbacks_( | 318 delayed_analysis_callbacks_( |
| 319 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), | 319 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), |
| 320 content::BrowserThread::GetBlockingPool() | 320 content::BrowserThread::GetBlockingPool() |
| 321 ->GetTaskRunnerWithShutdownBehavior( | 321 ->GetTaskRunnerWithShutdownBehavior( |
| 322 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | 322 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
| 323 extended_reporting_only_delayed_analysis_callbacks_( |
| 324 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), |
| 325 content::BrowserThread::GetBlockingPool() |
| 326 ->GetTaskRunnerWithShutdownBehavior( |
| 327 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
| 323 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), | 328 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), |
| 324 receiver_weak_ptr_factory_(this), | 329 receiver_weak_ptr_factory_(this), |
| 325 weak_ptr_factory_(this) { | 330 weak_ptr_factory_(this) { |
| 326 notification_registrar_.Add(this, | 331 notification_registrar_.Add(this, |
| 327 chrome::NOTIFICATION_PROFILE_ADDED, | 332 chrome::NOTIFICATION_PROFILE_ADDED, |
| 328 content::NotificationService::AllSources()); | 333 content::NotificationService::AllSources()); |
| 329 notification_registrar_.Add(this, | 334 notification_registrar_.Add(this, |
| 330 chrome::NOTIFICATION_PROFILE_DESTROYED, | 335 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 331 content::NotificationService::AllSources()); | 336 content::NotificationService::AllSources()); |
| 332 DownloadProtectionService* download_protection_service = | 337 DownloadProtectionService* download_protection_service = |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 delayed_analysis_callbacks_.RegisterCallback( | 385 delayed_analysis_callbacks_.RegisterCallback( |
| 381 base::Bind(callback, base::Passed(GetIncidentReceiver()))); | 386 base::Bind(callback, base::Passed(GetIncidentReceiver()))); |
| 382 | 387 |
| 383 // Start running the callbacks if any profiles are participating in safe | 388 // Start running the callbacks if any profiles are participating in safe |
| 384 // browsing. If none are now, running will commence if/when a participaing | 389 // browsing. If none are now, running will commence if/when a participaing |
| 385 // profile is added. | 390 // profile is added. |
| 386 if (FindEligibleProfile()) | 391 if (FindEligibleProfile()) |
| 387 delayed_analysis_callbacks_.Start(); | 392 delayed_analysis_callbacks_.Start(); |
| 388 } | 393 } |
| 389 | 394 |
| 395 void IncidentReportingService:: |
| 396 RegisterExtendedReportingOnlyDelayedAnalysisCallback( |
| 397 const DelayedAnalysisCallback& callback) { |
| 398 DCHECK(thread_checker_.CalledOnValidThread()); |
| 399 |
| 400 // |callback| will be run on the blocking pool. The receiver will bounce back |
| 401 // to the origin thread if needed. |
| 402 extended_reporting_only_delayed_analysis_callbacks_.RegisterCallback( |
| 403 base::Bind(callback, base::Passed(GetIncidentReceiver()))); |
| 404 |
| 405 // Start running the callbacks if any profiles have opted into Safebrowsing |
| 406 // extended reporting. If none are now, running will commence if/when such a |
| 407 // profile is added. |
| 408 Profile* profile = FindEligibleProfile(); |
| 409 if (profile && |
| 410 profile->GetPrefs()->GetBoolean( |
| 411 prefs::kSafeBrowsingExtendedReportingEnabled)) |
| 412 extended_reporting_only_delayed_analysis_callbacks_.Start(); |
| 413 } |
| 414 |
| 390 void IncidentReportingService::AddDownloadManager( | 415 void IncidentReportingService::AddDownloadManager( |
| 391 content::DownloadManager* download_manager) { | 416 content::DownloadManager* download_manager) { |
| 392 download_metadata_manager_.AddDownloadManager(download_manager); | 417 download_metadata_manager_.AddDownloadManager(download_manager); |
| 393 } | 418 } |
| 394 | 419 |
| 395 IncidentReportingService::IncidentReportingService( | 420 IncidentReportingService::IncidentReportingService( |
| 396 SafeBrowsingService* safe_browsing_service, | 421 SafeBrowsingService* safe_browsing_service, |
| 397 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 422 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 398 base::TimeDelta delayed_task_interval, | 423 base::TimeDelta delayed_task_interval, |
| 399 const scoped_refptr<base::TaskRunner>& delayed_task_runner) | 424 const scoped_refptr<base::TaskRunner>& delayed_task_runner) |
| 400 : database_manager_(safe_browsing_service | 425 : database_manager_(safe_browsing_service |
| 401 ? safe_browsing_service->database_manager() | 426 ? safe_browsing_service->database_manager() |
| 402 : NULL), | 427 : NULL), |
| 403 url_request_context_getter_(request_context_getter), | 428 url_request_context_getter_(request_context_getter), |
| 404 collect_environment_data_fn_(&CollectEnvironmentData), | 429 collect_environment_data_fn_(&CollectEnvironmentData), |
| 405 environment_collection_task_runner_( | 430 environment_collection_task_runner_( |
| 406 content::BrowserThread::GetBlockingPool() | 431 content::BrowserThread::GetBlockingPool() |
| 407 ->GetTaskRunnerWithShutdownBehavior( | 432 ->GetTaskRunnerWithShutdownBehavior( |
| 408 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | 433 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
| 409 environment_collection_pending_(), | 434 environment_collection_pending_(), |
| 410 collation_timeout_pending_(), | 435 collation_timeout_pending_(), |
| 411 collation_timer_(FROM_HERE, | 436 collation_timer_(FROM_HERE, |
| 412 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), | 437 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), |
| 413 this, | 438 this, |
| 414 &IncidentReportingService::OnCollationTimeout), | 439 &IncidentReportingService::OnCollationTimeout), |
| 415 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner), | 440 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner), |
| 441 extended_reporting_only_delayed_analysis_callbacks_(delayed_task_interval, |
| 442 delayed_task_runner), |
| 416 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), | 443 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), |
| 417 receiver_weak_ptr_factory_(this), | 444 receiver_weak_ptr_factory_(this), |
| 418 weak_ptr_factory_(this) { | 445 weak_ptr_factory_(this) { |
| 419 enabled_by_field_trial_ = IsFieldTrialEnabled(); | 446 enabled_by_field_trial_ = IsFieldTrialEnabled(); |
| 420 | 447 |
| 421 notification_registrar_.Add(this, | 448 notification_registrar_.Add(this, |
| 422 chrome::NOTIFICATION_PROFILE_ADDED, | 449 chrome::NOTIFICATION_PROFILE_ADDED, |
| 423 content::NotificationService::AllSources()); | 450 content::NotificationService::AllSources()); |
| 424 notification_registrar_.Add(this, | 451 notification_registrar_.Add(this, |
| 425 chrome::NOTIFICATION_PROFILE_DESTROYED, | 452 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 LogIncidentDataType(DROPPED, *incident); | 492 LogIncidentDataType(DROPPED, *incident); |
| 466 context->incidents.clear(); | 493 context->incidents.clear(); |
| 467 } | 494 } |
| 468 | 495 |
| 469 if (enabled_for_profile) { | 496 if (enabled_for_profile) { |
| 470 // Start processing delayed analysis callbacks if incident reporting is | 497 // Start processing delayed analysis callbacks if incident reporting is |
| 471 // enabled for this new profile. Start is idempotent, so this is safe even | 498 // enabled for this new profile. Start is idempotent, so this is safe even |
| 472 // if they're already running. | 499 // if they're already running. |
| 473 delayed_analysis_callbacks_.Start(); | 500 delayed_analysis_callbacks_.Start(); |
| 474 | 501 |
| 502 if (profile && |
| 503 profile->GetPrefs()->GetBoolean( |
| 504 prefs::kSafeBrowsingExtendedReportingEnabled)) { |
| 505 extended_reporting_only_delayed_analysis_callbacks_.Start(); |
| 506 } |
| 507 |
| 475 // Start a new report if there are process-wide incidents, or incidents for | 508 // Start a new report if there are process-wide incidents, or incidents for |
| 476 // this profile. | 509 // this profile. |
| 477 if ((GetProfileContext(nullptr) && | 510 if ((GetProfileContext(nullptr) && |
| 478 GetProfileContext(nullptr)->HasIncidents()) || | 511 GetProfileContext(nullptr)->HasIncidents()) || |
| 479 context->HasIncidents()) { | 512 context->HasIncidents()) { |
| 480 BeginReportProcessing(); | 513 BeginReportProcessing(); |
| 481 } | 514 } |
| 482 } | 515 } |
| 483 | 516 |
| 484 // TODO(grt): register for pref change notifications to start delayed analysis | 517 // TODO(grt): register for pref change notifications to start delayed analysis |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 if (!profile->IsOffTheRecord()) | 1103 if (!profile->IsOffTheRecord()) |
| 1071 OnProfileDestroyed(profile); | 1104 OnProfileDestroyed(profile); |
| 1072 break; | 1105 break; |
| 1073 } | 1106 } |
| 1074 default: | 1107 default: |
| 1075 break; | 1108 break; |
| 1076 } | 1109 } |
| 1077 } | 1110 } |
| 1078 | 1111 |
| 1079 } // namespace safe_browsing | 1112 } // namespace safe_browsing |
| OLD | NEW |