@@ -155,11 +155,47 @@ static void RecordStartupTimestamp() {
155155 }
156156}
157157
158+ // Though there can be multiple shells, some settings apply to all components in
159+ // the process. These have to be setup before the shell or any of its
160+ // sub-components can be initialized. In a perfect world, this would be empty.
161+ // TODO(chinmaygarde): The unfortunate side effect of this call is that settings
162+ // that cause shell initialization failures will still lead to some of their
163+ // settings being applied.
164+ static void PerformInitializationTasks (const blink::Settings& settings) {
165+ static std::once_flag gShellSettingsInitialization = {};
166+ std::call_once (gShellSettingsInitialization , [&settings] {
167+ RecordStartupTimestamp ();
168+
169+ fxl::LogSettings log_settings;
170+ log_settings.min_log_level =
171+ settings.verbose_logging ? fxl::LOG_INFO : fxl::LOG_ERROR;
172+ fxl::SetLogSettings (log_settings);
173+
174+ if (settings.trace_skia ) {
175+ InitSkiaEventTracer (settings.trace_skia );
176+ }
177+
178+ if (!settings.skia_deterministic_rendering_on_cpu ) {
179+ SkGraphics::Init ();
180+ } else {
181+ FXL_DLOG (INFO) << " Skia deterministic rendering is enabled." ;
182+ }
183+
184+ if (settings.icu_data_path .size () != 0 ) {
185+ fml::icu::InitializeICU (settings.icu_data_path );
186+ } else {
187+ FXL_DLOG (WARNING) << " Skipping ICU initialization in the shell." ;
188+ }
189+ });
190+ }
191+
158192std::unique_ptr<Shell> Shell::Create (
159193 blink::TaskRunners task_runners,
160194 blink::Settings settings,
161195 Shell::CreateCallback<PlatformView> on_create_platform_view,
162196 Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
197+ PerformInitializationTasks (settings);
198+
163199 auto vm = blink::DartVM::ForProcess (settings);
164200 FXL_CHECK (vm) << " Must be able to initialize the VM." ;
165201 return Shell::Create (std::move (task_runners), //
@@ -176,12 +212,7 @@ std::unique_ptr<Shell> Shell::Create(
176212 fxl::RefPtr<blink::DartSnapshot> isolate_snapshot,
177213 Shell::CreateCallback<PlatformView> on_create_platform_view,
178214 Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
179- RecordStartupTimestamp ();
180-
181- fxl::LogSettings log_settings;
182- log_settings.min_log_level =
183- settings.verbose_logging ? fxl::LOG_INFO : fxl::LOG_ERROR;
184- fxl::SetLogSettings (log_settings);
215+ PerformInitializationTasks (settings);
185216
186217 if (!task_runners.IsValid () || !on_create_platform_view ||
187218 !on_create_rasterizer) {
@@ -219,22 +250,6 @@ Shell::Shell(blink::TaskRunners task_runners, blink::Settings settings)
219250 FXL_DCHECK (task_runners_.IsValid ());
220251 FXL_DCHECK (task_runners_.GetPlatformTaskRunner ()->RunsTasksOnCurrentThread ());
221252
222- if (settings_.icu_data_path .size () != 0 ) {
223- fml::icu::InitializeICU (settings_.icu_data_path );
224- } else {
225- FXL_DLOG (WARNING) << " Skipping ICU initialization in the shell." ;
226- }
227-
228- if (settings_.trace_skia ) {
229- InitSkiaEventTracer (settings_.trace_skia );
230- }
231-
232- if (!settings_.skia_deterministic_rendering_on_cpu ) {
233- SkGraphics::Init ();
234- } else {
235- FXL_DLOG (INFO) << " Skia deterministic rendering is enabled." ;
236- }
237-
238253 // Install service protocol handlers.
239254
240255 service_protocol_handlers_[blink::ServiceProtocol::kScreenshotExtensionName
0 commit comments