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

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: Changed to feature 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
« no previous file with comments | « no previous file | chrome/common/chrome_features.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string>
11 #include <utility> 12 #include <utility>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/metrics/field_trial.h" 17 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/process/process_info.h" 19 #include "base/process/process_info.h"
19 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
20 #include "base/stl_util.h" 21 #include "base/stl_util.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
23 #include "base/threading/sequenced_worker_pool.h" 24 #include "base/threading/sequenced_worker_pool.h"
24 #include "build/build_config.h" 25 #include "build/build_config.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"
35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
37 #include "chrome/common/chrome_features.h"
36 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
37 #include "chrome/common/safe_browsing/csd.pb.h" 39 #include "chrome/common/safe_browsing/csd.pb.h"
38 #include "components/prefs/pref_service.h" 40 #include "components/prefs/pref_service.h"
39 #include "components/safe_browsing_db/database_manager.h" 41 #include "components/safe_browsing_db/database_manager.h"
40 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h " 42 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h "
41 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
43 #include "net/url_request/url_request_context_getter.h" 45 #include "net/url_request/url_request_context_getter.h"
44 46
45 namespace safe_browsing { 47 namespace safe_browsing {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 case MinimumProfileConsent::SAFE_BROWSING_ENABLED: 141 case MinimumProfileConsent::SAFE_BROWSING_ENABLED:
140 return true; 142 return true;
141 case MinimumProfileConsent::SAFE_BROWSING_EXTENDED_REPORTING_ENABLED: 143 case MinimumProfileConsent::SAFE_BROWSING_EXTENDED_REPORTING_ENABLED:
142 return profile->GetPrefs()->GetBoolean( 144 return profile->GetPrefs()->GetBoolean(
143 prefs::kSafeBrowsingExtendedReportingEnabled); 145 prefs::kSafeBrowsingExtendedReportingEnabled);
144 } 146 }
145 NOTREACHED(); 147 NOTREACHED();
146 return false; 148 return false;
147 } 149 }
148 150
151 // Returns the shutdown behavior for the task runners of the incident reporting
152 // service. Current metrics suggest that CONTINUE_ON_SHUTDOWN will reduce the
153 // number of browser hangs on shutdown.
154 base::SequencedWorkerPool::WorkerShutdown GetShutdownBehavior() {
155 return base::FeatureList::IsEnabled(features::kBrowserHangFixesExperiment)
156 ? base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN
157 : base::SequencedWorkerPool::SKIP_ON_SHUTDOWN;
158 }
159
149 } // namespace 160 } // namespace
150 161
151 struct IncidentReportingService::ProfileContext { 162 struct IncidentReportingService::ProfileContext {
152 ProfileContext(); 163 ProfileContext();
153 ~ProfileContext(); 164 ~ProfileContext();
154 165
155 // Returns true if the profile has incidents to be uploaded or cleared. 166 // Returns true if the profile has incidents to be uploaded or cleared.
156 bool HasIncidents() const; 167 bool HasIncidents() const;
157 168
158 // The incidents collected for this profile pending creation and/or upload. 169 // 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) 342 SafeBrowsingService* safe_browsing_service)
332 : database_manager_(safe_browsing_service 343 : database_manager_(safe_browsing_service
333 ? safe_browsing_service->database_manager() 344 ? safe_browsing_service->database_manager()
334 : nullptr), 345 : nullptr),
335 url_request_context_getter_( 346 url_request_context_getter_(
336 safe_browsing_service ? safe_browsing_service->url_request_context() 347 safe_browsing_service ? safe_browsing_service->url_request_context()
337 : nullptr), 348 : nullptr),
338 collect_environment_data_fn_(&CollectEnvironmentData), 349 collect_environment_data_fn_(&CollectEnvironmentData),
339 environment_collection_task_runner_( 350 environment_collection_task_runner_(
340 content::BrowserThread::GetBlockingPool() 351 content::BrowserThread::GetBlockingPool()
341 ->GetTaskRunnerWithShutdownBehavior( 352 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
342 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
343 environment_collection_pending_(), 353 environment_collection_pending_(),
344 collation_timeout_pending_(), 354 collation_timeout_pending_(),
345 collation_timer_(FROM_HERE, 355 collation_timer_(FROM_HERE,
346 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), 356 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs),
347 this, 357 this,
348 &IncidentReportingService::OnCollationTimeout), 358 &IncidentReportingService::OnCollationTimeout),
349 delayed_analysis_callbacks_( 359 delayed_analysis_callbacks_(
350 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), 360 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs),
351 content::BrowserThread::GetBlockingPool() 361 content::BrowserThread::GetBlockingPool()
352 ->GetTaskRunnerWithShutdownBehavior( 362 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
353 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
354 extended_reporting_only_delayed_analysis_callbacks_( 363 extended_reporting_only_delayed_analysis_callbacks_(
355 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs), 364 base::TimeDelta::FromMilliseconds(kDefaultCallbackIntervalMs),
356 content::BrowserThread::GetBlockingPool() 365 content::BrowserThread::GetBlockingPool()
357 ->GetTaskRunnerWithShutdownBehavior( 366 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
358 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
359 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), 367 download_metadata_manager_(content::BrowserThread::GetBlockingPool()),
360 receiver_weak_ptr_factory_(this), 368 receiver_weak_ptr_factory_(this),
361 weak_ptr_factory_(this) { 369 weak_ptr_factory_(this) {
362 notification_registrar_.Add(this, 370 notification_registrar_.Add(this,
363 chrome::NOTIFICATION_PROFILE_ADDED, 371 chrome::NOTIFICATION_PROFILE_ADDED,
364 content::NotificationService::AllSources()); 372 content::NotificationService::AllSources());
365 notification_registrar_.Add(this, 373 notification_registrar_.Add(this,
366 chrome::NOTIFICATION_PROFILE_DESTROYED, 374 chrome::NOTIFICATION_PROFILE_DESTROYED,
367 content::NotificationService::AllSources()); 375 content::NotificationService::AllSources());
368 DownloadProtectionService* download_protection_service = 376 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, 464 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
457 base::TimeDelta delayed_task_interval, 465 base::TimeDelta delayed_task_interval,
458 const scoped_refptr<base::TaskRunner>& delayed_task_runner) 466 const scoped_refptr<base::TaskRunner>& delayed_task_runner)
459 : database_manager_(safe_browsing_service 467 : database_manager_(safe_browsing_service
460 ? safe_browsing_service->database_manager() 468 ? safe_browsing_service->database_manager()
461 : NULL), 469 : NULL),
462 url_request_context_getter_(request_context_getter), 470 url_request_context_getter_(request_context_getter),
463 collect_environment_data_fn_(&CollectEnvironmentData), 471 collect_environment_data_fn_(&CollectEnvironmentData),
464 environment_collection_task_runner_( 472 environment_collection_task_runner_(
465 content::BrowserThread::GetBlockingPool() 473 content::BrowserThread::GetBlockingPool()
466 ->GetTaskRunnerWithShutdownBehavior( 474 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior())),
467 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
468 environment_collection_pending_(), 475 environment_collection_pending_(),
469 collation_timeout_pending_(), 476 collation_timeout_pending_(),
470 collation_timer_(FROM_HERE, 477 collation_timer_(FROM_HERE,
471 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs), 478 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs),
472 this, 479 this,
473 &IncidentReportingService::OnCollationTimeout), 480 &IncidentReportingService::OnCollationTimeout),
474 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner), 481 delayed_analysis_callbacks_(delayed_task_interval, delayed_task_runner),
475 extended_reporting_only_delayed_analysis_callbacks_(delayed_task_interval, 482 extended_reporting_only_delayed_analysis_callbacks_(delayed_task_interval,
476 delayed_task_runner), 483 delayed_task_runner),
477 download_metadata_manager_(content::BrowserThread::GetBlockingPool()), 484 download_metadata_manager_(content::BrowserThread::GetBlockingPool()),
(...skipping 12 matching lines...) Expand all
490 void IncidentReportingService::SetCollectEnvironmentHook( 497 void IncidentReportingService::SetCollectEnvironmentHook(
491 CollectEnvironmentDataFn collect_environment_data_hook, 498 CollectEnvironmentDataFn collect_environment_data_hook,
492 const scoped_refptr<base::TaskRunner>& task_runner) { 499 const scoped_refptr<base::TaskRunner>& task_runner) {
493 if (collect_environment_data_hook) { 500 if (collect_environment_data_hook) {
494 collect_environment_data_fn_ = collect_environment_data_hook; 501 collect_environment_data_fn_ = collect_environment_data_hook;
495 environment_collection_task_runner_ = task_runner; 502 environment_collection_task_runner_ = task_runner;
496 } else { 503 } else {
497 collect_environment_data_fn_ = &CollectEnvironmentData; 504 collect_environment_data_fn_ = &CollectEnvironmentData;
498 environment_collection_task_runner_ = 505 environment_collection_task_runner_ =
499 content::BrowserThread::GetBlockingPool() 506 content::BrowserThread::GetBlockingPool()
500 ->GetTaskRunnerWithShutdownBehavior( 507 ->GetTaskRunnerWithShutdownBehavior(GetShutdownBehavior());
501 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
502 } 508 }
503 } 509 }
504 510
505 void IncidentReportingService::DoExtensionCollection( 511 void IncidentReportingService::DoExtensionCollection(
506 ClientIncidentReport_ExtensionData* extension_data) { 512 ClientIncidentReport_ExtensionData* extension_data) {
507 CollectExtensionData(extension_data); 513 CollectExtensionData(extension_data);
508 } 514 }
509 515
510 void IncidentReportingService::OnProfileAdded(Profile* profile) { 516 void IncidentReportingService::OnProfileAdded(Profile* profile) {
511 DCHECK(thread_checker_.CalledOnValidThread()); 517 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 if (!profile->IsOffTheRecord()) 1153 if (!profile->IsOffTheRecord())
1148 OnProfileDestroyed(profile); 1154 OnProfileDestroyed(profile);
1149 break; 1155 break;
1150 } 1156 }
1151 default: 1157 default:
1152 break; 1158 break;
1153 } 1159 }
1154 } 1160 }
1155 1161
1156 } // namespace safe_browsing 1162 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_features.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698