1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "fuchsia_web/shell/shell_relauncher.h"
7 #include <fuchsia/component/cpp/fidl.h>
8 #include <lib/sys/component/cpp/testing/realm_builder.h>
9 #include <zircon/types.h>
14 #include "base/command_line.h"
15 #include "base/functional/callback.h"
16 #include "base/run_loop.h"
17 #include "fuchsia_web/common/test/test_realm_support.h"
19 absl::optional<int> RelaunchForWebInstanceHostIfParent(
20 base::StringPiece relative_component_url,
21 const base::CommandLine& command_line) {
22 // Nothing to do if running from the context of a relaunched process.
23 static constexpr char kNoRelaunch[] = "no-relaunch";
24 if (command_line.HasSwitch(kNoRelaunch)) {
28 auto realm_builder = component_testing::RealmBuilder::CreateFromRelativeUrl(
29 {relative_component_url.data(), relative_component_url.length()});
30 test::AppendCommandLineArgumentsForRealm(realm_builder, // IN-TEST
33 auto realm = realm_builder.Build();
35 fuchsia::component::BinderPtr binder_proxy =
36 realm.component().Connect<fuchsia::component::Binder>();
38 // Wait for binder_proxy to be closed.
39 base::RunLoop run_loop;
40 binder_proxy.set_error_handler(
41 [quit_closure = run_loop.QuitClosure()](zx_status_t status) {
42 std::move(quit_closure).Run();
46 // Nothing depends on the process exit code of web_engine_shell today, so
47 // simply return success in all cases.