blob: 443348c2de005a91ff0338d8d988fdb9e765bc1c [file] [log] [blame]
[email protected]3a80ea332012-01-09 19:53:291// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/browser/browser_process_impl.h"
6
avie4d7b6f2015-12-26 00:59:187#include <stddef.h>
dcheng4af48582016-04-19 00:29:358
[email protected]38489a32012-05-11 02:24:549#include <algorithm>
[email protected]3cdacd42010-04-30 18:55:5310#include <map>
dchenge73d8520c2015-12-27 01:19:0911#include <utility>
[email protected]68f88b992011-05-07 02:01:3912#include <vector>
[email protected]3cdacd42010-04-30 18:55:5313
[email protected]7a6af7e2014-07-08 20:11:1314#include "base/atomic_ref_count.h"
[email protected]b3cc0542011-11-19 22:43:4415#include "base/bind.h"
16#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/command_line.h"
[email protected]69c019472013-10-15 05:03:4718#include "base/debug/leak_annotations.h"
[email protected]c027d6d2014-06-05 15:25:4019#include "base/files/file_path.h"
fdoray283082bd2016-06-02 20:18:4620#include "base/location.h"
avie4d7b6f2015-12-26 00:59:1821#include "base/macros.h"
dcheng4af48582016-04-19 00:29:3522#include "base/memory/ptr_util.h"
rkaplow1b23b7d2015-02-13 20:52:4923#include "base/metrics/histogram_macros.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/path_service.h"
gab7af9dc02017-05-05 13:38:5425#include "base/run_loop.h"
fdoray283082bd2016-06-02 20:18:4626#include "base/single_thread_task_runner.h"
[email protected]985655a2011-02-23 09:54:2527#include "base/synchronization/waitable_event.h"
Gabriel Charette44db1422018-08-06 11:19:3328#include "base/task/task_traits.h"
Gabriel Charette055039132020-02-26 23:02:0629#include "base/task/thread_pool.h"
[email protected]34b99632011-01-01 01:01:0630#include "base/threading/thread.h"
31#include "base/threading/thread_restrictions.h"
fdoray283082bd2016-06-02 20:18:4632#include "base/threading/thread_task_runner_handle.h"
mabc0bf2792016-02-25 23:31:4733#include "base/time/default_clock.h"
[email protected]72f93712014-05-19 15:10:3934#include "base/time/default_tick_clock.h"
rkaplow1b23b7d2015-02-13 20:52:4935#include "base/trace_event/trace_event.h"
avie4d7b6f2015-12-26 00:59:1836#include "build/build_config.h"
Ryan Sturmf0ad4292019-05-10 00:51:1037#include "chrome/browser/battery/battery_metrics.h"
Hans Wennborg63344452019-10-15 10:15:2138#include "chrome/browser/browser_process_platform_part.h"
[email protected]c38831a12011-10-28 12:44:4939#include "chrome/browser/chrome_browser_main.h"
[email protected]572f40c9b2012-07-06 20:35:3340#include "chrome/browser/chrome_content_browser_client.h"
[email protected]fdf40f3e2013-07-11 23:55:4641#include "chrome/browser/chrome_notification_types.h"
[email protected]de0fdca22014-08-19 05:26:0942#include "chrome/browser/component_updater/chrome_component_updater_configurator.h"
[email protected]195c99c2012-10-31 06:24:5143#include "chrome/browser/defaults.h"
[email protected]70019152012-12-19 11:44:1944#include "chrome/browser/devtools/remote_debugging_server.h"
[email protected]254ed742011-08-16 18:45:2745#include "chrome/browser/download/download_request_limiter.h"
[email protected]75e51b52012-02-04 16:57:5446#include "chrome/browser/download/download_status_updater.h"
[email protected]e6933d2a2013-03-12 22:32:2147#include "chrome/browser/gpu/gpu_mode_manager.h"
[email protected]dcefa302009-05-20 00:24:3948#include "chrome/browser/icon_manager.h"
[email protected]c4ff4952010-01-08 19:12:4749#include "chrome/browser/intranet_redirect_detector.h"
[email protected]2e6389f2012-05-18 19:41:2550#include "chrome/browser/lifetime/application_lifetime.h"
Collin Baker62965522020-02-06 01:35:5751#include "chrome/browser/lifetime/browser_shutdown.h"
Lei Zhangdb5696b2017-11-20 21:13:4052#include "chrome/browser/lifetime/switch_utils.h"
Patrik Höglundb564859b2018-05-17 11:17:1653#include "chrome/browser/media/webrtc/webrtc_event_log_manager.h"
54#include "chrome/browser/media/webrtc/webrtc_log_uploader.h"
Xi Han07bad2892018-10-04 15:13:5855#include "chrome/browser/metrics/chrome_feature_list_creator.h"
blundellfecea528d2015-10-21 10:10:2256#include "chrome/browser/metrics/chrome_metrics_services_manager_client.h"
Alexei Svitkine9e9c3092019-01-08 03:14:2957#include "chrome/browser/metrics/metrics_reporting_state.h"
[email protected]0b565182011-03-02 18:11:1558#include "chrome/browser/metrics/thread_watcher.h"
Matt Menke21b9cc62017-08-23 15:45:4559#include "chrome/browser/net/system_network_context_manager.h"
miguelg23cd2dd72016-04-21 15:24:0360#include "chrome/browser/notifications/notification_platform_bridge.h"
Toni Barzicb598380e2018-11-26 19:14:1061#include "chrome/browser/notifications/system_notification_helper.h"
Clark DuVall38189ee2020-02-14 02:30:2862#include "chrome/browser/permissions/chrome_permissions_client.h"
Scott Violetfdd6f352018-01-12 19:12:2963#include "chrome/browser/policy/chrome_browser_policy_connector.h"
[email protected]caf63aea2011-04-26 11:04:1064#include "chrome/browser/prefs/browser_prefs.h"
[email protected]5b199522012-12-22 17:24:4465#include "chrome/browser/prefs/chrome_pref_service_factory.h"
[email protected]68f88b992011-05-07 02:01:3966#include "chrome/browser/printing/background_printing_manager.h"
[email protected]e06131d2010-02-10 18:40:3367#include "chrome/browser/printing/print_job_manager.h"
[email protected]d8ce31e2012-12-19 05:09:2168#include "chrome/browser/printing/print_preview_dialog_controller.h"
[email protected]8ecad5e2010-12-02 21:18:3369#include "chrome/browser/profiles/profile_manager.h"
Sebastien Marchand2ebd9252018-11-08 18:39:3570#include "chrome/browser/resource_coordinator/resource_coordinator_parts.h"
[email protected]81218f42009-02-05 18:48:0871#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]e450fa62011-02-01 12:52:5672#include "chrome/browser/shell_integration.h"
Lukasz Anforowicz65c61162019-03-27 20:33:5873#include "chrome/browser/site_isolation/prefs_observer.h"
Lukasz Anforowicz60d1253d2019-05-08 16:31:3774#include "chrome/browser/ssl/secure_origin_prefs_observer.h"
Xi Han85079c22019-04-18 21:43:0575#include "chrome/browser/startup_data.h"
[email protected]9e7f015f2011-05-28 00:24:2576#include "chrome/browser/status_icons/status_tray.h"
[email protected]94840bb2013-12-17 19:43:3877#include "chrome/browser/ui/browser_dialogs.h"
sorin39eab2f2015-01-06 01:09:0878#include "chrome/browser/update_client/chrome_update_query_params_delegate.h"
Scott Violet6200d332018-02-23 21:29:2379#include "chrome/common/buildflags.h"
droger64d71f12015-08-24 11:35:1180#include "chrome/common/channel_info.h"
[email protected]4ef795df2010-02-03 02:35:0881#include "chrome/common/chrome_constants.h"
sammc2a1451c2017-03-29 04:14:0682#include "chrome/common/chrome_features.h"
initial.commit09911bf2008-07-26 23:55:2983#include "chrome/common/chrome_paths.h"
84#include "chrome/common/chrome_switches.h"
[email protected]ad8b4ba2013-08-09 19:52:4485#include "chrome/common/extensions/chrome_extensions_client.h"
initial.commit09911bf2008-07-26 23:55:2986#include "chrome/common/pref_names.h"
[email protected]985655a2011-02-23 09:54:2587#include "chrome/common/url_constants.h"
Richard Knoll2b971e12019-04-18 09:54:2888#include "chrome/grit/chromium_strings.h"
[email protected]48ff2c7f2014-05-23 09:57:4589#include "chrome/installer/util/google_update_settings.h"
[email protected]de0fdca22014-08-19 05:26:0990#include "components/component_updater/component_updater_service.h"
Tibor Goldschwendt5f173cb2018-06-21 22:50:4091#include "components/component_updater/timer_update_scheduler.h"
Robert Sesek0f93c582017-12-19 15:13:4392#include "components/crash/core/common/crash_key.h"
Yao Xiao431dec62020-06-25 14:13:0693#include "components/federated_learning/floc_blocklist_service.h"
94#include "components/federated_learning/floc_constants.h"
Yao Xiaocc8e0c42020-10-01 17:34:4695#include "components/federated_learning/floc_sorting_lsh_clusters_service.h"
[email protected]c027d6d2014-06-05 15:25:4096#include "components/gcm_driver/gcm_driver.h"
Ran Ji73f3b432018-07-15 22:10:2797#include "components/language/core/browser/pref_names.h"
brettwe1f0af8b2015-10-09 21:30:4698#include "components/metrics/metrics_pref_names.h"
[email protected]d6147bd2014-06-11 01:58:1999#include "components/metrics/metrics_service.h"
blundell695d61f2015-10-21 11:25:53100#include "components/metrics_services_manager/metrics_services_manager.h"
Xi Han07bad2892018-10-04 15:13:58101#include "components/metrics_services_manager/metrics_services_manager_client.h"
[email protected]d0ab865b2014-06-04 19:41:34102#include "components/network_time/network_time_tracker.h"
Sophie Chang7b02ca692019-07-09 17:57:59103#include "components/optimization_guide/optimization_guide_features.h"
Sophie Changf453c0522017-11-03 06:33:49104#include "components/optimization_guide/optimization_guide_service.h"
Clark DuVall38189ee2020-02-14 02:30:28105#include "components/permissions/permissions_client.h"
[email protected]76b4b152013-12-08 21:10:04106#include "components/policy/core/common/policy_service.h"
brettwb1fc1b82016-02-02 00:19:08107#include "components/prefs/json_pref_store.h"
108#include "components/prefs/pref_registry_simple.h"
109#include "components/prefs/pref_service.h"
nzolghadrd87a308d2016-12-07 15:45:56110#include "components/rappor/public/rappor_utils.h"
111#include "components/rappor/rappor_service_impl.h"
Ali Jumafb3dc1f2020-01-07 17:33:47112#include "components/safe_browsing/core/safe_browsing_service_interface.h"
Mikel Astizf61f4ba02018-06-01 10:50:19113#include "components/sessions/core/session_id_generator.h"
Eric Robinson49f19b62018-09-17 21:28:15114#include "components/subresource_filter/content/browser/ruleset_service.h"
[email protected]bb1c86cd2014-01-29 18:22:18115#include "components/translate/core/browser/translate_download_manager.h"
oysteineb068f272017-05-23 00:14:01116#include "components/ukm/ukm_service.h"
sorin39eab2f2015-01-06 01:09:08117#include "components/update_client/update_query_params.h"
Xi Hana05ca5e2018-10-17 21:33:06118#include "components/variations/service/variations_service.h"
drogerf8479942014-11-21 17:47:53119#include "components/web_resource/web_resource_pref_names.h"
Eric Seckler8652dcd52018-09-20 10:42:28120#include "content/public/browser/browser_task_traits.h"
[email protected]c38831a12011-10-28 12:44:49121#include "content/public/browser/browser_thread.h"
[email protected]b9535422012-02-09 01:47:59122#include "content/public/browser/child_process_security_policy.h"
Tarun Bansal86b39222018-09-21 02:07:32123#include "content/public/browser/network_quality_observer_factory.h"
Helen Li72c87ae42017-11-06 18:31:56124#include "content/public/browser/network_service_instance.h"
[email protected]ad50def52011-10-19 23:17:07125#include "content/public/browser/notification_details.h"
[email protected]f3b1a082011-11-18 00:34:30126#include "content/public/browser/render_process_host.h"
[email protected]294bdb32014-05-30 07:01:54127#include "content/public/browser/service_worker_context.h"
128#include "content/public/browser/storage_partition.h"
Helen Li72c87ae42017-11-06 18:31:56129#include "content/public/common/content_features.h"
brettw90e92602015-10-10 00:12:40130#include "content/public/common/content_switches.h"
Matt Mueller859c9c72020-02-13 20:27:26131#include "content/public/common/network_service_util.h"
Scott Violetc8240b02018-03-08 22:03:59132#include "extensions/buildflags/buildflags.h"
[email protected]885c0e92012-11-13 20:27:42133#include "extensions/common/constants.h"
Scott Violeta35f9a42018-03-22 22:00:44134#include "media/media_buildflags.h"
Julie Jeongeun Kim17b2adf12019-10-29 10:24:48135#include "mojo/public/cpp/bindings/pending_receiver.h"
Matt Mueller859c9c72020-02-13 20:27:26136#include "net/log/net_log.h"
Scott Violet02e38b92018-03-27 23:42:14137#include "ppapi/buildflags/buildflags.h"
Scott Violet318a55f2018-03-30 19:08:19138#include "printing/buildflags/buildflags.h"
Eric Roman2b9260e2018-10-17 23:18:53139#include "services/network/public/cpp/features.h"
John Abd-El-Malek91243b32018-01-19 06:08:33140#include "services/network/public/cpp/network_switches.h"
derat49b2fd52015-01-16 15:32:12141#include "ui/base/idle/idle.h"
[email protected]c051a1b2011-01-21 23:30:17142#include "ui/base/l10n/l10n_util.h"
Evan Stade48b42852018-05-16 17:52:46143#include "ui/base/ui_base_features.h"
[email protected]b112a4c2009-02-01 20:24:01144
145#if defined(OS_WIN)
[email protected]770c6d82012-09-06 22:21:32146#include "base/win/windows_version.h"
Avi Drissman2e458df2020-07-29 16:24:31147#elif defined(OS_MAC)
[email protected]03d8d3e92011-09-20 06:07:11148#include "chrome/browser/chrome_browser_main_mac.h"
Lei Zhang3c258f92019-12-11 20:47:55149#include "chrome/browser/media/webrtc/system_media_capture_permissions_stats_mac.h"
[email protected]86230b92009-11-23 20:38:38150#endif
151
Scott Violet41d9e2a2018-06-20 23:36:00152#if !defined(OS_CHROMEOS)
Evan Stade4d8df162018-06-07 16:59:25153#include "ui/message_center/message_center.h"
Evan Stade196ec042018-03-13 19:44:36154#endif
155
Tibor Goldschwendt11b3cf22018-07-04 15:32:44156#if defined(OS_ANDROID)
Tibor Goldschwendt11b3cf22018-07-04 15:32:44157#include "chrome/browser/android/component_updater/background_task_update_scheduler.h"
Henrique Nakashima476b0b52020-01-24 22:28:03158#include "chrome/browser/flags/android/chrome_feature_list.h"
Mugdha Lakhania372586d2020-04-08 21:02:06159#include "chrome/browser/ssl/chrome_security_state_client.h"
Tibor Goldschwendt11b3cf22018-07-04 15:32:44160#else
Collin Baker06abf002020-09-24 19:20:12161#include "chrome/browser/devtools/devtools_auto_opener.h"
peter9f4490a2017-01-27 00:58:36162#include "chrome/browser/gcm/gcm_product_util.h"
Lei Zhang3c258f92019-12-11 20:47:55163#include "chrome/browser/resource_coordinator/tab_manager.h"
Collin Baker8a217552019-05-29 19:47:51164#include "chrome/browser/ui/browser_finder.h"
Collin Baker06abf002020-09-24 19:20:12165#include "chrome/browser/ui/browser_list.h"
[email protected]cb6341e2014-06-17 03:32:02166#include "components/gcm_driver/gcm_client_factory.h"
jitendra.ksb1b7fee2015-09-22 17:42:53167#include "components/gcm_driver/gcm_desktop_utils.h"
Michael Giuffrida2dbce0d12017-09-02 03:30:59168#include "components/keep_alive_registry/keep_alive_registry.h"
[email protected]4189bc222012-03-29 23:11:47169#endif
170
Denis Kuznetsov32099f32017-12-15 14:04:57171#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
thestige4155842014-10-20 18:58:02172#include "chrome/browser/background/background_mode_manager.h"
173#endif
174
brettw00899e62016-11-12 02:10:17175#if BUILDFLAG(ENABLE_EXTENSIONS)
Devlin Cronin40cae062018-09-07 18:34:18176#include "chrome/browser/apps/platform_apps/chrome_apps_browser_api_provider.h"
[email protected]d5a74be2014-08-08 01:01:27177#include "chrome/browser/extensions/chrome_extensions_browser_client.h"
[email protected]84b7a552014-07-19 04:52:06178#include "chrome/browser/extensions/event_router_forwarder.h"
[email protected]84b7a552014-07-19 04:52:06179#include "chrome/browser/media_galleries/media_file_system_registry.h"
thestigdc377202014-10-28 22:06:02180#include "chrome/browser/ui/apps/chrome_app_window_client.h"
Devlin Cronin10d5669e2018-08-20 15:59:06181#include "chrome/common/initialize_extensions_client.h"
[email protected]84b7a552014-07-19 04:52:06182#include "components/storage_monitor/storage_monitor.h"
thestige4155842014-10-20 18:58:02183#include "extensions/common/extension_l10n_util.h"
[email protected]84b7a552014-07-19 04:52:06184#endif
185
bauerbecab4f52017-03-13 20:16:41186#if BUILDFLAG(ENABLE_PLUGINS)
Lei Zhang3c258f92019-12-11 20:47:55187#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
188#include "chrome/browser/plugins/plugin_finder.h"
[email protected]cb6341e2014-06-17 03:32:02189#include "chrome/browser/plugins/plugins_resource_service.h"
Lei Zhang3c258f92019-12-11 20:47:55190#include "content/public/browser/plugin_service.h"
georgesak7b5281922015-06-30 13:25:17191#endif
192
thestig6ad7fe512015-10-01 06:40:27193#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
194#include "chrome/browser/first_run/upgrade_util.h"
Evan Stade4d8df162018-06-07 16:59:25195#include "chrome/browser/notifications/notification_ui_manager.h"
Mike Wasserman0fc30aa42018-02-08 18:43:20196#include "chrome/browser/ui/user_manager.h"
Guillaume Jenkins711bf012020-07-31 19:49:40197#include "components/enterprise/browser/controller/chrome_browser_cloud_management_controller.h"
thestig6ad7fe512015-10-01 06:40:27198#endif
199
Toby H5cfaf942019-07-25 22:54:50200#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
201#include "chrome/browser/component_updater/supervised_user_whitelist_installer.h"
202#endif
203
[email protected]3cdacd42010-04-30 18:55:53204#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
205// How often to check if the persistent instance of Chrome needs to restart
206// to install an update.
207static const int kUpdateCheckIntervalHours = 6;
208#endif
209
hashimotoe0e304c2015-04-14 04:32:15210#if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE)
[email protected]6ef01ac2014-02-19 02:06:40211// How long to wait for the File thread to complete during EndSession, on Linux
212// and Windows. We have a timeout here because we're unable to run the UI
213// messageloop and there's some deadlock risk. Our only option is to exit
214// anyway.
sammc2a1451c2017-03-29 04:14:06215static constexpr base::TimeDelta kEndSessionTimeout =
216 base::TimeDelta::FromSeconds(10);
[email protected]c6032e82010-09-13 20:06:05217#endif
218
[email protected]631bb742011-11-02 11:29:39219using content::BrowserThread;
[email protected]b9535422012-02-09 01:47:59220using content::ChildProcessSecurityPolicy;
[email protected]631bb742011-11-02 11:29:39221
billorrfc622a502016-11-30 01:55:15222rappor::RapporService* GetBrowserRapporService() {
223 if (g_browser_process != nullptr)
224 return g_browser_process->rappor_service();
225 return nullptr;
226}
227
Greg Thompsond4ecaa92020-08-20 09:15:40228BrowserProcessImpl::BrowserProcessImpl(StartupData* startup_data)
229 : startup_data_(startup_data),
230 browser_policy_connector_(startup_data->chrome_feature_list_creator()
231 ->TakeChromeBrowserPolicyConnector()),
232 local_state_(
233 startup_data->chrome_feature_list_creator()->TakePrefService()),
234 platform_part_(std::make_unique<BrowserProcessPlatformPart>()) {
initial.commit09911bf2008-07-26 23:55:29235 g_browser_process = this;
Xi Han07bad2892018-10-04 15:13:58236
Xi Han85079c22019-04-18 21:43:05237 DCHECK(startup_data);
Scott Violet875789e2018-02-02 07:46:48238 // Most work should be done in Init().
239}
240
241void BrowserProcessImpl::Init() {
Matt Mueller859c9c72020-02-13 20:27:26242 if (content::IsOutOfProcessNetworkService()) {
243 // Initialize NetLog source IDs to use an alternate starting value for
244 // the browser process. This needs to be done early in process startup
245 // before any NetLogSource objects might get created.
246 net::NetLog::Get()->InitializeSourceIdPartition();
247 }
248
Scott Violet875789e2018-02-02 07:46:48249#if defined(OS_CHROMEOS)
Darwin Huang663c17d2020-02-06 01:10:01250 // Forces creation of |metrics_services_manager_client_| if necessary
Scott Violet875789e2018-02-02 07:46:48251 // (typically this call is a no-op as MetricsServicesManager has already been
252 // created).
253 GetMetricsServicesManager();
254 DCHECK(metrics_services_manager_client_);
255 metrics_services_manager_client_->OnCrosSettingsCreated();
256#endif
257
258 download_status_updater_ = std::make_unique<DownloadStatusUpdater>();
259
260 rappor::SetDefaultServiceAccessor(&GetBrowserRapporService);
initial.commit09911bf2008-07-26 23:55:29261
Brett Wilson65f951c2016-11-03 22:06:12262#if BUILDFLAG(ENABLE_PRINTING)
initial.commit09911bf2008-07-26 23:55:29263 // Must be created after the NotificationService.
Jeremy Romanec48d7a2018-03-01 17:35:09264 print_job_manager_ = std::make_unique<printing::PrintJobManager>();
[email protected]058e5732012-03-01 22:48:03265#endif
initial.commit09911bf2008-07-26 23:55:29266
[email protected]672c8c12013-03-07 12:30:06267 ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(
268 chrome::kChromeSearchScheme);
[email protected]8add5412011-10-01 21:02:14269
Avi Drissman2e458df2020-07-29 16:24:31270#if defined(OS_MAC)
derat49b2fd52015-01-16 15:32:12271 ui::InitIdleMonitor();
[email protected]91901092013-01-31 01:53:59272#endif
273
brettw00899e62016-11-12 02:10:17274#if BUILDFLAG(ENABLE_EXTENSIONS)
oshima8304b512014-09-19 06:35:01275 extensions::AppWindowClient::Set(ChromeAppWindowClient::GetInstance());
[email protected]84b7a552014-07-19 04:52:06276
Lei Zhang7f3a88752017-08-25 20:17:32277 extension_event_router_forwarder_ =
278 base::MakeRefCounted<extensions::EventRouterForwarder>();
[email protected]cb6341e2014-06-17 03:32:02279
Devlin Cronin10d5669e2018-08-20 15:59:06280 EnsureExtensionsClientInitialized();
[email protected]aa3dd492013-11-05 17:09:09281
Lei Zhang7f3a88752017-08-25 20:17:32282 extensions_browser_client_ =
Jeremy Romanec48d7a2018-03-01 17:35:09283 std::make_unique<extensions::ChromeExtensionsBrowserClient>();
Devlin Cronin40cae062018-09-07 18:34:18284 extensions_browser_client_->AddAPIProvider(
Devlin Cronin362a47c2018-09-26 17:02:59285 std::make_unique<chrome_apps::ChromeAppsBrowserAPIProvider>());
[email protected]aa3dd492013-11-05 17:09:09286 extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
[email protected]d5a74be2014-08-08 01:01:27287#endif
[email protected]aa3dd492013-11-05 17:09:09288
Evan Stade4d8df162018-06-07 16:59:25289#if !defined(OS_CHROMEOS)
290 message_center::MessageCenter::Initialize();
Richard Knoll2b971e12019-04-18 09:54:28291 // Set the system notification source display name ("Google Chrome" or
292 // "Chromium").
293 if (message_center::MessageCenter::Get()) {
294 message_center::MessageCenter::Get()->SetSystemNotificationAppName(
295 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
296 }
Evan Stade196ec042018-03-13 19:44:36297#endif
[email protected]8f4b69e2014-06-26 00:01:31298
Toni Barzicb598380e2018-11-26 19:14:10299 system_notification_helper_ = std::make_unique<SystemNotificationHelper>();
300
sorin39eab2f2015-01-06 01:09:08301 update_client::UpdateQueryParams::SetDelegate(
302 ChromeUpdateQueryParamsDelegate::GetInstance());
dgnfe075c82016-03-18 11:25:35303
Clark DuVall38189ee2020-02-14 02:30:28304 // Make sure permissions client has been set.
305 ChromePermissionsClient::GetInstance();
306
dgnfe075c82016-03-18 11:25:35307#if !defined(OS_ANDROID)
Michael Giuffrida2dbce0d12017-09-02 03:30:59308 KeepAliveRegistry::GetInstance()->SetIsShuttingDown(false);
dgnfe075c82016-03-18 11:25:35309 KeepAliveRegistry::GetInstance()->AddObserver(this);
310#endif // !defined(OS_ANDROID)
Scott Violet875789e2018-02-02 07:46:48311
Lei Zhangb76b80e32020-04-08 16:58:16312 MigrateObsoleteLocalStatePrefs(local_state());
Scott Violet875789e2018-02-02 07:46:48313 pref_change_registrar_.Init(local_state());
314
315 // Initialize the notification for the default browser setting policy.
316 pref_change_registrar_.Add(
317 prefs::kDefaultBrowserSettingEnabled,
Alexander Cooperbc87af32020-07-15 15:59:45318 base::BindRepeating(&BrowserProcessImpl::ApplyDefaultBrowserPolicy,
319 base::Unretained(this)));
Scott Violet875789e2018-02-02 07:46:48320
321#if !defined(OS_ANDROID)
322 // This preference must be kept in sync with external values; update them
323 // whenever the preference or its controlling policy changes.
Alexei Svitkine9e9c3092019-01-08 03:14:29324 pref_change_registrar_.Add(metrics::prefs::kMetricsReportingEnabled,
Alexander Cooperbc87af32020-07-15 15:59:45325 base::BindRepeating(&ApplyMetricsReportingPolicy));
Scott Violet875789e2018-02-02 07:46:48326#endif
327
Elad Alon3c4c7fd2018-03-26 12:06:20328 DCHECK(!webrtc_event_log_manager_);
329 webrtc_event_log_manager_ = WebRtcEventLogManager::CreateSingletonInstance();
Henrik Grunelle11045a2019-04-12 09:27:27330
Avi Drissman2e458df2020-07-29 16:24:31331#if defined(OS_MAC)
Henrik Grunelle11045a2019-04-12 09:27:27332 system_media_permissions::LogSystemMediaPermissionsStartupStats();
333#endif
initial.commit09911bf2008-07-26 23:55:29334}
335
Wez25fd35f2018-05-25 22:57:41336#if !defined(OS_ANDROID)
Filip Gorski209a3472018-08-27 23:03:41337void BrowserProcessImpl::SetQuitClosure(base::OnceClosure quit_closure) {
Wez25fd35f2018-05-25 22:57:41338 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Greg Thompson822ab51a2018-09-18 06:45:29339 DCHECK(quit_closure);
Wez25fd35f2018-05-25 22:57:41340 DCHECK(!quit_closure_);
341 quit_closure_ = std::move(quit_closure);
342}
343#endif
344
Avi Drissman2e458df2020-07-29 16:24:31345#if defined(OS_MAC)
Greg Thompson822ab51a2018-09-18 06:45:29346void BrowserProcessImpl::ClearQuitClosure() {
347 quit_closure_.Reset();
Wez25fd35f2018-05-25 22:57:41348}
349#endif
350
initial.commit09911bf2008-07-26 23:55:29351BrowserProcessImpl::~BrowserProcessImpl() {
gab25894fe2017-05-30 03:40:36352 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
brettw00899e62016-11-12 02:10:17353#if BUILDFLAG(ENABLE_EXTENSIONS)
rockot48a6aac2016-07-28 17:23:54354 extensions::ExtensionsBrowserClient::Set(nullptr);
Michael Giuffrida43228dc2017-08-03 04:29:13355 extensions::AppWindowClient::Set(nullptr);
rockot48a6aac2016-07-28 17:23:54356#endif
357
dgnfe075c82016-03-18 11:25:35358#if !defined(OS_ANDROID)
359 KeepAliveRegistry::GetInstance()->RemoveObserver(this);
Francois Doray74fe9be2018-07-13 19:48:11360#endif
dgnfe075c82016-03-18 11:25:35361
[email protected]2e5b60a22011-11-28 15:56:41362 g_browser_process = NULL;
363}
364
thestigd75ce5532015-10-05 22:08:34365#if !defined(OS_ANDROID)
[email protected]2e5b60a22011-11-28 15:56:41366void BrowserProcessImpl::StartTearDown() {
csharrisonac2baf42015-10-20 13:32:57367 TRACE_EVENT0("shutdown", "BrowserProcessImpl::StartTearDown");
csharrison058781a2015-11-24 21:44:03368 // TODO(crbug.com/560486): Fix the tests that make the check of
369 // |tearing_down_| necessary in IsShuttingDown().
370 tearing_down_ = true;
371 DCHECK(IsShuttingDown());
Michael Giuffrida2dbce0d12017-09-02 03:30:59372
csharrison058781a2015-11-24 21:44:03373 metrics_services_manager_.reset();
[email protected]c4ff4952010-01-08 19:12:47374 intranet_redirect_detector_.reset();
[email protected]ed304482013-01-04 04:45:32375 if (safe_browsing_service_.get())
[email protected]9efb46692011-08-23 12:56:05376 safe_browsing_service()->ShutDown();
mab2f07cb92016-05-10 20:55:51377 network_time_tracker_.reset();
bauerbecab4f52017-03-13 20:16:41378#if BUILDFLAG(ENABLE_PLUGINS)
droger13cf36de2015-01-27 10:20:23379 plugins_resource_service_.reset();
380#endif
initial.commit09911bf2008-07-26 23:55:29381
Owen Min9e6cb6e2020-02-04 18:55:07382#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
383 // Initial cleanup for ChromeBrowserCloudManagement, shutdown components that
384 // depend on profile and notification system. For example, ProfileManager
385 // observer and KeyServices observer need to be removed before profiles.
386 if (browser_policy_connector_ &&
387 browser_policy_connector_->chrome_browser_cloud_management_controller()) {
388 browser_policy_connector_->chrome_browser_cloud_management_controller()
389 ->ShutDown();
390 }
391#endif
392
Toni Barzicb598380e2018-11-26 19:14:10393 system_notification_helper_.reset();
394
Evan Stade4d8df162018-06-07 16:59:25395#if !defined(OS_CHROMEOS)
John Abd-El-Malek89a5f3a2019-06-14 18:21:53396 // Need to clear the desktop notification balloons before the IO thread and
[email protected]d8a899c2010-09-21 04:50:33397 // before the profiles, since if there are any still showing we will access
398 // those things during teardown.
399 notification_ui_manager_.reset();
Evan Stade4d8df162018-06-07 16:59:25400#endif
[email protected]d8a899c2010-09-21 04:50:33401
Toby H5cfaf942019-07-25 22:54:50402#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
lwchkg9c183942016-03-13 06:29:54403 // The SupervisedUserWhitelistInstaller observes the ProfileAttributesStorage,
404 // so it needs to be shut down before the ProfileManager.
bauerb22951c32015-02-12 13:18:17405 supervised_user_whitelist_installer_.reset();
Toby H5cfaf942019-07-25 22:54:50406#endif
bauerb22951c32015-02-12 13:18:17407
dgozmanb1d32782015-05-21 20:27:07408 // Debugger must be cleaned up before ProfileManager.
409 remote_debugging_server_.reset();
dgozman54cc54e2016-02-23 03:47:30410 devtools_auto_opener_.reset();
fdoray3b9a7a62016-11-11 15:31:16411
Ryan Sturmf0ad4292019-05-10 00:51:10412 battery_metrics_.reset();
413
John Abd-El-Malek89a5f3a2019-06-14 18:21:53414 // Need to clear profiles (download managers) before the IO thread.
[email protected]89af4002013-09-06 07:47:07415 {
416 TRACE_EVENT0("shutdown",
417 "BrowserProcessImpl::StartTearDown:ProfileManager");
Mike Wasserman0fc30aa42018-02-08 18:43:20418#if !defined(OS_CHROMEOS)
[email protected]94840bb2013-12-17 19:43:38419 // The desktop User Manager needs to be closed before the guest profile
420 // can be destroyed.
anthonyvd66aa95d2015-10-02 15:40:26421 UserManager::Hide();
Mike Wasserman0fc30aa42018-02-08 18:43:20422#endif // !defined(OS_CHROMEOS)
[email protected]89af4002013-09-06 07:47:07423 profile_manager_.reset();
424 }
initial.commit09911bf2008-07-26 23:55:29425
brettw00899e62016-11-12 02:10:17426#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]8b60ca722013-07-19 01:29:02427 media_file_system_registry_.reset();
[email protected]e4c5f97b2014-02-17 18:57:17428 // Remove the global instance of the Storage Monitor now. Otherwise the
429 // FILE thread would be gone when we try to release it in the dtor and
430 // Valgrind would report a leak on almost every single browser_test.
[email protected]8b60ca722013-07-19 01:29:02431 // TODO(gbillock): Make this unnecessary.
[email protected]7bfe94602014-02-25 10:22:39432 storage_monitor::StorageMonitor::Destroy();
[email protected]8b60ca722013-07-19 01:29:02433#endif
434
Evan Stade4d8df162018-06-07 16:59:25435#if !defined(OS_CHROMEOS)
Evan Stade196ec042018-03-13 19:44:36436 if (message_center::MessageCenter::Get())
437 message_center::MessageCenter::Shutdown();
Evan Stade4d8df162018-06-07 16:59:25438#endif
[email protected]356530722013-03-05 19:10:19439
[email protected]985655a2011-02-23 09:54:25440 // The policy providers managed by |browser_policy_connector_| need to shut
atwilson0fabd512015-02-27 17:13:03441 // down while the IO and FILE threads are still alive. The monitoring
442 // framework owned by |browser_policy_connector_| relies on |gcm_driver_|, so
443 // this must be shutdown before |gcm_driver_| below.
[email protected]3b19e8e2012-10-17 19:15:49444 if (browser_policy_connector_)
445 browser_policy_connector_->Shutdown();
[email protected]f2a893c2011-01-05 09:38:07446
[email protected]c027d6d2014-06-05 15:25:40447 // The |gcm_driver_| must shut down while the IO thread is still alive.
448 if (gcm_driver_)
449 gcm_driver_->Shutdown();
450
[email protected]8fd11832011-07-14 20:01:13451 // Stop the watchdog thread before stopping other threads.
452 watchdog_thread_.reset();
[email protected]4189bc222012-03-29 23:11:47453
[email protected]7cad6b0d2013-04-25 20:29:32454 platform_part()->StartTearDown();
[email protected]ab8973da2013-11-25 19:32:38455
[email protected]969ebea2014-03-28 16:50:26456 // Cancel any uploads to release the system url request context references.
457 if (webrtc_log_uploader_)
Darin Fisher8c84328c2019-07-23 02:50:00458 webrtc_log_uploader_->Shutdown();
[email protected]f3724cf2014-03-04 11:21:10459
Mikel Astizf61f4ba02018-06-01 10:50:19460 sessions::SessionIdGenerator::GetInstance()->Shutdown();
461
Lei Zhang6a40593e2017-08-23 17:16:18462 if (local_state_)
463 local_state_->CommitPendingWrite();
Matt Menke02bf09f42018-01-17 21:18:36464
465 // This expects to be destroyed before the task scheduler is torn down.
Min Qin8caab1d2018-10-03 17:28:13466 SystemNetworkContextManager::DeleteInstance();
[email protected]2e5b60a22011-11-28 15:56:41467}
[email protected]8fd11832011-07-14 20:01:13468
[email protected]99907362012-01-11 05:41:40469void BrowserProcessImpl::PostDestroyThreads() {
470 // With the file_thread_ flushed, we can release any icon resources.
471 icon_manager_.reset();
initial.commit09911bf2008-07-26 23:55:29472
Elad Alon7264d6a2018-03-21 15:06:26473 // Must outlive the worker threads.
[email protected]969ebea2014-03-28 16:50:26474 webrtc_log_uploader_.reset();
initial.commit09911bf2008-07-26 23:55:29475}
thestigd75ce5532015-10-05 22:08:34476#endif // !defined(OS_ANDROID)
initial.commit09911bf2008-07-26 23:55:29477
Xi Han07bad2892018-10-04 15:13:58478void BrowserProcessImpl::SetMetricsServices(
479 std::unique_ptr<metrics_services_manager::MetricsServicesManager> manager,
480 metrics_services_manager::MetricsServicesManagerClient* client) {
481 metrics_services_manager_ = std::move(manager);
482 metrics_services_manager_client_ =
483 static_cast<ChromeMetricsServicesManagerClient*>(client);
484}
485
[email protected]7a6af7e2014-07-08 20:11:13486namespace {
487
488// Used at the end of session to block the UI thread for completion of sentinel
489// tasks on the set of threads used to persist profile data and local state.
490// This is done to ensure that the data has been persisted to disk before
491// continuing.
492class RundownTaskCounter :
493 public base::RefCountedThreadSafe<RundownTaskCounter> {
494 public:
495 RundownTaskCounter();
496
Gabriel Charette1f53ca32018-08-07 21:31:17497 // Increments |count_| and returns a closure bound to Decrement(). All
498 // closures returned by this RundownTaskCounter's GetRundownClosure() method
499 // must be invoked for TimedWait() to complete its wait without timing
500 // out.
501 base::OnceClosure GetRundownClosure();
[email protected]7a6af7e2014-07-08 20:11:13502
Gabriel Charette1f53ca32018-08-07 21:31:17503 // Waits until the count is zero or |timeout| expires.
504 // This can only be called once per instance.
505 void TimedWait(base::TimeDelta timeout);
[email protected]7a6af7e2014-07-08 20:11:13506
507 private:
508 friend class base::RefCountedThreadSafe<RundownTaskCounter>;
509 ~RundownTaskCounter() {}
510
511 // Decrements the counter and releases the waitable event on transition to
512 // zero.
513 void Decrement();
514
515 // The count starts at one to defer the possibility of one->zero transitions
516 // until TimedWait is called.
Gabriel Charette1f53ca32018-08-07 21:31:17517 base::AtomicRefCount count_{1};
[email protected]7a6af7e2014-07-08 20:11:13518 base::WaitableEvent waitable_event_;
519
520 DISALLOW_COPY_AND_ASSIGN(RundownTaskCounter);
521};
522
Gabriel Charette1f53ca32018-08-07 21:31:17523RundownTaskCounter::RundownTaskCounter() = default;
[email protected]7a6af7e2014-07-08 20:11:13524
Gabriel Charette1f53ca32018-08-07 21:31:17525base::OnceClosure RundownTaskCounter::GetRundownClosure() {
[email protected]7a6af7e2014-07-08 20:11:13526 // As the count starts off at one, it should never get to zero unless
527 // TimedWait has been called.
Jeremy Romanee96d562017-07-06 19:09:36528 DCHECK(!count_.IsZero());
[email protected]7a6af7e2014-07-08 20:11:13529
Jeremy Romanee96d562017-07-06 19:09:36530 count_.Increment();
[email protected]7a6af7e2014-07-08 20:11:13531
Gabriel Charette1f53ca32018-08-07 21:31:17532 return base::BindOnce(&RundownTaskCounter::Decrement, this);
[email protected]7a6af7e2014-07-08 20:11:13533}
534
535void RundownTaskCounter::Decrement() {
Jeremy Romanee96d562017-07-06 19:09:36536 if (!count_.Decrement())
[email protected]7a6af7e2014-07-08 20:11:13537 waitable_event_.Signal();
538}
539
Gabriel Charette1f53ca32018-08-07 21:31:17540void RundownTaskCounter::TimedWait(base::TimeDelta timeout) {
[email protected]7a6af7e2014-07-08 20:11:13541 // Decrement the excess count from the constructor.
542 Decrement();
543
Gabriel Charette1f53ca32018-08-07 21:31:17544 // RundownTaskCounter::TimedWait() could return
545 // |waitable_event_.TimedWait()|'s result if any user ever cared about whether
546 // it returned per success or timeout. Currently no user of this API cares and
547 // as such this return value is ignored.
548 waitable_event_.TimedWait(timeout);
[email protected]7a6af7e2014-07-08 20:11:13549}
550
Helen Li5f3d96a2018-08-10 20:37:24551#if !defined(OS_ANDROID)
552void RequestProxyResolvingSocketFactoryOnUIThread(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:48553 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>
554 receiver) {
Helen Li5f3d96a2018-08-10 20:37:24555 network::mojom::NetworkContext* network_context =
556 g_browser_process->system_network_context_manager()->GetContext();
Julie Jeongeun Kim17b2adf12019-10-29 10:24:48557 network_context->CreateProxyResolvingSocketFactory(std::move(receiver));
Helen Li5f3d96a2018-08-10 20:37:24558}
559
560void RequestProxyResolvingSocketFactory(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:48561 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>
562 receiver) {
Gabriel Charettee7cdc5cd2020-05-27 23:35:05563 content::GetUIThreadTaskRunner({})->PostTask(
564 FROM_HERE, base::BindOnce(&RequestProxyResolvingSocketFactoryOnUIThread,
Julie Jeongeun Kim17b2adf12019-10-29 10:24:48565 std::move(receiver)));
Helen Li5f3d96a2018-08-10 20:37:24566}
567#endif
568
[email protected]7a6af7e2014-07-08 20:11:13569} // namespace
570
Gabriel Charetteb1af7ffb2017-07-27 06:10:35571void BrowserProcessImpl::FlushLocalStateAndReply(base::OnceClosure reply) {
Gabriel Charette1f53ca32018-08-07 21:31:17572 if (local_state_) {
573 local_state_->CommitPendingWrite(std::move(reply));
574 return;
575 }
576 base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(reply));
Gabriel Charetteb1af7ffb2017-07-27 06:10:35577}
578
initial.commit09911bf2008-07-26 23:55:29579void BrowserProcessImpl::EndSession() {
initial.commit09911bf2008-07-26 23:55:29580 // Mark all the profiles as clean.
581 ProfileManager* pm = profile_manager();
[email protected]844a1002011-04-19 11:37:21582 std::vector<Profile*> profiles(pm->GetLoadedProfiles());
Lei Zhang7f3a88752017-08-25 20:17:32583 scoped_refptr<RundownTaskCounter> rundown_counter =
584 base::MakeRefCounted<RundownTaskCounter>();
[email protected]7a6af7e2014-07-08 20:11:13585 for (size_t i = 0; i < profiles.size(); ++i) {
586 Profile* profile = profiles[i];
587 profile->SetExitType(Profile::EXIT_SESSION_ENDED);
hashimoto1e67e2a2015-04-01 04:59:46588 if (profile->GetPrefs()) {
Gabriel Charette1f53ca32018-08-07 21:31:17589 profile->GetPrefs()->CommitPendingWrite(
590 base::OnceClosure(), rundown_counter->GetRundownClosure());
hashimoto1e67e2a2015-04-01 04:59:46591 }
[email protected]7a6af7e2014-07-08 20:11:13592 }
initial.commit09911bf2008-07-26 23:55:29593
594 // Tell the metrics service it was cleanly shutdown.
asvitkinecbd420732014-08-26 22:15:40595 metrics::MetricsService* metrics = g_browser_process->metrics_service();
Lei Zhang6a40593e2017-08-23 17:16:18596 if (metrics && local_state_) {
initial.commit09911bf2008-07-26 23:55:29597 metrics->RecordStartOfSessionEnd();
[email protected]a6aa7542013-10-19 10:24:35598#if !defined(OS_CHROMEOS)
initial.commit09911bf2008-07-26 23:55:29599 // MetricsService lazily writes to prefs, force it to write now.
[email protected]a6aa7542013-10-19 10:24:35600 // On ChromeOS, chrome gets killed when hangs, so no need to
[email protected]d6147bd2014-06-11 01:58:19601 // commit metrics::prefs::kStabilitySessionEndCompleted change immediately.
Gabriel Charette1f53ca32018-08-07 21:31:17602 local_state_->CommitPendingWrite(base::OnceClosure(),
603 rundown_counter->GetRundownClosure());
[email protected]a6aa7542013-10-19 10:24:35604#endif
initial.commit09911bf2008-07-26 23:55:29605 }
606
Etienne Pierre-Dorayc6a3baf2018-12-11 22:09:51607 // This wait is legitimate and necessary on Windows, since the process will
608 // be terminated soon.
[email protected]79a75b02012-04-26 18:03:58609 // http://crbug.com/125207
Etienne Pierre-Dorayc6a3baf2018-12-11 22:09:51610 base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_wait;
[email protected]79a75b02012-04-26 18:03:58611
initial.commit09911bf2008-07-26 23:55:29612 // We must write that the profile and metrics service shutdown cleanly,
613 // otherwise on startup we'll think we crashed. So we block until done and
614 // then proceed with normal shutdown.
[email protected]7a6af7e2014-07-08 20:11:13615 //
616 // If you change the condition here, be sure to also change
617 // ProfileBrowserTests to match.
hashimotoe0e304c2015-04-14 04:32:15618#if defined(USE_X11) || defined(OS_WIN) || defined(USE_OZONE)
[email protected]7a6af7e2014-07-08 20:11:13619 // Do a best-effort wait on the successful countdown of rundown tasks. Note
620 // that if we don't complete "quickly enough", Windows will terminate our
621 // process.
[email protected]6ef01ac2014-02-19 02:06:40622 //
623 // On Windows, we previously posted a message to FILE and then ran a nested
624 // message loop, waiting for that message to be processed until quitting.
625 // However, doing so means that other messages will also be processed. In
626 // particular, if the GPU process host notices that the GPU has been killed
627 // during shutdown, it races exiting the nested loop with the process host
628 // blocking the message loop attempting to re-establish a connection to the
629 // GPU process synchronously. Because the system may not be allowing
630 // processes to launch, this can result in a hang. See
631 // http://crbug.com/318527.
Gabriel Charette1f53ca32018-08-07 21:31:17632 rundown_counter->TimedWait(kEndSessionTimeout);
[email protected]c6032e82010-09-13 20:06:05633#else
634 NOTIMPLEMENTED();
635#endif
initial.commit09911bf2008-07-26 23:55:29636}
637
blundell695d61f2015-10-21 11:25:53638metrics_services_manager::MetricsServicesManager*
639BrowserProcessImpl::GetMetricsServicesManager() {
gab25894fe2017-05-30 03:40:36640 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
blundellfecea528d2015-10-21 10:10:22641 if (!metrics_services_manager_) {
Lei Zhang7f3a88752017-08-25 20:17:32642 auto client =
Jeremy Romanec48d7a2018-03-01 17:35:09643 std::make_unique<ChromeMetricsServicesManagerClient>(local_state());
Scott Violet875789e2018-02-02 07:46:48644 metrics_services_manager_client_ = client.get();
Lei Zhang7f3a88752017-08-25 20:17:32645 metrics_services_manager_ =
Jeremy Romanec48d7a2018-03-01 17:35:09646 std::make_unique<metrics_services_manager::MetricsServicesManager>(
Lei Zhang7f3a88752017-08-25 20:17:32647 std::move(client));
blundellfecea528d2015-10-21 10:10:22648 }
[email protected]544246e2014-06-06 11:22:28649 return metrics_services_manager_.get();
650}
651
asvitkinecbd420732014-08-26 22:15:40652metrics::MetricsService* BrowserProcessImpl::metrics_service() {
gab25894fe2017-05-30 03:40:36653 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]c3cac952014-05-09 01:51:18654 return GetMetricsServicesManager()->GetMetricsService();
[email protected]e13ad79b2010-07-22 21:36:50655}
656
nzolghadrd87a308d2016-12-07 15:45:56657rappor::RapporServiceImpl* BrowserProcessImpl::rappor_service() {
gab25894fe2017-05-30 03:40:36658 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
nzolghadrd87a308d2016-12-07 15:45:56659 return GetMetricsServicesManager()->GetRapporServiceImpl();
[email protected]2a172e42014-02-21 04:06:10660}
661
Matt Menke21b9cc62017-08-23 15:45:45662SystemNetworkContextManager*
663BrowserProcessImpl::system_network_context_manager() {
664 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Min Qin8caab1d2018-10-03 17:28:13665 DCHECK(SystemNetworkContextManager::GetInstance());
666 return SystemNetworkContextManager::GetInstance();
Matt Menke21b9cc62017-08-23 15:45:45667}
668
Antonio Gomesacd1a942018-07-10 20:23:54669scoped_refptr<network::SharedURLLoaderFactory>
670BrowserProcessImpl::shared_url_loader_factory() {
671 return system_network_context_manager()->GetSharedURLLoaderFactory();
672}
673
Tarun Bansalcd6a6cb2018-06-27 22:03:22674network::NetworkQualityTracker* BrowserProcessImpl::network_quality_tracker() {
675 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Tarun Bansalcd6a6cb2018-06-27 22:03:22676 if (!network_quality_tracker_) {
677 network_quality_tracker_ = std::make_unique<network::NetworkQualityTracker>(
678 base::BindRepeating(&content::GetNetworkService));
679 }
680 return network_quality_tracker_.get();
681}
682
[email protected]0b565182011-03-02 18:11:15683WatchDogThread* BrowserProcessImpl::watchdog_thread() {
gab25894fe2017-05-30 03:40:36684 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]0b565182011-03-02 18:11:15685 if (!created_watchdog_thread_)
686 CreateWatchdogThread();
687 DCHECK(watchdog_thread_.get() != NULL);
688 return watchdog_thread_.get();
689}
690
[email protected]e13ad79b2010-07-22 21:36:50691ProfileManager* BrowserProcessImpl::profile_manager() {
gab25894fe2017-05-30 03:40:36692 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]e13ad79b2010-07-22 21:36:50693 if (!created_profile_manager_)
694 CreateProfileManager();
695 return profile_manager_.get();
696}
697
[email protected]b1de2c72013-02-06 02:45:47698PrefService* BrowserProcessImpl::local_state() {
gab25894fe2017-05-30 03:40:36699 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]e13ad79b2010-07-22 21:36:50700 return local_state_.get();
701}
702
blundell57bcfed2015-09-04 08:44:45703variations::VariationsService* BrowserProcessImpl::variations_service() {
gab25894fe2017-05-30 03:40:36704 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]c3cac952014-05-09 01:51:18705 return GetMetricsServicesManager()->GetVariationsService();
[email protected]54e26c122012-05-17 15:36:21706}
707
[email protected]7cad6b0d2013-04-25 20:29:32708BrowserProcessPlatformPart* BrowserProcessImpl::platform_part() {
709 return platform_part_.get();
[email protected]5b869962011-09-20 19:49:33710}
[email protected]db0e86dd2011-03-16 14:47:21711
[email protected]5a38dfd2012-07-23 23:22:10712extensions::EventRouterForwarder*
[email protected]3ce02412011-03-01 12:01:15713BrowserProcessImpl::extension_event_router_forwarder() {
brettw00899e62016-11-12 02:10:17714#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]3ce02412011-03-01 12:01:15715 return extension_event_router_forwarder_.get();
[email protected]84b7a552014-07-19 04:52:06716#else
717 return NULL;
718#endif
[email protected]3ce02412011-03-01 12:01:15719}
720
[email protected]e13ad79b2010-07-22 21:36:50721NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
gab25894fe2017-05-30 03:40:36722 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
miguelg23cd2dd72016-04-21 15:24:03723// TODO(miguelg) return NULL for MAC as well once native notifications
724// are enabled by default.
Evan Stade4d8df162018-06-07 16:59:25725#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
miguelg23cd2dd72016-04-21 15:24:03726 return nullptr;
Evan Stade4d8df162018-06-07 16:59:25727#else
[email protected]e13ad79b2010-07-22 21:36:50728 if (!created_notification_ui_manager_)
729 CreateNotificationUIManager();
730 return notification_ui_manager_.get();
Evan Stade4d8df162018-06-07 16:59:25731#endif
miguelg23cd2dd72016-04-21 15:24:03732}
733
734NotificationPlatformBridge* BrowserProcessImpl::notification_platform_bridge() {
thomasanderson421f86bb2017-04-05 06:32:42735#if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
miguelg23cd2dd72016-04-21 15:24:03736 if (!created_notification_bridge_)
737 CreateNotificationPlatformBridge();
738 return notification_bridge_.get();
739#else
740 return nullptr;
741#endif
[email protected]e13ad79b2010-07-22 21:36:50742}
743
Scott Violetfdd6f352018-01-12 19:12:29744policy::ChromeBrowserPolicyConnector*
745BrowserProcessImpl::browser_policy_connector() {
gab25894fe2017-05-30 03:40:36746 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]985655a2011-02-23 09:54:25747 return browser_policy_connector_.get();
[email protected]f2a893c2011-01-05 09:38:07748}
749
[email protected]a4179c2a2012-02-09 18:14:21750policy::PolicyService* BrowserProcessImpl::policy_service() {
[email protected]3b19e8e2012-10-17 19:15:49751 return browser_policy_connector()->GetPolicyService();
[email protected]a4179c2a2012-02-09 18:14:21752}
753
[email protected]e13ad79b2010-07-22 21:36:50754IconManager* BrowserProcessImpl::icon_manager() {
gab25894fe2017-05-30 03:40:36755 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]e13ad79b2010-07-22 21:36:50756 if (!created_icon_manager_)
757 CreateIconManager();
758 return icon_manager_.get();
759}
760
[email protected]e6933d2a2013-03-12 22:32:21761GpuModeManager* BrowserProcessImpl::gpu_mode_manager() {
gab25894fe2017-05-30 03:40:36762 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Lei Zhang7f3a88752017-08-25 20:17:32763 if (!gpu_mode_manager_)
Jeremy Romanec48d7a2018-03-01 17:35:09764 gpu_mode_manager_ = std::make_unique<GpuModeManager>();
[email protected]e6933d2a2013-03-12 22:32:21765 return gpu_mode_manager_.get();
766}
767
Pavel Feldmanc9ae59c2018-02-13 16:15:15768void BrowserProcessImpl::CreateDevToolsProtocolHandler() {
gab25894fe2017-05-30 03:40:36769 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]81054f812012-08-30 00:47:09770#if !defined(OS_ANDROID)
[email protected]76698ea2012-08-24 20:50:37771 // StartupBrowserCreator::LaunchBrowser can be run multiple times when browser
772 // is started with several profiles or existing browser process is reused.
Lei Zhang7f3a88752017-08-25 20:17:32773 if (!remote_debugging_server_) {
Jeremy Romanec48d7a2018-03-01 17:35:09774 remote_debugging_server_ = std::make_unique<RemoteDebuggingServer>();
[email protected]76698ea2012-08-24 20:50:37775 }
[email protected]81054f812012-08-30 00:47:09776#endif
[email protected]5613126e2011-01-31 15:27:55777}
778
dgozman54cc54e2016-02-23 03:47:30779void BrowserProcessImpl::CreateDevToolsAutoOpener() {
gab25894fe2017-05-30 03:40:36780 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
dgozman54cc54e2016-02-23 03:47:30781#if !defined(OS_ANDROID)
782 // StartupBrowserCreator::LaunchBrowser can be run multiple times when browser
783 // is started with several profiles or existing browser process is reused.
Lei Zhang7f3a88752017-08-25 20:17:32784 if (!devtools_auto_opener_)
Jeremy Romanec48d7a2018-03-01 17:35:09785 devtools_auto_opener_ = std::make_unique<DevToolsAutoOpener>();
dgozman54cc54e2016-02-23 03:47:30786#endif
787}
788
[email protected]e13ad79b2010-07-22 21:36:50789bool BrowserProcessImpl::IsShuttingDown() {
gab25894fe2017-05-30 03:40:36790 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
csharrison058781a2015-11-24 21:44:03791 // TODO(crbug.com/560486): Fix the tests that make the check of
792 // |tearing_down_| necessary here.
dgnfe075c82016-03-18 11:25:35793 return shutting_down_ || tearing_down_;
[email protected]e13ad79b2010-07-22 21:36:50794}
795
initial.commit09911bf2008-07-26 23:55:29796printing::PrintJobManager* BrowserProcessImpl::print_job_manager() {
gab25894fe2017-05-30 03:40:36797 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
initial.commit09911bf2008-07-26 23:55:29798 return print_job_manager_.get();
799}
800
[email protected]d8ce31e2012-12-19 05:09:21801printing::PrintPreviewDialogController*
802 BrowserProcessImpl::print_preview_dialog_controller() {
Brett Wilson65f951c2016-11-03 22:06:12803#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
gab25894fe2017-05-30 03:40:36804 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]d8ce31e2012-12-19 05:09:21805 if (!print_preview_dialog_controller_.get())
806 CreatePrintPreviewDialogController();
807 return print_preview_dialog_controller_.get();
[email protected]658677f2012-06-09 06:04:02808#else
809 NOTIMPLEMENTED();
810 return NULL;
[email protected]058e5732012-03-01 22:48:03811#endif
[email protected]dbeebd52010-11-16 20:34:16812}
813
[email protected]68f88b992011-05-07 02:01:39814printing::BackgroundPrintingManager*
815 BrowserProcessImpl::background_printing_manager() {
Brett Wilson65f951c2016-11-03 22:06:12816#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
gab25894fe2017-05-30 03:40:36817 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Lei Zhang7f3a88752017-08-25 20:17:32818 if (!background_printing_manager_)
[email protected]68f88b992011-05-07 02:01:39819 CreateBackgroundPrintingManager();
820 return background_printing_manager_.get();
[email protected]658677f2012-06-09 06:04:02821#else
822 NOTIMPLEMENTED();
823 return NULL;
[email protected]058e5732012-03-01 22:48:03824#endif
[email protected]68f88b992011-05-07 02:01:39825}
826
[email protected]e13ad79b2010-07-22 21:36:50827IntranetRedirectDetector* BrowserProcessImpl::intranet_redirect_detector() {
gab25894fe2017-05-30 03:40:36828 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Lei Zhang7f3a88752017-08-25 20:17:32829 if (!intranet_redirect_detector_)
[email protected]e13ad79b2010-07-22 21:36:50830 CreateIntranetRedirectDetector();
831 return intranet_redirect_detector_.get();
832}
833
834const std::string& BrowserProcessImpl::GetApplicationLocale() {
Lei Zhang97a1d2c2020-02-01 10:17:09835#if !defined(OS_CHROMEOS)
836 // TODO(crbug.com/1033644): Remove #if.
837 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
838#endif
[email protected]e13ad79b2010-07-22 21:36:50839 DCHECK(!locale_.empty());
840 return locale_;
841}
842
Michael Giuffrida693d01a2018-10-18 00:42:38843void BrowserProcessImpl::SetApplicationLocale(
Xi Han349162b2018-10-26 12:44:23844 const std::string& actual_locale) {
Scott Violet875789e2018-02-02 07:46:48845 // NOTE: this is called before any threads have been created in non-test
846 // environments.
Michael Giuffrida693d01a2018-10-18 00:42:38847 locale_ = actual_locale;
Michael Giuffrida693d01a2018-10-18 00:42:38848 ChromeContentBrowserClient::SetApplicationLocale(actual_locale);
[email protected]e5e72cc2014-07-22 19:06:49849 translate::TranslateDownloadManager::GetInstance()->set_application_locale(
Michael Giuffrida693d01a2018-10-18 00:42:38850 actual_locale);
[email protected]e13ad79b2010-07-22 21:36:50851}
852
[email protected]073ed7b2010-09-27 09:20:02853DownloadStatusUpdater* BrowserProcessImpl::download_status_updater() {
[email protected]7a0e72f2011-09-20 19:59:11854 return download_status_updater_.get();
[email protected]073ed7b2010-09-27 09:20:02855}
856
[email protected]95951992013-09-13 00:37:54857MediaFileSystemRegistry* BrowserProcessImpl::media_file_system_registry() {
brettw00899e62016-11-12 02:10:17858#if BUILDFLAG(ENABLE_EXTENSIONS)
[email protected]42aec8df2012-12-12 06:03:57859 if (!media_file_system_registry_)
Jeremy Romanec48d7a2018-03-01 17:35:09860 media_file_system_registry_ = std::make_unique<MediaFileSystemRegistry>();
[email protected]42aec8df2012-12-12 06:03:57861 return media_file_system_registry_.get();
[email protected]84b7a552014-07-19 04:52:06862#else
863 return NULL;
[email protected]e8262a52013-04-24 02:02:51864#endif
[email protected]42aec8df2012-12-12 06:03:57865}
866
[email protected]bbf32c52013-06-03 14:05:52867WebRtcLogUploader* BrowserProcessImpl::webrtc_log_uploader() {
Lei Zhang7f3a88752017-08-25 20:17:32868 if (!webrtc_log_uploader_)
Jeremy Romanec48d7a2018-03-01 17:35:09869 webrtc_log_uploader_ = std::make_unique<WebRtcLogUploader>();
[email protected]bbf32c52013-06-03 14:05:52870 return webrtc_log_uploader_.get();
871}
[email protected]bbf32c52013-06-03 14:05:52872
[email protected]d0ab865b2014-06-04 19:41:34873network_time::NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() {
[email protected]ad9cfab2014-05-30 10:17:03874 if (!network_time_tracker_) {
Jeremy Romanec48d7a2018-03-01 17:35:09875 network_time_tracker_ = std::make_unique<network_time::NetworkTimeTracker>(
dcheng4af48582016-04-19 00:29:35876 base::WrapUnique(new base::DefaultClock()),
mab2f07cb92016-05-10 20:55:51877 base::WrapUnique(new base::DefaultTickClock()), local_state(),
John Abd-El-Malek0a52618c2018-06-19 18:06:04878 system_network_context_manager()->GetSharedURLLoaderFactory());
[email protected]ad9cfab2014-05-30 10:17:03879 }
[email protected]72f93712014-05-19 15:10:39880 return network_time_tracker_.get();
881}
882
Adam Langley1cb73c72020-08-28 17:06:44883#if !defined(OS_ANDROID)
[email protected]c027d6d2014-06-05 15:25:40884gcm::GCMDriver* BrowserProcessImpl::gcm_driver() {
gab25894fe2017-05-30 03:40:36885 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]c027d6d2014-06-05 15:25:40886 if (!gcm_driver_)
887 CreateGCMDriver();
888 return gcm_driver_.get();
889}
Adam Langley1cb73c72020-08-28 17:06:44890#endif
[email protected]c027d6d2014-06-05 15:25:40891
lpyfedf65a2017-06-01 01:41:24892resource_coordinator::TabManager* BrowserProcessImpl::GetTabManager() {
gab25894fe2017-05-30 03:40:36893 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Sebastien Marchand2ebd9252018-11-08 18:39:35894 return resource_coordinator_parts()->tab_manager();
895}
896
897resource_coordinator::ResourceCoordinatorParts*
898BrowserProcessImpl::resource_coordinator_parts() {
899 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
900 if (!resource_coordinator_parts_) {
901 resource_coordinator_parts_ =
902 std::make_unique<resource_coordinator::ResourceCoordinatorParts>();
Francois Doraya271a5c2018-04-03 18:37:11903 }
Sebastien Marchand2ebd9252018-11-08 18:39:35904 return resource_coordinator_parts_.get();
georgesak7b5281922015-06-30 13:25:17905}
906
Greg Thompson08451a42020-02-04 23:45:54907BuildState* BrowserProcessImpl::GetBuildState() {
908#if !defined(OS_ANDROID)
909 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
910 return &build_state_;
911#else
912 NOTIMPLEMENTED();
913 return nullptr;
914#endif
915}
916
[email protected]b1de2c72013-02-06 02:45:47917// static
918void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) {
919 registry->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
920 false);
[email protected]b1de2c72013-02-06 02:45:47921
[email protected]b1de2c72013-02-06 02:45:47922 registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false);
923
jam1c5a91492016-02-24 20:47:53924#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]b4b709a2013-04-19 21:08:14925 registry->RegisterBooleanPref(prefs::kEulaAccepted, false);
jam1c5a91492016-02-24 20:47:53926#endif // defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]b1de2c72013-02-06 02:45:47927
928 // TODO(brettw,*): this comment about ResourceBundle was here since
929 // initial commit. This comment seems unrelated, bit-rotten and
930 // a candidate for removal.
931 // Initialize ResourceBundle which handles files loaded from external
932 // sources. This has to be done before uninstall code path and before prefs
933 // are registered.
Ran Ji73f3b432018-07-15 22:10:27934 registry->RegisterStringPref(language::prefs::kApplicationLocale,
935 std::string());
[email protected]b1de2c72013-02-06 02:45:47936#if defined(OS_CHROMEOS)
937 registry->RegisterStringPref(prefs::kOwnerLocale, std::string());
938 registry->RegisterStringPref(prefs::kHardwareKeyboardLayout,
939 std::string());
940#endif // defined(OS_CHROMEOS)
jessicagab7a08b2016-03-11 22:34:49941
blundell6e85b7c2015-09-29 12:33:35942 registry->RegisterBooleanPref(metrics::prefs::kMetricsReportingEnabled,
943 GoogleUpdateSettings::GetCollectStatsConsent());
[email protected]b1de2c72013-02-06 02:45:47944}
945
[email protected]254ed742011-08-16 18:45:27946DownloadRequestLimiter* BrowserProcessImpl::download_request_limiter() {
gab25894fe2017-05-30 03:40:36947 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Lei Zhang7f3a88752017-08-25 20:17:32948 if (!download_request_limiter_.get()) {
949 download_request_limiter_ = base::MakeRefCounted<DownloadRequestLimiter>();
950 }
[email protected]dc24976f2013-06-02 21:15:09951 return download_request_limiter_.get();
[email protected]254ed742011-08-16 18:45:27952}
953
[email protected]9e7f015f2011-05-28 00:24:25954BackgroundModeManager* BrowserProcessImpl::background_mode_manager() {
gab25894fe2017-05-30 03:40:36955 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Denis Kuznetsov32099f32017-12-15 14:04:57956#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
Lei Zhang7f3a88752017-08-25 20:17:32957 if (!background_mode_manager_)
[email protected]9e7f015f2011-05-28 00:24:25958 CreateBackgroundModeManager();
959 return background_mode_manager_.get();
[email protected]7cee1902012-08-23 00:02:45960#else
961 NOTIMPLEMENTED();
962 return NULL;
963#endif
[email protected]9e7f015f2011-05-28 00:24:25964}
965
[email protected]e178ad92013-06-28 02:29:25966void BrowserProcessImpl::set_background_mode_manager_for_test(
dcheng4af48582016-04-19 00:29:35967 std::unique_ptr<BackgroundModeManager> manager) {
Denis Kuznetsov32099f32017-12-15 14:04:57968#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
dchenge73d8520c2015-12-27 01:19:09969 background_mode_manager_ = std::move(manager);
thestige4155842014-10-20 18:58:02970#endif
[email protected]e178ad92013-06-28 02:29:25971}
972
[email protected]9e7f015f2011-05-28 00:24:25973StatusTray* BrowserProcessImpl::status_tray() {
gab25894fe2017-05-30 03:40:36974 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Lei Zhang7f3a88752017-08-25 20:17:32975 if (!status_tray_)
[email protected]9e7f015f2011-05-28 00:24:25976 CreateStatusTray();
977 return status_tray_.get();
978}
979
vakh9a474d832015-11-13 01:43:09980safe_browsing::SafeBrowsingService*
981BrowserProcessImpl::safe_browsing_service() {
gab25894fe2017-05-30 03:40:36982 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
[email protected]462a0ff2011-06-02 17:15:34983 if (!created_safe_browsing_service_)
984 CreateSafeBrowsingService();
985 return safe_browsing_service_.get();
986}
987
Eric Robinsonefb3ea552018-11-02 18:24:32988subresource_filter::RulesetService*
engedyc5ef21ad2016-06-17 20:22:27989BrowserProcessImpl::subresource_filter_ruleset_service() {
gab25894fe2017-05-30 03:40:36990 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
engedyc5ef21ad2016-06-17 20:22:27991 if (!created_subresource_filter_ruleset_service_)
992 CreateSubresourceFilterRulesetService();
993 return subresource_filter_ruleset_service_.get();
994}
995
Yao Xiao431dec62020-06-25 14:13:06996federated_learning::FlocBlocklistService*
997BrowserProcessImpl::floc_blocklist_service() {
998 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
999 if (!floc_blocklist_service_)
1000 CreateFlocBlocklistService();
1001 return floc_blocklist_service_.get();
1002}
1003
Yao Xiaocc8e0c42020-10-01 17:34:461004federated_learning::FlocSortingLshClustersService*
1005BrowserProcessImpl::floc_sorting_lsh_clusters_service() {
1006 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
1007 if (!floc_sorting_lsh_clusters_service_)
1008 CreateFlocSortingLshClustersService();
1009 return floc_sorting_lsh_clusters_service_.get();
1010}
1011
Sophie Changf453c0522017-11-03 06:33:491012optimization_guide::OptimizationGuideService*
1013BrowserProcessImpl::optimization_guide_service() {
1014 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
1015 if (!created_optimization_guide_service_)
1016 CreateOptimizationGuideService();
1017 return optimization_guide_service_.get();
1018}
1019
Xi Han9fd44002019-04-30 17:39:361020StartupData* BrowserProcessImpl::startup_data() {
1021 return startup_data_;
1022}
1023
[email protected]e13ad79b2010-07-22 21:36:501024#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
1025void BrowserProcessImpl::StartAutoupdateTimer() {
[email protected]d323a172011-09-02 18:23:021026 autoupdate_timer_.Start(FROM_HERE,
[email protected]e13ad79b2010-07-22 21:36:501027 base::TimeDelta::FromHours(kUpdateCheckIntervalHours),
1028 this,
1029 &BrowserProcessImpl::OnAutoupdateTimer);
1030}
1031#endif
1032
[email protected]055981f2014-01-17 20:22:321033component_updater::ComponentUpdateService*
1034BrowserProcessImpl::component_updater() {
sorin7a43e832016-09-15 21:29:291035 if (component_updater_)
1036 return component_updater_.get();
1037
1038 if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
1039 return nullptr;
1040
Tibor Goldschwendt11b3cf22018-07-04 15:32:441041 std::unique_ptr<component_updater::UpdateScheduler> scheduler;
1042#if defined(OS_ANDROID)
1043 if (base::FeatureList::IsEnabled(
1044 chrome::android::kBackgroundTaskComponentUpdate) &&
1045 component_updater::BackgroundTaskUpdateScheduler::IsAvailable()) {
1046 scheduler =
1047 std::make_unique<component_updater::BackgroundTaskUpdateScheduler>();
1048 }
1049#endif
1050 if (!scheduler)
1051 scheduler = std::make_unique<component_updater::TimerUpdateScheduler>();
1052
sorin7a43e832016-09-15 21:29:291053 component_updater_ = component_updater::ComponentUpdateServiceFactory(
1054 component_updater::MakeChromeComponentUpdaterConfigurator(
1055 base::CommandLine::ForCurrentProcess(),
Tibor Goldschwendt5f173cb2018-06-21 22:50:401056 g_browser_process->local_state()),
Tibor Goldschwendt11b3cf22018-07-04 15:32:441057 std::move(scheduler));
sorin7a43e832016-09-15 21:29:291058
[email protected]c1adf5a2011-08-03 22:11:371059 return component_updater_.get();
[email protected]aafbcb572011-08-03 22:22:321060}
[email protected]c1adf5a2011-08-03 22:11:371061
Toby H5cfaf942019-07-25 22:54:501062#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
bauerb22951c32015-02-12 13:18:171063component_updater::SupervisedUserWhitelistInstaller*
1064BrowserProcessImpl::supervised_user_whitelist_installer() {
1065 if (!supervised_user_whitelist_installer_) {
1066 supervised_user_whitelist_installer_ =
1067 component_updater::SupervisedUserWhitelistInstaller::Create(
lwchkg9c183942016-03-13 06:29:541068 component_updater(),
1069 &profile_manager()->GetProfileAttributesStorage(),
bauerb22951c32015-02-12 13:18:171070 local_state());
1071 }
1072 return supervised_user_whitelist_installer_.get();
1073}
Toby H5cfaf942019-07-25 22:54:501074#endif // BUILDFLAG(ENABLE_SUPERVISED_USERS)
bauerb22951c32015-02-12 13:18:171075
dgnfe075c82016-03-18 11:25:351076void BrowserProcessImpl::OnKeepAliveStateChanged(bool is_keeping_alive) {
1077 if (is_keeping_alive)
1078 Pin();
1079 else
1080 Unpin();
1081}
1082
Tarun Bansal86b39222018-09-21 02:07:321083void BrowserProcessImpl::CreateNetworkQualityObserver() {
1084 DCHECK(!network_quality_observer_);
1085 network_quality_observer_ =
1086 content::CreateNetworkQualityObserver(network_quality_tracker());
1087 DCHECK(network_quality_observer_);
1088}
1089
sorindd63a932016-08-15 03:22:471090void BrowserProcessImpl::OnKeepAliveRestartStateChanged(bool can_restart) {}
dgnfe075c82016-03-18 11:25:351091
[email protected]0b565182011-03-02 18:11:151092void BrowserProcessImpl::CreateWatchdogThread() {
melandory1346cde2016-06-11 00:42:121093 DCHECK(!created_watchdog_thread_ && !watchdog_thread_);
[email protected]0b565182011-03-02 18:11:151094 created_watchdog_thread_ = true;
1095
Jeremy Romanec48d7a2018-03-01 17:35:091096 auto thread = std::make_unique<WatchDogThread>();
[email protected]1c8fcb52014-06-26 22:36:321097 base::Thread::Options options;
1098 options.timer_slack = base::TIMER_SLACK_MAXIMUM;
1099 if (!thread->StartWithOptions(options))
[email protected]0b565182011-03-02 18:11:151100 return;
1101 watchdog_thread_.swap(thread);
1102}
1103
initial.commit09911bf2008-07-26 23:55:291104void BrowserProcessImpl::CreateProfileManager() {
melandory1346cde2016-06-11 00:42:121105 DCHECK(!created_profile_manager_ && !profile_manager_);
initial.commit09911bf2008-07-26 23:55:291106 created_profile_manager_ = true;
1107
[email protected]650b2d52013-02-10 03:41:451108 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:521109 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
Jeremy Romanec48d7a2018-03-01 17:35:091110 profile_manager_ = std::make_unique<ProfileManager>(user_data_dir);
initial.commit09911bf2008-07-26 23:55:291111}
1112
Bernhard Bauer5533f9912017-11-06 17:56:021113void BrowserProcessImpl::PreCreateThreads(
1114 const base::CommandLine& command_line) {
brettw00899e62016-11-12 02:10:171115#if BUILDFLAG(ENABLE_EXTENSIONS)
naskoabed2a52017-05-03 05:10:171116 // chrome-extension:// URLs are safe to request anywhere, but may only
1117 // commit (including in iframes) in extension processes.
1118 ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeIsolatedScheme(
1119 extensions::kExtensionScheme, true);
nicka0b7b872016-10-21 18:39:161120#endif
1121
Ken Rockotacbf3d8c2019-06-13 23:10:271122 battery_metrics_ = std::make_unique<BatteryMetrics>();
1123
Lukasz Anforowicz60d1253d2019-05-08 16:31:371124 secure_origin_prefs_observer_ =
1125 std::make_unique<SecureOriginPrefsObserver>(local_state());
Lukasz Anforowicz65c61162019-03-27 20:33:581126 site_isolation_prefs_observer_ =
1127 std::make_unique<SiteIsolationPrefsObserver>(local_state());
Henrique Nakashimafaf51102019-07-16 16:48:351128
1129 // Create SystemNetworkContextManager without a NetworkService if it has not
1130 // been requested yet.
1131 if (!SystemNetworkContextManager::HasInstance())
1132 SystemNetworkContextManager::CreateInstance(local_state());
[email protected]99907362012-01-11 05:41:401133}
1134
[email protected]d2caaa22011-12-12 03:04:151135void BrowserProcessImpl::PreMainMessageLoopRun() {
rkaplow1b23b7d2015-02-13 20:52:491136 TRACE_EVENT0("startup", "BrowserProcessImpl::PreMainMessageLoopRun");
1137 SCOPED_UMA_HISTOGRAM_TIMER(
1138 "Startup.BrowserProcessImpl_PreMainMessageLoopRunTime");
1139
[email protected]362d694f2013-02-28 09:07:241140 // browser_policy_connector() is created very early because local_state()
1141 // needs policy to be initialized with the managed preference values.
1142 // However, policy fetches from the network and loading of disk caches
1143 // requires that threads are running; this Init() call lets the connector
1144 // resume its initialization now that the loops are spinning and the
1145 // system request context is available for the fetchers.
Jay Civelli6ab180d2018-06-21 23:02:581146 browser_policy_connector()->Init(
Reilly Grant47285da2018-08-02 01:23:241147 local_state(),
Jay Civelli6ab180d2018-06-21 23:02:581148 system_network_context_manager()->GetSharedURLLoaderFactory());
[email protected]362d694f2013-02-28 09:07:241149
[email protected]0ca957872013-01-03 20:24:041150 if (local_state_->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled))
1151 ApplyDefaultBrowserPolicy();
1152
jam1c5a91492016-02-24 20:47:531153#if !defined(OS_ANDROID)
[email protected]fc0cd312014-01-13 14:25:541154 ApplyMetricsReportingPolicy();
1155#endif
1156
brettw4b461082016-11-19 18:55:161157#if BUILDFLAG(ENABLE_PLUGINS)
Lei Zhang3c258f92019-12-11 20:47:551158 auto* plugin_service = content::PluginService::GetInstance();
[email protected]99907362012-01-11 05:41:401159 plugin_service->SetFilter(ChromePluginServiceFilter::GetInstance());
[email protected]99907362012-01-11 05:41:401160
[email protected]de75c702012-09-25 23:06:021161 // Triggers initialization of the singleton instance on UI thread.
1162 PluginFinder::GetInstance()->Init();
[email protected]2366a3a2012-10-02 20:41:141163
bauerbecab4f52017-03-13 20:16:411164 DCHECK(!plugins_resource_service_);
1165 plugins_resource_service_ =
Jeremy Romanec48d7a2018-03-01 17:35:091166 std::make_unique<PluginsResourceService>(local_state());
[email protected]97eddfe2013-02-12 19:16:301167 plugins_resource_service_->Init();
brettw4b461082016-11-19 18:55:161168#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]ed304482013-01-04 04:45:321169
jam1c5a91492016-02-24 20:47:531170#if !defined(OS_ANDROID)
Ken Rockot8af6e392019-12-12 22:32:241171 storage_monitor::StorageMonitor::Create();
[email protected]8b60ca722013-07-19 01:29:021172#endif
1173
[email protected]90a4b9d2013-07-31 12:14:401174 platform_part_->PreMainMessageLoopRun();
estark4f480f4f2016-09-29 16:40:511175
1176 if (base::FeatureList::IsEnabled(network_time::kNetworkTimeServiceQuerying)) {
Jeremy Romanec48d7a2018-03-01 17:35:091177 network_time_tracker_ = std::make_unique<network_time::NetworkTimeTracker>(
estark4f480f4f2016-09-29 16:40:511178 base::WrapUnique(new base::DefaultClock()),
1179 base::WrapUnique(new base::DefaultTickClock()), local_state(),
John Abd-El-Malek0a52618c2018-06-19 18:06:041180 system_network_context_manager()->GetSharedURLLoaderFactory());
estark4f480f4f2016-09-29 16:40:511181 }
Tarun Bansal86b39222018-09-21 02:07:321182
1183 CreateNetworkQualityObserver();
Mugdha Lakhania372586d2020-04-08 21:02:061184
1185#if defined(OS_ANDROID)
Mugdha Lakhanid372b322020-04-09 15:09:161186 // This needs to be here so that SecurityStateClient is non-null when
1187 // SecurityStateModel code is called.
Mugdha Lakhania372586d2020-04-08 21:02:061188 security_state::SetSecurityStateClient(new ChromeSecurityStateClient());
1189#endif
[email protected]d2caaa22011-12-12 03:04:151190}
1191
initial.commit09911bf2008-07-26 23:55:291192void BrowserProcessImpl::CreateIconManager() {
melandory1346cde2016-06-11 00:42:121193 DCHECK(!created_icon_manager_ && !icon_manager_);
initial.commit09911bf2008-07-26 23:55:291194 created_icon_manager_ = true;
Jeremy Romanec48d7a2018-03-01 17:35:091195 icon_manager_ = std::make_unique<IconManager>();
initial.commit09911bf2008-07-26 23:55:291196}
1197
[email protected]c4ff4952010-01-08 19:12:471198void BrowserProcessImpl::CreateIntranetRedirectDetector() {
melandory1346cde2016-06-11 00:42:121199 DCHECK(!intranet_redirect_detector_);
Jeremy Romanec48d7a2018-03-01 17:35:091200 intranet_redirect_detector_ = std::make_unique<IntranetRedirectDetector>();
[email protected]c4ff4952010-01-08 19:12:471201}
1202
miguelg23cd2dd72016-04-21 15:24:031203void BrowserProcessImpl::CreateNotificationPlatformBridge() {
thomasanderson421f86bb2017-04-05 06:32:421204#if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
melandory1346cde2016-06-11 00:42:121205 DCHECK(!notification_bridge_);
Ayu Ishii2a8d0d3b2019-01-08 01:45:581206 notification_bridge_ = NotificationPlatformBridge::Create();
miguelg23cd2dd72016-04-21 15:24:031207 created_notification_bridge_ = true;
1208#endif
1209}
1210
[email protected]29672ab2009-10-30 03:44:031211void BrowserProcessImpl::CreateNotificationUIManager() {
Evan Stade4d8df162018-06-07 16:59:251212// Android and Chrome OS do not use the NotificationUIManager anymore.
miguelg23cd2dd72016-04-21 15:24:031213// All notification traffic is routed through NotificationPlatformBridge.
Evan Stade4d8df162018-06-07 16:59:251214#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
melandory1346cde2016-06-11 00:42:121215 DCHECK(!notification_ui_manager_);
Ayu Ishii2a8d0d3b2019-01-08 01:45:581216 notification_ui_manager_ = NotificationUIManager::Create();
Evan Stade3044d4f2018-02-09 23:54:061217 created_notification_ui_manager_ = !!notification_ui_manager_;
[email protected]29cebbd2012-06-06 21:43:421218#endif
[email protected]29672ab2009-10-30 03:44:031219}
1220
[email protected]9e7f015f2011-05-28 00:24:251221void BrowserProcessImpl::CreateBackgroundModeManager() {
Denis Kuznetsov32099f32017-12-15 14:04:571222#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
melandory1346cde2016-06-11 00:42:121223 DCHECK(!background_mode_manager_);
Jeremy Romanec48d7a2018-03-01 17:35:091224 background_mode_manager_ = std::make_unique<BackgroundModeManager>(
Lei Zhang7f3a88752017-08-25 20:17:321225 *base::CommandLine::ForCurrentProcess(),
1226 &profile_manager()->GetProfileAttributesStorage());
thestige4155842014-10-20 18:58:021227#endif
[email protected]9e7f015f2011-05-28 00:24:251228}
1229
1230void BrowserProcessImpl::CreateStatusTray() {
melandory1346cde2016-06-11 00:42:121231 DCHECK(!status_tray_);
Ayu Ishii2a8d0d3b2019-01-08 01:45:581232 status_tray_ = StatusTray::Create();
[email protected]9e7f015f2011-05-28 00:24:251233}
1234
[email protected]d8ce31e2012-12-19 05:09:211235void BrowserProcessImpl::CreatePrintPreviewDialogController() {
Brett Wilson65f951c2016-11-03 22:06:121236#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
melandory1346cde2016-06-11 00:42:121237 DCHECK(!print_preview_dialog_controller_);
[email protected]d8ce31e2012-12-19 05:09:211238 print_preview_dialog_controller_ =
Lei Zhang7f3a88752017-08-25 20:17:321239 base::MakeRefCounted<printing::PrintPreviewDialogController>();
[email protected]658677f2012-06-09 06:04:021240#else
1241 NOTIMPLEMENTED();
[email protected]058e5732012-03-01 22:48:031242#endif
[email protected]dbeebd52010-11-16 20:34:161243}
1244
[email protected]68f88b992011-05-07 02:01:391245void BrowserProcessImpl::CreateBackgroundPrintingManager() {
Brett Wilson65f951c2016-11-03 22:06:121246#if BUILDFLAG(ENABLE_PRINT_PREVIEW)
melandory1346cde2016-06-11 00:42:121247 DCHECK(!background_printing_manager_);
Lei Zhang7f3a88752017-08-25 20:17:321248 background_printing_manager_ =
Jeremy Romanec48d7a2018-03-01 17:35:091249 std::make_unique<printing::BackgroundPrintingManager>();
[email protected]658677f2012-06-09 06:04:021250#else
1251 NOTIMPLEMENTED();
1252#endif
[email protected]68f88b992011-05-07 02:01:391253}
1254
[email protected]462a0ff2011-06-02 17:15:341255void BrowserProcessImpl::CreateSafeBrowsingService() {
melandory1346cde2016-06-11 00:42:121256 DCHECK(!safe_browsing_service_);
[email protected]8c40da62011-07-13 22:58:461257 // Set this flag to true so that we don't retry indefinitely to
1258 // create the service class if there was an error.
[email protected]462a0ff2011-06-02 17:15:341259 created_safe_browsing_service_ = true;
Daniel Ruberyf5f4a1c2019-05-09 19:51:101260
1261 // The factory can be overridden in tests.
1262 if (!safe_browsing::SafeBrowsingServiceInterface::HasFactory()) {
1263 safe_browsing::SafeBrowsingServiceInterface::RegisterFactory(
1264 safe_browsing::GetSafeBrowsingServiceFactory());
1265 }
1266
1267 // TODO(crbug/925153): Port consumers of the |safe_browsing_service_| to use
1268 // the interface in components/safe_browsing, and remove this cast.
1269 safe_browsing_service_ = static_cast<safe_browsing::SafeBrowsingService*>(
1270 safe_browsing::SafeBrowsingServiceInterface::CreateSafeBrowsingService());
1271 if (safe_browsing_service_)
1272 safe_browsing_service_->Initialize();
[email protected]462a0ff2011-06-02 17:15:341273}
1274
engedyc5ef21ad2016-06-17 20:22:271275void BrowserProcessImpl::CreateSubresourceFilterRulesetService() {
1276 DCHECK(!subresource_filter_ruleset_service_);
1277 created_subresource_filter_ruleset_service_ = true;
1278
engedyc5ef21ad2016-06-17 20:22:271279 base::FilePath user_data_dir;
Avi Drissman9098f9002018-05-04 00:11:521280 base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
csharrison8a923d62017-03-10 15:42:131281 subresource_filter_ruleset_service_ =
Colin Blundellc7db0302020-09-29 20:48:351282 subresource_filter::RulesetService::Create(local_state(), user_data_dir);
engedyc5ef21ad2016-06-17 20:22:271283}
1284
Yao Xiao431dec62020-06-25 14:13:061285void BrowserProcessImpl::CreateFlocBlocklistService() {
1286 DCHECK(!floc_blocklist_service_);
1287 floc_blocklist_service_ =
1288 std::make_unique<federated_learning::FlocBlocklistService>();
1289}
1290
Yao Xiaocc8e0c42020-10-01 17:34:461291void BrowserProcessImpl::CreateFlocSortingLshClustersService() {
1292 DCHECK(!floc_sorting_lsh_clusters_service_);
1293 floc_sorting_lsh_clusters_service_ =
1294 std::make_unique<federated_learning::FlocSortingLshClustersService>();
1295}
1296
Sophie Changf453c0522017-11-03 06:33:491297void BrowserProcessImpl::CreateOptimizationGuideService() {
1298 DCHECK(!created_optimization_guide_service_);
1299 DCHECK(!optimization_guide_service_);
1300 created_optimization_guide_service_ = true;
1301
Sophie Chang7b02ca692019-07-09 17:57:591302 if (!optimization_guide::features::IsOptimizationHintsEnabled())
Sophie Changf453c0522017-11-03 06:33:491303 return;
1304
1305 optimization_guide_service_ =
Jeremy Romanec48d7a2018-03-01 17:35:091306 std::make_unique<optimization_guide::OptimizationGuideService>(
Gabriel Charetteb2bbd482020-05-27 01:24:211307 content::GetUIThreadTaskRunner({}));
Sophie Changf453c0522017-11-03 06:33:491308}
1309
Adam Langley1cb73c72020-08-28 17:06:441310#if !defined(OS_ANDROID)
1311// Android's GCMDriver currently makes the assumption that it's a singleton.
1312// Until this gets fixed, instantiating multiple Java GCMDrivers will throw an
1313// exception, but because they're only initialized on demand these crashes
1314// would be very difficult to triage. See http://crbug.com/437827.
[email protected]c027d6d2014-06-05 15:25:401315void BrowserProcessImpl::CreateGCMDriver() {
1316 DCHECK(!gcm_driver_);
1317
[email protected]c027d6d2014-06-05 15:25:401318 base::FilePath store_path;
Avi Drissman9098f9002018-05-04 00:11:521319 CHECK(base::PathService::Get(chrome::DIR_GLOBAL_GCM_STORE, &store_path));
jitendra.ksb1b7fee2015-09-22 17:42:531320 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
Gabriel Charette055039132020-02-26 23:02:061321 base::ThreadPool::CreateSequencedTaskRunner(
1322 {base::MayBlock(), base::TaskPriority::BEST_EFFORT,
fdorayff7a2feb2017-05-16 13:28:181323 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
jitendra.ksb1b7fee2015-09-22 17:42:531324
[email protected]c027d6d2014-06-05 15:25:401325 gcm_driver_ = gcm::CreateGCMDriverDesktop(
dcheng4af48582016-04-19 00:29:351326 base::WrapUnique(new gcm::GCMClientFactory), local_state(), store_path,
Mihai Sardarescud260bd262019-12-10 16:40:251327 /*remove_account_mappings_with_email_key=*/false,
Helen Li5f3d96a2018-08-10 20:37:241328 base::BindRepeating(&RequestProxyResolvingSocketFactory),
Mark Pilgrim7634f5b52018-06-27 19:53:271329 system_network_context_manager()->GetSharedURLLoaderFactory(),
Robbie McElrathb01499332018-09-25 00:53:131330 content::GetNetworkConnectionTracker(), chrome::GetChannel(),
1331 gcm::GetProductCategoryForSubtypes(local_state()),
Gabriel Charetteb2bbd482020-05-27 01:24:211332 content::GetUIThreadTaskRunner({}), content::GetIOThreadTaskRunner({}),
jitendra.ksb1b7fee2015-09-22 17:42:531333 blocking_task_runner);
[email protected]c027d6d2014-06-05 15:25:401334}
Adam Langley1cb73c72020-08-28 17:06:441335#endif // defined(OS_ANDROID)
[email protected]c027d6d2014-06-05 15:25:401336
[email protected]b61f62a2011-11-01 02:02:101337void BrowserProcessImpl::ApplyDefaultBrowserPolicy() {
[email protected]ed304482013-01-04 04:45:321338 if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) {
pmonette8db6a8be2016-02-11 01:50:311339 // The worker pointer is reference counted. While it is running, the
1340 // message loops of the FILE and UI thread will hold references to it
1341 // and it will be automatically freed once all its tasks have finished.
Lei Zhang7f3a88752017-08-25 20:17:321342 auto set_browser_worker =
Will Cassellac79ca562020-07-25 04:03:091343 base::MakeRefCounted<shell_integration::DefaultBrowserWorker>();
pmonette8db6a8be2016-02-11 01:50:311344 // The user interaction must always be disabled when applying the default
1345 // browser policy since it is done at each browser startup and the result
1346 // of the interaction cannot be forced.
1347 set_browser_worker->set_interactive_permitted(false);
Will Cassellac79ca562020-07-25 04:03:091348 set_browser_worker->StartSetAsDefault(base::NullCallback());
[email protected]b61f62a2011-11-01 02:02:101349 }
1350}
1351
dgnfe075c82016-03-18 11:25:351352void BrowserProcessImpl::Pin() {
gab25894fe2017-05-30 03:40:361353 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Nico Webere66ab192020-04-23 23:08:271354 CHECK(!IsShuttingDown());
dgnfe075c82016-03-18 11:25:351355}
1356
1357void BrowserProcessImpl::Unpin() {
gab25894fe2017-05-30 03:40:361358 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Greg Thompson822ab51a2018-09-18 06:45:291359
1360#if !defined(OS_ANDROID)
1361 // The quit closure is set by ChromeBrowserMainParts to transfer ownership of
1362 // the browser's lifetime to the BrowserProcess. Any KeepAlives registered and
1363 // unregistered prior to setting the quit closure are ignored. Only once the
1364 // quit closure is set should unpinning start process shutdown.
1365 if (!quit_closure_)
1366 return;
1367#endif
dgnfe075c82016-03-18 11:25:351368
Wez25fd35f2018-05-25 22:57:411369 DCHECK(!shutting_down_);
dgnfe075c82016-03-18 11:25:351370 shutting_down_ = true;
Vladislav Kaznacheeveb65ea12019-05-14 00:30:051371
1372#if !defined(OS_ANDROID)
1373 KeepAliveRegistry::GetInstance()->SetIsShuttingDown();
1374#endif // !defined(OS_ANDROID)
1375
Brett Wilson65f951c2016-11-03 22:06:121376#if BUILDFLAG(ENABLE_PRINTING)
dgnfe075c82016-03-18 11:25:351377 // Wait for the pending print jobs to finish. Don't do this later, since
gab2998ee72017-05-05 16:23:501378 // this might cause a nested run loop to run, and we don't want pending
dgnfe075c82016-03-18 11:25:351379 // tasks to run once teardown has started.
1380 print_job_manager_->Shutdown();
1381#endif
1382
1383#if defined(LEAK_SANITIZER)
1384 // Check for memory leaks now, before we start shutting down threads. Doing
1385 // this early means we won't report any shutdown-only leaks (as they have
1386 // not yet happened at this point).
1387 // If leaks are found, this will make the process exit immediately.
1388 __lsan_do_leak_check();
1389#endif
1390
gab7af9dc02017-05-05 13:38:541391 CHECK(base::RunLoop::IsRunningOnCurrentThread());
dgnfe075c82016-03-18 11:25:351392
Avi Drissman2e458df2020-07-29 16:24:311393#if defined(OS_MAC)
fdoray283082bd2016-06-02 20:18:461394 base::ThreadTaskRunnerHandle::Get()->PostTask(
kylechar893ad5772019-02-15 18:31:591395 FROM_HERE,
1396 base::BindOnce(ChromeBrowserMainPartsMac::DidEndMainMessageLoop));
dgnfe075c82016-03-18 11:25:351397#endif
dgnfe075c82016-03-18 11:25:351398
1399#if !defined(OS_ANDROID)
Wez25fd35f2018-05-25 22:57:411400 std::move(quit_closure_).Run();
1401
dgnfe075c82016-03-18 11:25:351402 chrome::ShutdownIfNeeded();
Collin Baker62965522020-02-06 01:35:571403
1404 // TODO(crbug.com/967603): remove when root cause is found.
1405 CHECK_EQ(BrowserList::GetInstance()->size(), 0u);
dgnfe075c82016-03-18 11:25:351406#endif // !defined(OS_ANDROID)
1407}
1408
[email protected]3cdacd42010-04-30 18:55:531409// Mac is currently not supported.
1410#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
[email protected]bd48c2b02010-04-09 20:32:421411
Greg Thompsonf9ce2502017-11-14 00:13:351412bool BrowserProcessImpl::IsRunningInBackground() const {
1413 // Check if browser is in the background.
dgn02377782016-03-12 00:58:381414 return chrome::GetTotalBrowserCount() == 0 &&
Greg Thompsonf9ce2502017-11-14 00:13:351415 KeepAliveRegistry::GetInstance()->IsKeepingAlive();
[email protected]bd48c2b02010-04-09 20:32:421416}
1417
[email protected]f6e6d2e2011-10-28 18:39:221418void BrowserProcessImpl::RestartBackgroundInstance() {
avi3ef9ec9e2014-12-22 22:50:171419 base::CommandLine* old_cl = base::CommandLine::ForCurrentProcess();
Lei Zhang3db6d1d2017-11-16 20:06:441420 auto new_cl = std::make_unique<base::CommandLine>(old_cl->GetProgram());
[email protected]bd48c2b02010-04-09 20:32:421421
Jeremy Roman863386d2017-10-31 19:25:381422 base::CommandLine::SwitchMap switches = old_cl->GetSwitches();
[email protected]5c08f222010-09-22 09:37:211423 switches::RemoveSwitchesForAutostart(&switches);
[email protected]bd48c2b02010-04-09 20:32:421424
1425 // Append the rest of the switches (along with their values, if any)
1426 // to the new command line
Lei Zhang7f3a88752017-08-25 20:17:321427 for (const auto& it : switches) {
Lei Zhang3db6d1d2017-11-16 20:06:441428 const auto& switch_name = it.first;
1429 const auto& switch_value = it.second;
1430 if (switch_value.empty())
1431 new_cl->AppendSwitch(switch_name);
Lei Zhang7f3a88752017-08-25 20:17:321432 else
Lei Zhang3db6d1d2017-11-16 20:06:441433 new_cl->AppendSwitchNative(switch_name, switch_value);
[email protected]bd48c2b02010-04-09 20:32:421434 }
1435
Lei Zhang3db6d1d2017-11-16 20:06:441436 // Switches to add when auto-restarting Chrome.
1437 static constexpr const char* kSwitchesToAddOnAutorestart[] = {
1438 switches::kNoStartupWindow};
1439
[email protected]6c10c972010-08-11 04:15:471440 // Ensure that our desired switches are set on the new process.
Lei Zhang3db6d1d2017-11-16 20:06:441441 for (const char* switch_to_add : kSwitchesToAddOnAutorestart) {
1442 if (!new_cl->HasSwitch(switch_to_add))
1443 new_cl->AppendSwitch(switch_to_add);
[email protected]6c10c972010-08-11 04:15:471444 }
[email protected]bd48c2b02010-04-09 20:32:421445
fdoray343068c42016-02-03 15:45:581446#if defined(OS_WIN)
fdoray9a9f0c42016-06-17 21:46:311447 new_cl->AppendArg(switches::kPrefetchArgumentBrowserBackground);
fdoray343068c42016-02-03 15:45:581448#endif // defined(OS_WIN)
1449
[email protected]3cdacd42010-04-30 18:55:531450 DLOG(WARNING) << "Shutting down current instance of the browser.";
[email protected]0c98ab652013-02-18 00:39:371451 chrome::AttemptExit();
[email protected]3cdacd42010-04-30 18:55:531452
Greg Thompson87ee38f2019-08-09 06:00:231453 upgrade_util::SetNewCommandLine(std::move(new_cl));
[email protected]bd48c2b02010-04-09 20:32:421454}
1455
1456void BrowserProcessImpl::OnAutoupdateTimer() {
Greg Thompsonf9ce2502017-11-14 00:13:351457 if (IsRunningInBackground()) {
1458 // upgrade_util::IsUpdatePendingRestart touches the disk, so do it on a
1459 // suitable thread.
Gabriel Charette055039132020-02-26 23:02:061460 base::ThreadPool::PostTaskAndReplyWithResult(
Greg Thompsonf9ce2502017-11-14 00:13:351461 FROM_HERE,
Gabriel Charette055039132020-02-26 23:02:061462 {base::TaskPriority::BEST_EFFORT,
Greg Thompsonf9ce2502017-11-14 00:13:351463 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN, base::MayBlock()},
1464 base::BindOnce(&upgrade_util::IsUpdatePendingRestart),
1465 base::BindOnce(&BrowserProcessImpl::OnPendingRestartResult,
1466 base::Unretained(this)));
1467 }
1468}
1469
1470void BrowserProcessImpl::OnPendingRestartResult(
1471 bool is_update_pending_restart) {
1472 // Make sure that the browser is still in the background after returning from
1473 // the check.
1474 if (is_update_pending_restart && IsRunningInBackground()) {
[email protected]3cdacd42010-04-30 18:55:531475 DLOG(WARNING) << "Detected update. Restarting browser.";
[email protected]f6e6d2e2011-10-28 18:39:221476 RestartBackgroundInstance();
[email protected]bd48c2b02010-04-09 20:32:421477 }
1478}
1479
[email protected]3cdacd42010-04-30 18:55:531480#endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)