blob: 61101b6cecf5a7f5aba49c331ae935222d50148e [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
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// When each service is created, we set a flag indicating this. At this point,
6// the service initialization could fail or succeed. This allows us to remember
7// if we tried to create a service, and not try creating it over and over if
8// the creation failed.
9
[email protected]58dca552009-06-17 00:35:0210#ifndef CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
11#define CHROME_BROWSER_BROWSER_PROCESS_IMPL_H_
initial.commit09911bf2008-07-26 23:55:2912
avie4d7b6f2015-12-26 00:59:1813#include <stdint.h>
14
dcheng4af48582016-04-19 00:29:3515#include <memory>
initial.commit09911bf2008-07-26 23:55:2916#include <string>
17
Keishi Hattori0e45c022021-11-27 09:25:5218#include "base/memory/raw_ptr.h"
[email protected]80745e32012-05-08 01:22:1219#include "base/memory/ref_counted.h"
gab25894fe2017-05-30 03:40:3620#include "base/sequence_checker.h"
[email protected]4dcb7972013-06-28 15:15:4121#include "base/timer/timer.h"
avie4d7b6f2015-12-26 00:59:1822#include "build/build_config.h"
Yuta Hijikata235fc62b2020-12-08 03:48:3223#include "build/chromeos_buildflags.h"
initial.commit09911bf2008-07-26 23:55:2924#include "chrome/browser/browser_process.h"
Scott Violet6200d332018-02-23 21:29:2325#include "chrome/common/buildflags.h"
Michael Giuffrida2dbce0d12017-09-02 03:30:5926#include "components/keep_alive_registry/keep_alive_state_observer.h"
Xi Han07bad2892018-10-04 15:13:5827#include "components/metrics_services_manager/metrics_services_manager.h"
Scott Violet9ae82892018-03-01 18:38:1228#include "components/nacl/common/buildflags.h"
Xi Handdb1ab12018-08-27 22:18:5429#include "components/prefs/persistent_pref_store.h"
brettwb1fc1b82016-02-02 00:19:0830#include "components/prefs/pref_change_registrar.h"
Scott Violetc8240b02018-03-08 22:03:5931#include "extensions/buildflags/buildflags.h"
Scott Violeta35f9a42018-03-22 22:00:4432#include "media/media_buildflags.h"
Scott Violet02e38b92018-03-27 23:42:1433#include "ppapi/buildflags/buildflags.h"
Scott Violet318a55f2018-03-30 19:08:1934#include "printing/buildflags/buildflags.h"
Tarun Bansal86b39222018-09-21 02:07:3235#include "services/network/public/cpp/network_quality_tracker.h"
Takuto Ikutaaa3b796c2019-02-06 02:54:5636#include "services/network/public/mojom/network_service.mojom-forward.h"
Abigail Klein7a63c572024-02-28 20:45:0937#include "services/screen_ai/buildflags/buildflags.h"
[email protected]b112a4c2009-02-01 20:24:0138
Xiaohan Wang55ae2c012022-01-20 21:49:1139#if !BUILDFLAG(IS_ANDROID)
Greg Thompson08451a42020-02-04 23:45:5440#include "chrome/browser/upgrade_detector/build_state.h"
41#endif
42
Xiaohan Wang55ae2c012022-01-20 21:49:1143#if BUILDFLAG(IS_ANDROID)
Oksana Zhuravlova3a4e4212021-02-17 21:51:3344#include "base/android/application_status_listener.h"
Amanda Lin Dietz8864d302023-06-26 18:36:3945#include "chrome/browser/accessibility/accessibility_prefs/android/accessibility_prefs_controller.h"
Xiaohan Wang55ae2c012022-01-20 21:49:1146#endif // BUILDFLAG(IS_ANDROID)
Oksana Zhuravlova3a4e4212021-02-17 21:51:3347
Ryan Sturmf0ad4292019-05-10 00:51:1048class BatteryMetrics;
Scott Violet875789e2018-02-02 07:46:4849class ChromeMetricsServicesManagerClient;
dgozman54cc54e2016-02-23 03:47:3050class DevToolsAutoOpener;
[email protected]4475d232011-07-27 15:29:2051class RemoteDebuggingServer;
[email protected]b1de2c72013-02-06 02:45:4752class PrefRegistrySimple;
Nicolas Dossou-Gbete5522bb02023-11-24 00:31:3553class SearchEngineChoiceProfileTagger;
Lukasz Anforowicz60d1253d2019-05-08 16:31:3754class SecureOriginPrefsObserver;
Lukasz Anforowicz65c61162019-03-27 20:33:5855class SiteIsolationPrefsObserver;
Toni Barzicb598380e2018-11-26 19:14:1056class SystemNotificationHelper;
Xi Han85079c22019-04-18 21:43:0557class StartupData;
initial.commit09911bf2008-07-26 23:55:2958
Jesse McKenna98e60df2021-08-17 16:57:0859namespace breadcrumbs {
60class ApplicationBreadcrumbsLogger;
Jesse McKenna98e60df2021-08-17 16:57:0861} // namespace breadcrumbs
62
James Scottf4b57662023-05-17 20:52:2863namespace embedder_support {
64class OriginTrialsSettingsStorage;
65} // namespace embedder_support
66
[email protected]aa3dd492013-11-05 17:09:0967namespace extensions {
Alex Cooper29c20fc2022-12-22 18:17:0568class ChromeExtensionsBrowserClient;
[email protected]aa3dd492013-11-05 17:09:0969}
70
[email protected]c027d6d2014-06-05 15:25:4071namespace gcm {
72class GCMDriver;
73}
74
Will Harris9b89cb02023-10-18 21:56:0975namespace os_crypt_async {
76class OSCryptAsync;
77}
78
[email protected]5b869962011-09-20 19:49:3379namespace policy {
Scott Violetfdd6f352018-01-12 19:12:2980class ChromeBrowserPolicyConnector;
[email protected]a4179c2a2012-02-09 18:14:2181class PolicyService;
Scott Violetfdd6f352018-01-12 19:12:2982} // namespace policy
[email protected]fcf53572011-06-29 15:44:3783
Elad Alon39b1f6cc2018-08-30 09:52:2184namespace webrtc_event_logging {
85class WebRtcEventLogManager;
86} // namespace webrtc_event_logging
87
Akihiro Otacee2d142021-06-08 00:52:0588namespace speech {
Rob Schonberger6d23a432024-03-25 23:25:4989class SodaInstaller;
Akihiro Otacee2d142021-06-08 00:52:0590} // namespace speech
91
Ramin Halavatiec90e022023-05-23 13:55:0592namespace screen_ai {
Ramin Halavatief04cb22023-08-25 08:29:3093class ScreenAIInstallState;
Ramin Halavatiec90e022023-05-23 13:55:0594} // namespace screen_ai
95
initial.commit09911bf2008-07-26 23:55:2996// Real implementation of BrowserProcess that creates and returns the services.
[email protected]6618d1d2010-12-15 21:18:4797class BrowserProcessImpl : public BrowserProcess,
dgnfe075c82016-03-18 11:25:3598 public KeepAliveStateObserver {
initial.commit09911bf2008-07-26 23:55:2999 public:
Xi Han85079c22019-04-18 21:43:05100 // |startup_data| should not be null. The BrowserProcessImpl
Xi Han07bad2892018-10-04 15:13:58101 // will take the PrefService owned by the creator as the Local State instead
102 // of loading the JSON file from disk.
Xi Han85079c22019-04-18 21:43:05103 explicit BrowserProcessImpl(StartupData* startup_data);
Peter Boström53c6c5952021-09-17 09:41:26104
105 BrowserProcessImpl(const BrowserProcessImpl&) = delete;
106 BrowserProcessImpl& operator=(const BrowserProcessImpl&) = delete;
107
Daniel Chenga542fca2014-10-21 09:51:29108 ~BrowserProcessImpl() override;
initial.commit09911bf2008-07-26 23:55:29109
Scott Violet875789e2018-02-02 07:46:48110 // Called to complete initialization.
111 void Init();
112
Xiaohan Wang55ae2c012022-01-20 21:49:11113#if !BUILDFLAG(IS_ANDROID)
Greg Thompson822ab51a2018-09-18 06:45:29114 // Sets a closure to be run to break out of a run loop on browser shutdown
115 // (when the KeepAlive count reaches zero).
116 // TODO(https://crbug.com/845966): This is also used on macOS for the Cocoa
117 // first run dialog so that shutdown can be initiated via a signal while the
118 // first run dialog is showing.
Filip Gorski209a3472018-08-27 23:03:41119 void SetQuitClosure(base::OnceClosure quit_closure);
Wez25fd35f2018-05-25 22:57:41120#endif
121
Xiaohan Wang55ae2c012022-01-20 21:49:11122#if BUILDFLAG(IS_MAC)
Greg Thompson822ab51a2018-09-18 06:45:29123 // Clears the quit closure. Shutdown will not be initiated should the
124 // KeepAlive count reach zero. This function may be called more than once.
125 // TODO(https://crbug.com/845966): Remove this once the Cocoa first run
126 // dialog no longer needs it.
127 void ClearQuitClosure();
Wez25fd35f2018-05-25 22:57:41128#endif
129
[email protected]99907362012-01-11 05:41:40130 // Called before the browser threads are created.
Gabriel Charette4c1897a2022-05-02 18:22:25131 void PreCreateThreads();
[email protected]2e5b60a22011-11-28 15:56:41132
[email protected]d2caaa22011-12-12 03:04:15133 // Called after the threads have been created but before the message loops
134 // starts running. Allows the browser process to do any initialization that
135 // requires all threads running.
136 void PreMainMessageLoopRun();
137
[email protected]2e5b60a22011-11-28 15:56:41138 // Most cleanup is done by these functions, driven from
139 // ChromeBrowserMain based on notifications from the content
140 // framework, rather than in the destructor, so that we can
141 // interleave cleanup with threads being stopped.
Xiaohan Wang55ae2c012022-01-20 21:49:11142#if !BUILDFLAG(IS_ANDROID)
[email protected]2e5b60a22011-11-28 15:56:41143 void StartTearDown();
[email protected]99907362012-01-11 05:41:40144 void PostDestroyThreads();
thestigd75ce5532015-10-05 22:08:34145#endif
[email protected]2e5b60a22011-11-28 15:56:41146
Xi Han07bad2892018-10-04 15:13:58147 // Sets |metrics_services_manager_| and |metrics_services_manager_client_|
148 // which is owned by it.
149 void SetMetricsServices(
150 std::unique_ptr<metrics_services_manager::MetricsServicesManager> manager,
151 metrics_services_manager::MetricsServicesManagerClient* client);
152
[email protected]80745e32012-05-08 01:22:12153 // BrowserProcess implementation.
Daniel Chenga542fca2014-10-21 09:51:29154 void EndSession() override;
Gabriel Charetteb1af7ffb2017-07-27 06:10:35155 void FlushLocalStateAndReply(base::OnceClosure reply) override;
blundell695d61f2015-10-21 11:25:53156 metrics_services_manager::MetricsServicesManager* GetMetricsServicesManager()
157 override;
Daniel Chenga542fca2014-10-21 09:51:29158 metrics::MetricsService* metrics_service() override;
Min Qin8caab1d2018-10-03 17:28:13159 // TODO(qinmin): Remove this method as callers can retrieve the global
160 // instance from SystemNetworkContextManager directly.
Matt Menke21b9cc62017-08-23 15:45:45161 SystemNetworkContextManager* system_network_context_manager() override;
Antonio Gomesacd1a942018-07-10 20:23:54162 scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory()
163 override;
Tarun Bansalcd6a6cb2018-06-27 22:03:22164 network::NetworkQualityTracker* network_quality_tracker() override;
James Scottf4b57662023-05-17 20:52:28165 embedder_support::OriginTrialsSettingsStorage*
166 GetOriginTrialsSettingsStorage() override;
Daniel Chenga542fca2014-10-21 09:51:29167 ProfileManager* profile_manager() override;
168 PrefService* local_state() override;
blundell57bcfed2015-09-04 08:44:45169 variations::VariationsService* variations_service() override;
Daniel Chenga542fca2014-10-21 09:51:29170 BrowserProcessPlatformPart* platform_part() override;
171 extensions::EventRouterForwarder* extension_event_router_forwarder() override;
172 NotificationUIManager* notification_ui_manager() override;
miguelg23cd2dd72016-04-21 15:24:03173 NotificationPlatformBridge* notification_platform_bridge() override;
Scott Violetfdd6f352018-01-12 19:12:29174 policy::ChromeBrowserPolicyConnector* browser_policy_connector() override;
Daniel Chenga542fca2014-10-21 09:51:29175 policy::PolicyService* policy_service() override;
176 IconManager* icon_manager() override;
Daniel Chenga542fca2014-10-21 09:51:29177 GpuModeManager* gpu_mode_manager() override;
Pavel Feldmanc9ae59c2018-02-13 16:15:15178 void CreateDevToolsProtocolHandler() override;
dgozman54cc54e2016-02-23 03:47:30179 void CreateDevToolsAutoOpener() override;
Daniel Chenga542fca2014-10-21 09:51:29180 bool IsShuttingDown() override;
181 printing::PrintJobManager* print_job_manager() override;
182 printing::PrintPreviewDialogController* print_preview_dialog_controller()
183 override;
184 printing::BackgroundPrintingManager* background_printing_manager() override;
Xiaohan Wang55ae2c012022-01-20 21:49:11185#if !BUILDFLAG(IS_ANDROID)
Daniel Chenga542fca2014-10-21 09:51:29186 IntranetRedirectDetector* intranet_redirect_detector() override;
Tommy Lid5b7c22b2020-10-28 01:26:51187#endif
Daniel Chenga542fca2014-10-21 09:51:29188 const std::string& GetApplicationLocale() override;
Xi Han349162b2018-10-26 12:44:23189 void SetApplicationLocale(const std::string& actual_locale) override;
Daniel Chenga542fca2014-10-21 09:51:29190 DownloadStatusUpdater* download_status_updater() override;
191 DownloadRequestLimiter* download_request_limiter() override;
192 BackgroundModeManager* background_mode_manager() override;
Reid Kleckner4d3f21c2021-01-25 22:48:31193#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
Daniel Chenga542fca2014-10-21 09:51:29194 void set_background_mode_manager_for_test(
dcheng4af48582016-04-19 00:29:35195 std::unique_ptr<BackgroundModeManager> manager) override;
Reid Kleckner4d3f21c2021-01-25 22:48:31196#endif
Daniel Chenga542fca2014-10-21 09:51:29197 StatusTray* status_tray() override;
vakh9a474d832015-11-13 01:43:09198 safe_browsing::SafeBrowsingService* safe_browsing_service() override;
Eric Robinsonefb3ea552018-11-02 18:24:32199 subresource_filter::RulesetService* subresource_filter_ruleset_service()
200 override;
Zainab Rizvi766266982024-04-09 13:55:41201 subresource_filter::RulesetService*
202 fingerprinting_protection_ruleset_service() override;
[email protected]6641bf662009-08-21 00:34:09203
Xi Han9fd44002019-04-30 17:39:36204 StartupData* startup_data() override;
205
Yuta Hijikata235fc62b2020-12-08 03:48:32206// TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
207// of lacros-chrome is complete.
Xiaohan Wang55ae2c012022-01-20 21:49:11208#if BUILDFLAG(IS_WIN) || (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
dchenge1bc7982014-10-30 00:32:40209 void StartAutoupdateTimer() override;
[email protected]3cdacd42010-04-30 18:55:53210#endif
[email protected]bd48c2b02010-04-09 20:32:42211
Daniel Chenga542fca2014-10-21 09:51:29212 component_updater::ComponentUpdateService* component_updater() override;
Daniel Chenga542fca2014-10-21 09:51:29213 MediaFileSystemRegistry* media_file_system_registry() override;
Daniel Chenga542fca2014-10-21 09:51:29214 WebRtcLogUploader* webrtc_log_uploader() override;
Daniel Chenga542fca2014-10-21 09:51:29215 network_time::NetworkTimeTracker* network_time_tracker() override;
Xiaohan Wang55ae2c012022-01-20 21:49:11216#if !BUILDFLAG(IS_ANDROID)
Daniel Chenga542fca2014-10-21 09:51:29217 gcm::GCMDriver* gcm_driver() override;
Adam Langley1cb73c72020-08-28 17:06:44218#endif
lpyfedf65a2017-06-01 01:41:24219 resource_coordinator::TabManager* GetTabManager() override;
Sebastien Marchand2ebd9252018-11-08 18:39:35220 resource_coordinator::ResourceCoordinatorParts* resource_coordinator_parts()
221 override;
[email protected]ca167a32011-09-30 15:19:11222
Xiaohan Wang55ae2c012022-01-20 21:49:11223#if !BUILDFLAG(IS_ANDROID)
Reilly Grantbfc2ab72021-06-02 23:57:30224 SerialPolicyAllowedPorts* serial_policy_allowed_ports() override;
Jack Hsiehea76b94b52022-12-13 16:37:05225 HidSystemTrayIcon* hid_system_tray_icon() override;
Juan Garza Sanchez696d43192023-07-11 21:58:06226 UsbSystemTrayIcon* usb_system_tray_icon() override;
Reilly Grantbfc2ab72021-06-02 23:57:30227#endif
228
Will Harris9b89cb02023-10-18 21:56:09229 os_crypt_async::OSCryptAsync* os_crypt_async() override;
230
Greg Thompson08451a42020-02-04 23:45:54231 BuildState* GetBuildState() override;
232
[email protected]b1de2c72013-02-06 02:45:47233 static void RegisterPrefs(PrefRegistrySimple* registry);
234
initial.commit09911bf2008-07-26 23:55:29235 private:
Elad Alon39b1f6cc2018-08-30 09:52:21236 using WebRtcEventLogManager = webrtc_event_logging::WebRtcEventLogManager;
237
dgnfe075c82016-03-18 11:25:35238 // KeepAliveStateObserver implementation
239 void OnKeepAliveStateChanged(bool is_keeping_alive) override;
240 void OnKeepAliveRestartStateChanged(bool can_restart) override;
241
Tarun Bansal86b39222018-09-21 02:07:32242 // Create network quality observer so that it can propagate network quality
243 // changes to the render process.
244 void CreateNetworkQualityObserver();
245
initial.commit09911bf2008-07-26 23:55:29246 void CreateProfileManager();
initial.commit09911bf2008-07-26 23:55:29247 void CreateIconManager();
miguelg23cd2dd72016-04-21 15:24:03248 void CreateNotificationPlatformBridge();
[email protected]29672ab2009-10-30 03:44:03249 void CreateNotificationUIManager();
[email protected]d8ce31e2012-12-19 05:09:21250 void CreatePrintPreviewDialogController();
[email protected]68f88b992011-05-07 02:01:39251 void CreateBackgroundPrintingManager();
[email protected]462a0ff2011-06-02 17:15:34252 void CreateSafeBrowsingService();
engedyc5ef21ad2016-06-17 20:22:27253 void CreateSubresourceFilterRulesetService();
Zainab Rizvi766266982024-04-09 13:55:41254 void CreateFingerprintingProtectionRulesetService();
Sophie Changf453c0522017-11-03 06:33:49255 void CreateOptimizationGuideService();
[email protected]9e7f015f2011-05-28 00:24:25256 void CreateStatusTray();
257 void CreateBackgroundModeManager();
[email protected]c027d6d2014-06-05 15:25:40258 void CreateGCMDriver();
Kalvin Lee5873f732022-07-27 01:58:22259 void CreateNetworkTimeTracker();