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

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

Issue 1905293003: Use CONTINUE_ON_SHUTDOWN for IncidentReportingService tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 #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 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/process/process_info.h" 18 #include "base/process/process_info.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/thread_task_runner_handle.h" 22 #include "base/thread_task_runner_handle.h"
23 #include "base/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "chrome/browser/browser_hangs_experiment.h"
25 #include "chrome/browser/chrome_notification_types.h" 26 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 27 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
27 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle ction.h" 29 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle ction.h"
29 #include "chrome/browser/safe_browsing/incident_reporting/extension_data_collect ion.h" 30 #include "chrome/browser/safe_browsing/incident_reporting/extension_data_collect ion.h"
30 #include "chrome/browser/safe_browsing/incident_reporting/incident.h" 31 #include "chrome/browser/safe_browsing/incident_reporting/incident.h"
31 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" 32 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h"
32 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload er_impl.h" 33 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload er_impl.h"
33 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_ delegate.h" 34 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_ delegate.h"
34 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h" 35 #include "chrome/browser/safe_browsing/incident_reporting/state_store.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 case MinimumProfileConsent::SAFE_BROWSING_ENABLED: 140 case MinimumProfileConsent::SAFE_BROWSING_ENABLED:
140 return true; 141 return true;
141 case MinimumProfileConsent::SAFE_BROWSING_EXTENDED_REPORTING_ENABLED: 142 case MinimumProfileConsent::SAFE_BROWSING_EXTENDED_REPORTING_ENABLED:
142 return profile->GetPrefs()->GetBoolean( 143 return profile->GetPrefs()->GetBoolean(
143 prefs::kSafeBrowsingExtendedReportingEnabled); 144 prefs::kSafeBrowsingExtendedReportingEnabled);
144 } 145 }
145 NOTREACHED(); 146 NOTREACHED();
146 return false; 147 return false;
147 } 148 }
148 149
150 // Returns the shutdown behavior for the task runners of the incident reporting
151 // service. Current metrics suggest that CONTINUE_ON_SHUTDOWN will reduce the
152 // number of browser hangs on shutdown.
153 base::SequencedWorkerPool::WorkerShutdown GetShutdownBehavior() {
154 return IsBrowserHangsExperimentEnabled()
155 ? base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN
156 : base::SequencedWorkerPool::SKIP_ON_SHUTDOWN;
157 }
158
149 } // namespace 159 } // namespace
150 160
151 struct IncidentReportingService::ProfileContext { 161 struct IncidentReportingService::ProfileContext {
152 ProfileContext(); 162 ProfileContext();
153 ~ProfileContext(); 163 ~ProfileContext();
154 164
155 // Returns true if the profile has incidents to be uploaded or cleared. 165 // Returns true if the profile has incidents to be uploaded or cleared.
156 bool HasIncidents() const; 166 bool HasIncidents() const;
157 167
158 // The incidents collected for this profile pending creation and/or upload. 168 // The incidents collected for this profile pending creation and/or upload.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 SafeBrowsingService* safe_browsing_service) 341 SafeBrowsingService* safe_browsing_service)
332 : database_manager_(safe_browsing_service 342 : database_manager_(safe_browsing_service
333 ? safe_browsing_service->database_manager() 343 ? safe_browsing_service->database_manager()
334 : nullptr), 344 : nullptr),
335 url_request_context_getter_( 345 url_request_context_getter_(
336 safe_browsing_service ? safe_browsing_service->url_request_context() 346 safe_browsing_service ? safe_browsing_service->url_request_context()
337 : nullptr), 347 : nullptr),
338 collect_environment_data_fn_(&CollectEnvironmentData), 348 collect_environment_data_fn_(&CollectEnvironmentData),
339 environment_collection_task_runner_( 349 environment_collection_task_runner_(
340 content::BrowserThread::GetBlockingPool() 350 content::BrowserThread::GetBlockingPool()
341 ->GetTaskRunnerWithShutdownBehavior( 351 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
342 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
343 environment_collection_pending_(), 352 environment_collection_pending_(),
344 collation_timeout_pending_(), 353 collation_timeout_pending_(),
345 collation_timer_(FROM_HERE, 354 collation_timer_(FROM_HERE,
346 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), 355 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs),
347 this, 356 this,
348 &IncidentReportingService::OnCollationTimeout), 357 &IncidentReportingService::OnCollationTimeout),
349 delayed_analysis_callbacks_( 358 delayed_analysis_callbacks_(
350 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), 359 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs),
351 content::BrowserThread::GetBlockingPool() 360 content::BrowserThread::GetBlockingPool()
352 ->GetTaskRunnerWithShutdownBehavior( 361 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
353 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
354 extended_reporting_only_delayed_analysis_callbacks_( 362 extended_reporting_only_delayed_analysis_callbacks_(
355 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), 363 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs),
356 content::BrowserThread::GetBlockingPool() 364 content::BrowserThread::GetBlockingPool()
357 ->GetTaskRunnerWithShutdownBehavior( 365 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
358 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
359 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), 366 download_metadata_manager_(content::BrowserThread::GetBlockingPool()),
360 receiver_weak_ptr_factory_(this), 367 receiver_weak_ptr_factory_(this),
361 weak_ptr_factory_(this) { 368 weak_ptr_factory_(this) {
362 notification_registrar_.Add(this, 369 notification_registrar_.Add(this,
363 chrome::NOTIFICATION_PROFILE_ADDED, 370 chrome::NOTIFICATION_PROFILE_ADDED,
364 content::NotificationService::AllSources()); 371 content::NotificationService::AllSources());
365 notification_registrar_.Add(this, 372 notification_registrar_.Add(this,
366 chrome::NOTIFICATION_PROFILE_DESTROYED, 373 chrome::NOTIFICATION_PROFILE_DESTROYED,
367 content::NotificationService::AllSources()); 374 content::NotificationService::AllSources());
368 DownloadProtectionService* download_protection_service = 375 DownloadProtectionService* download_protection_service =
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 463 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
457 base::TimeDelta delayed_task_interval, 464 base::TimeDelta delayed_task_interval,
458 const scoped_refptr<base::TaskRunner>& delayed_task_runner) 465 const scoped_refptr<base::TaskRunner>& delayed_task_runner)
459 : database_manager_(safe_browsing_service 466 : database_manager_(safe_browsing_service
460 ? safe_browsing_service->database_manager() 467 ? safe_browsing_service->database_manager()
461 : NULL), 468 : NULL),
462 url_request_context_getter_(request_context_getter), 469 url_request_context_getter_(request_context_getter),
463 collect_environment_data_fn_(&CollectEnvironmentData), 470 collect_environment_data_fn_(&CollectEnvironmentData),
464 environment_collection_task_runner_( 471 environment_collection_task_runner_(
465 content::BrowserThread::GetBlockingPool() 472 content::BrowserThread::GetBlockingPool()
466 ->GetTaskRunnerWithShutdownBehavior( 473 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
467 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
468 environment_collection_pending_(), 474 environment_collection_pending_(),
469 collation_timeout_pending_(), 475 collation_timeout_pending_(),
470 collation_timer_(FROM_HERE, 476 collation_timer_(FROM_HERE,
471 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), 477 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs),
472 this, 478 this,
473 &IncidentReportingService::OnCollationTimeout), 479 &IncidentReportingService::OnCollationTimeout),
474 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner), 480 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner),
475 extended_reporting_only_delayed_analysis_callbacks_(delayed_task_interval, 481 extended_reporting_only_delayed_analysis_callbacks_(delayed_task_interval,
476 delayed_task_runner), 482 delayed_task_runner),
477 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), 483 download_metadata_manager_(content::BrowserThread::GetBlockingPool()),
(...skipping 12 matching lines...) Expand all
490 void IncidentReportingService::SetCollectEnvironmentHook( 496 void IncidentReportingService::SetCollectEnvironmentHook(
491 CollectEnvironmentDataFn collect_environment_data_hook, 497 CollectEnvironmentDataFn collect_environment_data_hook,
492 const scoped_refptr<base::TaskRunner>& task_runner) { 498 const scoped_refptr<base::TaskRunner>& task_runner) {
493 if (collect_environment_data_hook) { 499 if (collect_environment_data_hook) {
494 collect_environment_data_fn_ = collect_environment_data_hook; 500 collect_environment_data_fn_ = collect_environment_data_hook;
495 environment_collection_task_runner_ = task_runner; 501 environment_collection_task_runner_ = task_runner;
496 } else { 502 } else {
497 collect_environment_data_fn_ = &CollectEnvironmentData; 503 collect_environment_data_fn_ = &CollectEnvironmentData;
498 environment_collection_task_runner_ = 504 environment_collection_task_runner_ =
499 content::BrowserThread::GetBlockingPool() 505 content::BrowserThread::GetBlockingPool()
500 ->GetTaskRunnerWithShutdownBehavior( 506 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior());
501 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
502 } 507 }
503 } 508 }
504 509
505 void IncidentReportingService::DoExtensionCollection( 510 void IncidentReportingService::DoExtensionCollection(
506 ClientIncidentReport_ExtensionData* extension_data) { 511 ClientIncidentReport_ExtensionData* extension_data) {
507 CollectExtensionData(extension_data); 512 CollectExtensionData(extension_data);
508 } 513 }
509 514
510 void IncidentReportingService::OnProfileAdded(Profile* profile) { 515 void IncidentReportingService::OnProfileAdded(Profile* profile) {
511 DCHECK(thread_checker_.CalledOnValidThread()); 516 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 if (!profile->IsOffTheRecord()) 1152 if (!profile->IsOffTheRecord())
1148 OnProfileDestroyed(profile); 1153 OnProfileDestroyed(profile);
1149 break; 1154 break;
1150 } 1155 }
1151 default: 1156 default:
1152 break; 1157 break;
1153 } 1158 }
1154 } 1159 }
1155 1160
1156 } // namespace safe_browsing 1161 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698