Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_ | ||||
6 | #define CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_ | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 7 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 8 | #include <memory> |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 9 | #include <optional> |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 10 | |
Jan Keitel | 748d58e0 | 2024-01-19 21:55:38 | [diff] [blame] | 11 | #include "base/callback_list.h" |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 12 | #include "base/functional/callback_helpers.h" |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 14 | #include "base/memory/raw_ref.h" |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
Gabriel Charette | eadf5886 | 2019-08-29 05:20:27 | [diff] [blame] | 16 | #include "base/task/thread_pool/thread_pool_instance.h" |
Gabriel Charette | 7870bb6 | 2021-11-30 14:32:50 | [diff] [blame] | 17 | #include "base/types/strong_alias.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 18 | #include "build/build_config.h" |
John Abd-El-Malek | f3243dc | 2021-05-07 16:20:01 | [diff] [blame] | 19 | #include "content/browser/browser_process_io_thread.h" |
Lei Zhang | 7ab31375 | 2021-11-17 01:26:00 | [diff] [blame] | 20 | #include "content/common/content_export.h" |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 21 | #include "content/public/browser/browser_main_runner.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 22 | #include "media/media_buildflags.h" |
Miyoung Shin | 99505dd | 2019-07-27 12:45:35 | [diff] [blame] | 23 | #include "services/viz/public/mojom/compositing/compositing_mode_watcher.mojom.h" |
Scott Violet | b72577d | 2019-01-09 22:18:18 | [diff] [blame] | 24 | #include "ui/base/buildflags.h" |
Eriko Kurimoto | bb0e760c | 2023-12-04 15:13:20 | [diff] [blame] | 25 | #include "ui/base/ozone_buildflags.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 26 | |
sadrul | 578205fa | 2016-04-11 22:43:56 | [diff] [blame] | 27 | #if defined(USE_AURA) |
28 | namespace aura { | ||||
29 | class Env; | ||||
30 | } | ||||
31 | #endif | ||||
32 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 33 | namespace base { |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 34 | class CommandLine; |
[email protected] | 89bf27e | 2013-06-27 18:04:56 | [diff] [blame] | 35 | class HighResolutionTimerManager; |
gab | 3ee0e44 | 2016-12-16 17:43:11 | [diff] [blame] | 36 | class MemoryPressureMonitor; |
kylechar | ee7cefd | 2017-07-13 16:05:03 | [diff] [blame] | 37 | class SingleThreadTaskRunner; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 38 | class SystemMonitor; |
[email protected] | 111494e | 2013-07-24 18:38:29 | [diff] [blame] | 39 | } // namespace base |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 40 | |
Ken Rockot | 27a62d5 | 2019-10-30 01:57:01 | [diff] [blame] | 41 | namespace data_decoder { |
42 | class ServiceProvider; | ||||
43 | } | ||||
44 | |||||
sadrul | 059bc53 | 2017-07-05 21:22:16 | [diff] [blame] | 45 | namespace gpu { |
46 | class GpuChannelEstablishFactory; | ||||
47 | } | ||||
48 | |||||
[email protected] | 67dfea90 | 2012-04-03 01:49:09 | [diff] [blame] | 49 | namespace media { |
alokp | 2cbd4fc | 2017-05-13 04:13:24 | [diff] [blame] | 50 | class AudioManager; |
olka | ef762c9 | 2017-02-06 16:45:16 | [diff] [blame] | 51 | class AudioSystem; |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 52 | #if BUILDFLAG(IS_WIN) |
mcasas | 96388e9 | 2016-03-02 02:18:07 | [diff] [blame] | 53 | class SystemMessageWindowWin; |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 54 | #elif (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(USE_UDEV) |
mcasas | 9d206368 | 2016-02-11 22:12:39 | [diff] [blame] | 55 | class DeviceMonitorLinux; |
56 | #endif | ||||
toyoshim | 59e31971 | 2016-10-13 06:43:29 | [diff] [blame] | 57 | } // namespace media |
58 | |||||
toyoshim | 78b9d63 | 2015-05-08 04:58:31 | [diff] [blame] | 59 | namespace midi { |
toyoshim | 967340a | 2016-12-15 06:18:29 | [diff] [blame] | 60 | class MidiService; |
toyoshim | 78b9d63 | 2015-05-08 04:58:31 | [diff] [blame] | 61 | } // namespace midi |
[email protected] | 67dfea90 | 2012-04-03 01:49:09 | [diff] [blame] | 62 | |
amistry | cafcdff | 2016-06-17 03:33:48 | [diff] [blame] | 63 | namespace mojo { |
Ken Rockot | dba46db | 2018-07-04 18:41:04 | [diff] [blame] | 64 | namespace core { |
amistry | cafcdff | 2016-06-17 03:33:48 | [diff] [blame] | 65 | class ScopedIPCSupport; |
Ken Rockot | 8a7f35f | 2018-07-04 19:40:56 | [diff] [blame] | 66 | } // namespace core |
amistry | cafcdff | 2016-06-17 03:33:48 | [diff] [blame] | 67 | } // namespace mojo |
68 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 69 | namespace net { |
70 | class NetworkChangeNotifier; | ||||
[email protected] | 111494e | 2013-07-24 18:38:29 | [diff] [blame] | 71 | } // namespace net |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 72 | |
fsamuel | ea696982 | 2017-06-12 21:14:32 | [diff] [blame] | 73 | namespace viz { |
danakj | ab9ef4d | 2017-10-31 23:38:33 | [diff] [blame] | 74 | class CompositingModeReporterImpl; |
Fady Samuel | dea5e8f | 2017-07-19 21:41:33 | [diff] [blame] | 75 | class HostFrameSinkManager; |
François Doray | f6b9b34 | 2019-07-15 15:34:34 | [diff] [blame] | 76 | } // namespace viz |
fsamuel | ea696982 | 2017-06-12 21:14:32 | [diff] [blame] | 77 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 78 | namespace content { |
Greg Thompson | d97b838 | 2023-08-22 10:18:39 | [diff] [blame] | 79 | class BrowserAccessibilityStateImpl; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 80 | class BrowserMainParts; |
Alex Attar | 63ab3bd | 2023-07-11 19:31:44 | [diff] [blame] | 81 | class BackgroundTracingManager; |
[email protected] | 2208a74d | 2012-10-29 17:09:44 | [diff] [blame] | 82 | class BrowserOnlineStateObserver; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 83 | class BrowserThreadImpl; |
Tommy Steimel | 561c68b | 2019-01-24 07:27:04 | [diff] [blame] | 84 | class MediaKeysListenerManagerImpl; |
[email protected] | 1d232b9 | 2012-10-29 17:39:07 | [diff] [blame] | 85 | class MediaStreamManager; |
ananta | 73296c57 | 2016-08-15 21:58:25 | [diff] [blame] | 86 | class SaveFileManager; |
braveyao | ab81ed65 | 2018-10-03 17:37:51 | [diff] [blame] | 87 | class ScreenlockMonitor; |
Ayu Ishii | ae5d9bf | 2020-05-01 18:50:09 | [diff] [blame] | 88 | class SmsProvider; |
[email protected] | fcb8e021 | 2012-10-29 11:57:18 | [diff] [blame] | 89 | class SpeechRecognitionManagerImpl; |
[email protected] | 232e09d | 2013-08-27 15:29:56 | [diff] [blame] | 90 | class StartupTaskRunner; |
Ehsan Chiniforooshan | c77b44e | 2017-10-10 18:12:10 | [diff] [blame] | 91 | class TracingControllerImpl; |
[email protected] | 97646c9 | 2012-07-31 20:30:08 | [diff] [blame] | 92 | struct MainFunctionParams; |
93 | |||||
erikchen | cfb4c383 | 2018-08-13 20:49:28 | [diff] [blame] | 94 | namespace responsiveness { |
95 | class Watcher; | ||||
96 | } // namespace responsiveness | ||||
97 | |||||
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 98 | #if BUILDFLAG(IS_ANDROID) |
jonross | 3698029 | 2014-10-08 15:55:10 | [diff] [blame] | 99 | class ScreenOrientationDelegate; |
[email protected] | 97646c9 | 2012-07-31 20:30:08 | [diff] [blame] | 100 | #endif |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 101 | |
[email protected] | 53ab480 | 2012-04-12 22:14:35 | [diff] [blame] | 102 | // Implements the main browser loop stages called from BrowserMainRunner. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 103 | // See comments in browser_main_parts.h for additional info. |
[email protected] | 89acda8 | 2013-06-25 20:52:50 | [diff] [blame] | 104 | class CONTENT_EXPORT BrowserMainLoop { |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 105 | public: |
[email protected] | aa44546 | 2013-06-21 17:12:36 | [diff] [blame] | 106 | // Returns the current instance. This is used to get access to the getters |
107 | // that return objects which are owned by this class. | ||||
108 | static BrowserMainLoop* GetInstance(); | ||||
109 | |||||
Xi Han | 57b856f8 | 2018-06-22 18:10:10 | [diff] [blame] | 110 | static media::AudioManager* GetAudioManager(); |
111 | |||||
Gabriel Charette | 43fd370 | 2019-05-29 16:36:51 | [diff] [blame] | 112 | // The ThreadPoolInstance must exist but not to be started when building |
Xi Han | f19a89e8 | 2018-06-14 13:26:30 | [diff] [blame] | 113 | // BrowserMainLoop. |
Xi Han | 8012e46 | 2018-10-05 19:52:30 | [diff] [blame] | 114 | explicit BrowserMainLoop( |
Gabriel Charette | fbeeb1c | 2021-11-10 20:50:06 | [diff] [blame] | 115 | MainFunctionParams parameters, |
Gabriel Charette | 43fd370 | 2019-05-29 16:36:51 | [diff] [blame] | 116 | std::unique_ptr<base::ThreadPoolInstance::ScopedExecutionFence> fence); |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 117 | |
118 | BrowserMainLoop(const BrowserMainLoop&) = delete; | ||||
119 | BrowserMainLoop& operator=(const BrowserMainLoop&) = delete; | ||||
120 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 121 | virtual ~BrowserMainLoop(); |
122 | |||||
Xi Han | 4090dcc | 2018-07-11 03:15:20 | [diff] [blame] | 123 | void Init(); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 124 | |
Scott Violet | 9068b4df | 2018-01-12 16:44:21 | [diff] [blame] | 125 | // Return value is exit status. Anything other than RESULT_CODE_NORMAL_EXIT |
126 | // is considered an error. | ||||
127 | int EarlyInitialization(); | ||||
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 128 | |
[email protected] | d957b10 | 2014-04-25 20:17:19 | [diff] [blame] | 129 | // Initializes the toolkit. Returns whether the toolkit initialization was |
130 | // successful or not. | ||||
131 | bool InitializeToolkit(); | ||||
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 132 | |
Gabriel Charette | 09c6a96e | 2021-05-17 14:52:59 | [diff] [blame] | 133 | void PreCreateMainMessageLoop(); |
Gabriel Charette | c716bcf3 | 2021-03-16 16:25:35 | [diff] [blame] | 134 | // Creates the main message loop, bringing APIs like |
Sean Maher | 70f294293 | 2023-01-04 22:15:06 | [diff] [blame] | 135 | // SingleThreadTaskRunner::GetCurrentDefault() online. |
Gabriel Charette | 09c6a96e | 2021-05-17 14:52:59 | [diff] [blame] | 136 | void CreateMainMessageLoop(); |
137 | void PostCreateMainMessageLoop(); | ||||
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 138 | |
Alexander Dunaev | 0521017 | 2022-01-19 19:43:09 | [diff] [blame] | 139 | // Creates a "bare" message loop that is required to exit gracefully at the |
140 | // early stage if the toolkit failed to initialise. | ||||
141 | void CreateMessageLoopForEarlyShutdown(); | ||||
142 | |||||
[email protected] | 232e09d | 2013-08-27 15:29:56 | [diff] [blame] | 143 | // Create and start running the tasks we need to complete startup. Note that |
144 | // this can be called more than once (currently only on Android) if we get a | ||||
145 | // request for synchronous startup while the tasks created by asynchronous | ||||
Gabriel Charette | c716bcf3 | 2021-03-16 16:25:35 | [diff] [blame] | 146 | // startup are still running. Completes tasks synchronously as part of this |
147 | // method on non-Android platforms. | ||||
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 148 | void CreateStartupTasks(); |
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 149 | |
Gabriel Charette | c716bcf3 | 2021-03-16 16:25:35 | [diff] [blame] | 150 | // Performs the default message loop run logic. |
151 | void RunMainMessageLoop(); | ||||
152 | |||||
153 | // Performs the pre-shutdown steps. | ||||
154 | void PreShutdown(); | ||||
[email protected] | f573ed6b | 2012-02-10 15:58:52 | [diff] [blame] | 155 | |
156 | // Performs the shutdown sequence, starting with PostMainMessageLoopRun | ||||
157 | // through stopping threads to PostDestroyThreads. | ||||
158 | void ShutdownThreadsAndCleanUp(); | ||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 159 | |
160 | int GetResultCode() const { return result_code_; } | ||||
161 | |||||
Shelley Vohr | 98d8535 | 2021-10-28 17:11:36 | [diff] [blame] | 162 | // Needed by some embedders. |
163 | void SetResultCode(int code) { result_code_ = code; } | ||||
164 | |||||
Olga Sharonova | 57964cb | 2018-05-17 11:08:00 | [diff] [blame] | 165 | media::AudioManager* audio_manager() const; |
Olga Sharonova | 57964cb | 2018-05-17 11:08:00 | [diff] [blame] | 166 | bool AudioServiceOutOfProcess() const; |
olka | ef762c9 | 2017-02-06 16:45:16 | [diff] [blame] | 167 | media::AudioSystem* audio_system() const { return audio_system_.get(); } |
[email protected] | aa44546 | 2013-06-21 17:12:36 | [diff] [blame] | 168 | MediaStreamManager* media_stream_manager() const { |
169 | return media_stream_manager_.get(); | ||||
170 | } | ||||
Tommy Steimel | 561c68b | 2019-01-24 07:27:04 | [diff] [blame] | 171 | MediaKeysListenerManagerImpl* media_keys_listener_manager() const { |
172 | return media_keys_listener_manager_.get(); | ||||
173 | } | ||||
Marina Ciocea | 35090794 | 2018-05-07 07:54:23 | [diff] [blame] | 174 | |
Eriko Kurimoto | 6465646 | 2022-07-21 01:07:49 | [diff] [blame] | 175 | #if BUILDFLAG(IS_CHROMEOS) |
John Abd-El-Malek | 0343895 | 2019-05-16 22:53:51 | [diff] [blame] | 176 | // Only expose this on ChromeOS since it's only needed there. On Android this |
177 | // be null if this process started in reduced mode. | ||||
178 | net::NetworkChangeNotifier* network_change_notifier() const { | ||||
179 | return network_change_notifier_.get(); | ||||
180 | } | ||||
Marina Ciocea | 35090794 | 2018-05-07 07:54:23 | [diff] [blame] | 181 | #endif |
182 | |||||
toyoshim | 967340a | 2016-12-15 06:18:29 | [diff] [blame] | 183 | midi::MidiService* midi_service() const { return midi_service_.get(); } |
[email protected] | 52e456b9 | 2012-02-23 17:13:18 | [diff] [blame] | 184 | |
kylechar | ee7cefd | 2017-07-13 16:05:03 | [diff] [blame] | 185 | // Returns the task runner for tasks that that are critical to producing a new |
186 | // CompositorFrame on resize. On Mac this will be the task runner provided by | ||||
187 | // WindowResizeHelperMac, on other platforms it will just be the thread task | ||||
188 | // runner. | ||||
189 | scoped_refptr<base::SingleThreadTaskRunner> GetResizeTaskRunner(); | ||||
190 | |||||
sadrul | 059bc53 | 2017-07-05 21:22:16 | [diff] [blame] | 191 | gpu::GpuChannelEstablishFactory* gpu_channel_establish_factory() const; |
192 | |||||
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 193 | #if BUILDFLAG(IS_ANDROID) |
Bo Liu | 79c92c3b | 2017-06-28 18:52:25 | [diff] [blame] | 194 | void SynchronouslyFlushStartupTasks(); |
Alex Clarke | bc88088 | 2019-04-05 16:48:00 | [diff] [blame] | 195 | |
196 | // |enabled| Whether or not CreateStartupTasks() posts any tasks. This is | ||||
197 | // useful because some javatests want to test native task posting without the | ||||
198 | // whole browser loaded. In that scenario tasks posted by CreateStartupTasks() | ||||
199 | // may crash if run. | ||||
200 | static void EnableStartupTasks(bool enabled); | ||||
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 201 | #endif // BUILDFLAG(IS_ANDROID) |
Bo Liu | 79c92c3b | 2017-06-28 18:52:25 | [diff] [blame] | 202 | |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 203 | #if !BUILDFLAG(IS_ANDROID) |
danakj | 4def4a24 | 2017-06-24 01:18:37 | [diff] [blame] | 204 | // TODO(fsamuel): We should find an object to own HostFrameSinkManager on all |
fsamuel | ea696982 | 2017-06-12 21:14:32 | [diff] [blame] | 205 | // platforms including Android. See http://crbug.com/732507. |
danakj | 4def4a24 | 2017-06-24 01:18:37 | [diff] [blame] | 206 | viz::HostFrameSinkManager* host_frame_sink_manager() const { |
207 | return host_frame_sink_manager_.get(); | ||||
fsamuel | ea696982 | 2017-06-12 21:14:32 | [diff] [blame] | 208 | } |
209 | #endif | ||||
210 | |||||
Gyuyoung Kim | 11f483a1 | 2019-09-18 02:15:13 | [diff] [blame] | 211 | // Binds a receiver to the singleton CompositingModeReporter. |
danakj | ab9ef4d | 2017-10-31 23:38:33 | [diff] [blame] | 212 | void GetCompositingModeReporter( |
Gyuyoung Kim | 11f483a1 | 2019-09-18 02:15:13 | [diff] [blame] | 213 | mojo::PendingReceiver<viz::mojom::CompositingModeReporter> receiver); |
danakj | ab9ef4d | 2017-10-31 23:38:33 | [diff] [blame] | 214 | |
Ayu Ishii | ae5d9bf | 2020-05-01 18:50:09 | [diff] [blame] | 215 | SmsProvider* GetSmsProvider(); |
216 | void SetSmsProviderForTesting(std::unique_ptr<SmsProvider>); | ||||
217 | |||||
Scott Violet | a41777b | 2018-01-18 20:43:41 | [diff] [blame] | 218 | BrowserMainParts* parts() { return parts_.get(); } |
219 | |||||
Michael Thiessen | c8842d0 | 2023-02-16 17:06:02 | [diff] [blame] | 220 | // This should only be called after the IO thread has been started (and will |
221 | // crash otherwise). May block on the thread ID being initialized if the IO | ||||
222 | // thread ThreadMain has not yet run. | ||||
223 | base::PlatformThreadId GetIOThreadId(); | ||||
224 | |||||
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 225 | private: |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 226 | FRIEND_TEST_ALL_PREFIXES(BrowserMainLoopTest, CreateThreadsInSingleProcess); |
Carlos Caballero | e840fc3 | 2019-05-27 14:16:37 | [diff] [blame] | 227 | FRIEND_TEST_ALL_PREFIXES( |
228 | BrowserMainLoopTest, | ||||
229 | PostTaskToIOThreadBeforeThreadCreationDoesNotRunTask); | ||||
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 230 | |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 231 | // Called just before creating the threads |
232 | int PreCreateThreads(); | ||||
233 | |||||
234 | // Create all secondary threads. | ||||
235 | int CreateThreads(); | ||||
236 | |||||
Xi Cheng | 8c965371 | 2018-01-24 06:07:27 | [diff] [blame] | 237 | // Called just after creating the threads. |
238 | int PostCreateThreads(); | ||||
Gabriel Charette | c716bcf3 | 2021-03-16 16:25:35 | [diff] [blame] | 239 | void PostCreateThreadsImpl(); |
[email protected] | 57624ab | 2013-08-01 16:01:51 | [diff] [blame] | 240 | |
241 | int PreMainMessageLoopRun(); | ||||
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 242 | |
Gabriel Charette | 7870bb6 | 2021-11-30 14:32:50 | [diff] [blame] | 243 | // One last opportunity to intercept the upcoming MainMessageLoopRun (or |
244 | // before yielding to the native loop on Android). Returns false iff the run | ||||
245 | // should proceed after this call. | ||||
246 | using ProceedWithMainMessageLoopRun = | ||||
247 | base::StrongAlias<class ProceedWithMainMessageLoopRunTag, bool>; | ||||
248 | ProceedWithMainMessageLoopRun InterceptMainMessageLoopRun(); | ||||
249 | |||||
sadrul | a15cfccb | 2016-08-08 18:04:07 | [diff] [blame] | 250 | void InitializeMojo(); |
[email protected] | 1eb1461 | 2013-11-21 01:04:58 | [diff] [blame] | 251 | |
Olga Sharonova | c0c0d24 | 2018-06-19 10:13:47 | [diff] [blame] | 252 | void InitializeAudio(); |
alokp | 2cbd4fc | 2017-05-13 04:13:24 | [diff] [blame] | 253 | |
boliu | 7439d04 | 2015-01-27 22:51:11 | [diff] [blame] | 254 | bool UsingInProcessGpu() const; |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 255 | |
bashi | 58dd2fa | 2016-10-17 00:01:07 | [diff] [blame] | 256 | void InitializeMemoryManagementComponent(); |
257 | |||||
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 258 | // Quick reference for initialization order: |
259 | // Constructor | ||||
260 | // Init() | ||||
261 | // EarlyInitialization() | ||||
262 | // InitializeToolkit() | ||||
Gabriel Charette | 09c6a96e | 2021-05-17 14:52:59 | [diff] [blame] | 263 | // PreCreateMainMessageLoop() |
264 | // CreateMainMessageLoop() | ||||
265 | // PostCreateMainMessageLoop() | ||||
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 266 | // CreateStartupTasks() |
267 | // PreCreateThreads() | ||||
Gabriel Charette | c716bcf3 | 2021-03-16 16:25:35 | [diff] [blame] | 268 | // InitializeMemoryManagementComponent() |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 269 | // CreateThreads() |
Xi Cheng | 8c965371 | 2018-01-24 06:07:27 | [diff] [blame] | 270 | // PostCreateThreads() |
Gabriel Charette | c716bcf3 | 2021-03-16 16:25:35 | [diff] [blame] | 271 | // PostCreateThreadsImpl() |
272 | // InitializeMojo() | ||||
273 | // InitializeAudio() | ||||
274 | // PreMainMessageLoopRun() | ||||
275 | // MainMessageLoopRun() | ||||
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 276 | // OnFirstIdle() |
boliu | 7439d04 | 2015-01-27 22:51:11 | [diff] [blame] | 277 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 278 | // Members initialized on construction --------------------------------------- |
Gabriel Charette | fbeeb1c | 2021-11-10 20:50:06 | [diff] [blame] | 279 | MainFunctionParams parameters_; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 280 | const raw_ref<const base::CommandLine> parsed_command_line_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 281 | int result_code_; |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 282 | bool created_threads_; // True if the non-UI threads were created. |
Xi Han | 8012e46 | 2018-10-05 19:52:30 | [diff] [blame] | 283 | // //content must be initialized single-threaded until |
284 | // BrowserMainLoop::CreateThreads() as things initialized before it require an | ||||
285 | // initialize-once happens-before relationship with all eventual content tasks | ||||
286 | // running on other threads. This ScopedExecutionFence ensures that no tasks | ||||
Gabriel Charette | 52fa3ae | 2019-04-15 21:44:37 | [diff] [blame] | 287 | // posted to ThreadPool gets to run before CreateThreads(); satisfying this |
Gabriel Charette | 43fd370 | 2019-05-29 16:36:51 | [diff] [blame] | 288 | // requirement even though the ThreadPoolInstance is created and started |
289 | // before content is entered. | ||||
290 | std::unique_ptr<base::ThreadPoolInstance::ScopedExecutionFence> | ||||
Xi Han | 8012e46 | 2018-10-05 19:52:30 | [diff] [blame] | 291 | scoped_execution_fence_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 292 | |
François Doray | f6b9b34 | 2019-07-15 15:34:34 | [diff] [blame] | 293 | // BEST_EFFORT tasks are not allowed to run between //content initialization |
294 | // and startup completion. | ||||
295 | // | ||||
296 | // TODO(fdoray): Move this to a more elaborate class that prevents BEST_EFFORT | ||||
297 | // tasks from running when resources are needed to respond to user actions. | ||||
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 298 | std::optional<base::ThreadPoolInstance::ScopedBestEffortExecutionFence> |
François Doray | f6b9b34 | 2019-07-15 15:34:34 | [diff] [blame] | 299 | scoped_best_effort_execution_fence_; |
300 | |||||
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 301 | // Members initialized in |Init()| ------------------------------------------- |
302 | std::unique_ptr<mojo::core::ScopedIPCSupport> mojo_ipc_support_; | ||||
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 303 | |
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 304 | // Members initialized in |InitializeToolkit()| ------------------------------ |
sadrul | 578205fa | 2016-04-11 22:43:56 | [diff] [blame] | 305 | #if defined(USE_AURA) |
306 | std::unique_ptr<aura::Env> env_; | ||||
307 | #endif | ||||
308 | |||||
Gabriel Charette | 09c6a96e | 2021-05-17 14:52:59 | [diff] [blame] | 309 | // Members initialized in |PostCreateMainMessageLoop()| ---------------------- |
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 310 | std::unique_ptr<base::SystemMonitor> system_monitor_; |
311 | std::unique_ptr<base::HighResolutionTimerManager> hi_res_timer_manager_; | ||||
312 | std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; | ||||
313 | std::unique_ptr<ScreenlockMonitor> screenlock_monitor_; | ||||
314 | // Per-process listener for online state changes. | ||||
315 | std::unique_ptr<BrowserOnlineStateObserver> online_state_observer_; | ||||
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 316 | #if BUILDFLAG(IS_ANDROID) |
jonross | 3698029 | 2014-10-08 15:55:10 | [diff] [blame] | 317 | // Android implementation of ScreenOrientationDelegate |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 318 | std::unique_ptr<ScreenOrientationDelegate> screen_orientation_delegate_; |
jonross | 3698029 | 2014-10-08 15:55:10 | [diff] [blame] | 319 | #endif |
Greg Thompson | d97b838 | 2023-08-22 10:18:39 | [diff] [blame] | 320 | std::unique_ptr<BrowserAccessibilityStateImpl> browser_accessibility_state_; |
chrisha | dc837f5 | 2015-05-15 03:09:06 | [diff] [blame] | 321 | |
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 322 | // Destroy |parts_| before above members (except the ones that are explicitly |
323 | // reset() on shutdown) but after |main_thread_| and services below. | ||||
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 324 | std::unique_ptr<BrowserMainParts> parts_; |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 325 | |
Gabriel Charette | 09c6a96e | 2021-05-17 14:52:59 | [diff] [blame] | 326 | // Members initialized in |CreateMainMessageLoop()| -------------------------- |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 327 | // This must get destroyed before other threads that are created in |parts_|. |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 328 | std::unique_ptr<BrowserThreadImpl> main_thread_; |
[email protected] | 60b122d | 2012-01-09 23:00:07 | [diff] [blame] | 329 | |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 330 | // Members initialized in |CreateStartupTasks()| ----------------------------- |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 331 | std::unique_ptr<StartupTaskRunner> startup_task_runner_; |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 332 | |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 333 | // Members initialized in |PreCreateThreads()| ------------------------------- |
334 | // Torn down in ShutdownThreadsAndCleanUp. | ||||
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 335 | std::unique_ptr<base::MemoryPressureMonitor> memory_pressure_monitor_; |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 336 | |
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 337 | // Members initialized in |CreateThreads()| ---------------------------------- |
338 | std::unique_ptr<BrowserProcessIOThread> io_thread_; | ||||
339 | |||||
340 | // BEGIN Members initialized in |PostCreateThreads()| ------------------------ | ||||
341 | // *************************************************************************** | ||||
Tommy Steimel | 561c68b | 2019-01-24 07:27:04 | [diff] [blame] | 342 | std::unique_ptr<MediaKeysListenerManagerImpl> media_keys_listener_manager_; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 343 | |
Ken Rockot | 27a62d5 | 2019-10-30 01:57:01 | [diff] [blame] | 344 | // Support for out-of-process Data Decoder. |
345 | std::unique_ptr<data_decoder::ServiceProvider> data_decoder_service_provider_; | ||||
346 | |||||
Olga Sharonova | 57964cb | 2018-05-17 11:08:00 | [diff] [blame] | 347 | // |audio_manager_| is not instantiated when the audio service runs out of |
348 | // process. | ||||
alokp | 2cbd4fc | 2017-05-13 04:13:24 | [diff] [blame] | 349 | std::unique_ptr<media::AudioManager> audio_manager_; |
Olga Sharonova | 57964cb | 2018-05-17 11:08:00 | [diff] [blame] | 350 | |
olka | ef762c9 | 2017-02-06 16:45:16 | [diff] [blame] | 351 | std::unique_ptr<media::AudioSystem> audio_system_; |
[email protected] | cec9563 | 2014-07-02 18:01:50 | [diff] [blame] | 352 | |
toyoshim | 967340a | 2016-12-15 06:18:29 | [diff] [blame] | 353 | std::unique_ptr<midi::MidiService> midi_service_; |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 354 | |
Kevin Marshall | f788237 | 2017-06-06 00:14:34 | [diff] [blame] | 355 | // Must be deleted on the IO thread. |
356 | std::unique_ptr<SpeechRecognitionManagerImpl> speech_recognition_manager_; | ||||
357 | |||||
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 358 | #if BUILDFLAG(IS_WIN) |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 359 | std::unique_ptr<media::SystemMessageWindowWin> system_message_window_; |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 360 | #elif (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(USE_UDEV) |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 361 | std::unique_ptr<media::DeviceMonitorLinux> device_monitor_linux_; |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 362 | #endif |
363 | |||||
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 364 | std::unique_ptr<MediaStreamManager> media_stream_manager_; |
ananta | 73296c57 | 2016-08-15 21:58:25 | [diff] [blame] | 365 | scoped_refptr<SaveFileManager> save_file_manager_; |
Ehsan Chiniforooshan | c77b44e | 2017-10-10 18:12:10 | [diff] [blame] | 366 | std::unique_ptr<content::TracingControllerImpl> tracing_controller_; |
Alex Attar | 63ab3bd | 2023-07-11 19:31:44 | [diff] [blame] | 367 | std::unique_ptr<BackgroundTracingManager> background_tracing_manager_; |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 368 | #if !BUILDFLAG(IS_ANDROID) |
danakj | 4def4a24 | 2017-06-24 01:18:37 | [diff] [blame] | 369 | std::unique_ptr<viz::HostFrameSinkManager> host_frame_sink_manager_; |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 370 | |
danakj | ab9ef4d | 2017-10-31 23:38:33 | [diff] [blame] | 371 | // Reports on the compositing mode in the system for clients to submit |
372 | // resources of the right type. This is null if the display compositor | ||||
373 | // is not in this process. | ||||
374 | std::unique_ptr<viz::CompositingModeReporterImpl> | ||||
375 | compositing_mode_reporter_impl_; | ||||
danakj | 4ee301c | 2017-11-29 16:19:43 | [diff] [blame] | 376 | #endif |
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 377 | // *************************************************************************** |
378 | // END Members initialized in |PostCreateThreads()| -------------------------- | ||||
379 | |||||
380 | // Members initialized in |PreMainMessageLoopRun()| -------------------------- | ||||
381 | scoped_refptr<responsiveness::Watcher> responsiveness_watcher_; | ||||
Jan Keitel | 748d58e0 | 2024-01-19 21:55:38 | [diff] [blame] | 382 | base::CallbackListSubscription idle_callback_subscription_; |
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 383 | |
384 | // Members not associated with a specific phase. | ||||
Gabriel Charette | e35e7db | 2021-05-12 15:30:02 | [diff] [blame] | 385 | std::unique_ptr<SmsProvider> sms_provider_; |
danakj | ab9ef4d | 2017-10-31 23:38:33 | [diff] [blame] | 386 | |
thestig | 7e202d1a | 2015-05-27 21:54:55 | [diff] [blame] | 387 | // DO NOT add members here. Add them to the right categories above. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 388 | }; |
389 | |||||
390 | } // namespace content | ||||
391 | |||||
392 | #endif // CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_ |