Skip to content

Commit b8b0d72

Browse files
authored
[fuchsia] Create CF v2 Flutter runner. (flutter#29142)
1 parent fc733b3 commit b8b0d72

10 files changed

Lines changed: 993 additions & 75 deletions

File tree

ci/licenses_golden/licenses_flutter

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,9 +1413,11 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/vmservice/meta/vmservi
14131413
FILE: ../../../flutter/shell/platform/fuchsia/flutter/accessibility_bridge.cc
14141414
FILE: ../../../flutter/shell/platform/fuchsia/flutter/accessibility_bridge.h
14151415
FILE: ../../../flutter/shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc
1416-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component.cc
1417-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component.h
1418-
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_unittest.cc
1416+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v1.cc
1417+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v1.h
1418+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v1_unittest.cc
1419+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.cc
1420+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.h
14191421
FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.cc
14201422
FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.h
14211423
FILE: ../../../flutter/shell/platform/fuchsia/flutter/file_in_namespace_buffer.cc

shell/platform/fuchsia/dart_runner/dart_component_controller_v2.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ void DartComponentControllerV2::Run() {
354354
loop_->Run();
355355

356356
if (binding_.is_bound()) {
357+
// TODO(fxb/79871): This is likely a bug. We're taking the return_code
358+
// of the process (a uint32_t) and implicitly converting it into a
359+
// zx_status_t that is used as the epitaph. The uint32_t return code is
360+
// unlikely to correspond to the epitaph status that is expected to close
361+
// the connection (with the exception of 0 == ZX_OK). For the documentation
362+
// of what epitaph status we should choose, see
363+
// https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/fidl/fuchsia.component.runner/component_runner.fidl;l=118;drc=e3b39f2b57e720770773b857feca4f770ee0619e
357364
binding_.Close(return_code_);
358365
}
359366
}

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ template("runner_sources") {
5757
sources = [
5858
"accessibility_bridge.cc",
5959
"accessibility_bridge.h",
60-
"component.cc",
61-
"component.h",
60+
"component_v1.cc",
61+
"component_v1.h",
62+
"component_v2.cc",
63+
"component_v2.h",
6264
"engine.cc",
6365
"engine.h",
6466
"file_in_namespace_buffer.cc",
@@ -138,6 +140,7 @@ template("runner_sources") {
138140

139141
deps = [
140142
"$fuchsia_sdk_root/fidl:fuchsia.accessibility.semantics",
143+
"$fuchsia_sdk_root/fidl:fuchsia.component.runner",
141144
"$fuchsia_sdk_root/fidl:fuchsia.fonts",
142145
"$fuchsia_sdk_root/fidl:fuchsia.images",
143146
"$fuchsia_sdk_root/fidl:fuchsia.intl",
@@ -465,7 +468,7 @@ executable("flutter_runner_unittests") {
465468

466469
sources = [
467470
"accessibility_bridge_unittest.cc",
468-
"component_unittest.cc",
471+
"component_v1_unittest.cc",
469472
"flutter_runner_fakes.h",
470473
"focus_delegate_unittests.cc",
471474
"fuchsia_intl_unittest.cc",

shell/platform/fuchsia/flutter/component.cc renamed to shell/platform/fuchsia/flutter/component_v1.cc

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "component.h"
5+
#include "component_v1.h"
66

77
#include <dlfcn.h>
88
#include <fuchsia/mem/cpp/fidl.h>
@@ -59,7 +59,7 @@ std::string DebugLabelForUrl(const std::string& url) {
5959

6060
} // namespace
6161

62-
void Component::ParseProgramMetadata(
62+
void ComponentV1::ParseProgramMetadata(
6363
const fidl::VectorPtr<fuchsia::sys::ProgramMetadata>& program_metadata,
6464
std::string* data_path,
6565
std::string* assets_path) {
@@ -80,21 +80,21 @@ void Component::ParseProgramMetadata(
8080
}
8181
}
8282

83-
ActiveComponent Component::Create(
83+
ActiveComponentV1 ComponentV1::Create(
8484
TerminationCallback termination_callback,
8585
fuchsia::sys::Package package,
8686
fuchsia::sys::StartupInfo startup_info,
8787
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
8888
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
8989
auto thread = std::make_unique<fml::Thread>();
90-
std::unique_ptr<Component> component;
90+
std::unique_ptr<ComponentV1> component;
9191

9292
fml::AutoResetWaitableEvent latch;
9393
thread->GetTaskRunner()->PostTask([&]() mutable {
94-
component.reset(new Component(std::move(termination_callback),
95-
std::move(package), std::move(startup_info),
96-
runner_incoming_services,
97-
std::move(controller)));
94+
component.reset(new ComponentV1(std::move(termination_callback),
95+
std::move(package), std::move(startup_info),
96+
runner_incoming_services,
97+
std::move(controller)));
9898
latch.Signal();
9999
});
100100

@@ -103,7 +103,7 @@ ActiveComponent Component::Create(
103103
.component = std::move(component)};
104104
}
105105

106-
Component::Component(
106+
ComponentV1::ComponentV1(
107107
TerminationCallback termination_callback,
108108
fuchsia::sys::Package package,
109109
fuchsia::sys::StartupInfo startup_info,
@@ -215,9 +215,9 @@ Component::Component(
215215
[this](zx_status_t status, std::unique_ptr<fuchsia::io::NodeInfo> info) {
216216
cloned_directory_ptr_.Unbind();
217217
if (status != ZX_OK) {
218-
FML_LOG(ERROR) << "could not bind out directory for flutter app("
219-
<< debug_label_
220-
<< "): " << zx_status_get_string(status);
218+
FML_LOG(ERROR)
219+
<< "could not bind out directory for flutter component("
220+
<< debug_label_ << "): " << zx_status_get_string(status);
221221
return;
222222
}
223223
const char* other_dirs[] = {"debug", "ctrl", "diagnostics"};
@@ -433,7 +433,7 @@ Component::Component(
433433
// happening on the UI thread. If the Component dtor and thread
434434
// termination happen (on the platform thread) between the previous
435435
// line and the next line, a crash will occur since we'll be posting
436-
// to a dead thread. See Runner::OnComponentTerminate() in
436+
// to a dead thread. See Runner::OnComponentV1Terminate() in
437437
// runner.cc.
438438
platform_task_runner->PostTask([weak, runner_incoming_services,
439439
component_url, error, stack_trace]() {
@@ -458,13 +458,13 @@ Component::Component(
458458
};
459459
}
460460

461-
Component::~Component() = default;
461+
ComponentV1::~ComponentV1() = default;
462462

463-
const std::string& Component::GetDebugLabel() const {
463+
const std::string& ComponentV1::GetDebugLabel() const {
464464
return debug_label_;
465465
}
466466

467-
void Component::Kill() {
467+
void ComponentV1::Kill() {
468468
component_controller_.events().OnTerminated(
469469
last_return_code_.second, fuchsia::sys::TerminationReason::EXITED);
470470

@@ -473,11 +473,11 @@ void Component::Kill() {
473473
// collected.
474474
}
475475

476-
void Component::Detach() {
476+
void ComponentV1::Detach() {
477477
component_controller_.set_error_handler(nullptr);
478478
}
479479

480-
void Component::OnEngineTerminate(const Engine* shell_holder) {
480+
void ComponentV1::OnEngineTerminate(const Engine* shell_holder) {
481481
auto found = std::find_if(shell_holders_.begin(), shell_holders_.end(),
482482
[shell_holder](const auto& holder) {
483483
return holder.get() == shell_holder;
@@ -504,7 +504,7 @@ void Component::OnEngineTerminate(const Engine* shell_holder) {
504504
}
505505
}
506506

507-
void Component::CreateView(
507+
void ComponentV1::CreateView(
508508
zx::eventpair token,
509509
fidl::InterfaceRequest<fuchsia::sys::ServiceProvider> /*incoming_services*/,
510510
fidl::InterfaceHandle<
@@ -514,7 +514,7 @@ void Component::CreateView(
514514
std::move(view_ref_pair.view_ref));
515515
}
516516

517-
void Component::CreateViewWithViewRef(
517+
void ComponentV1::CreateViewWithViewRef(
518518
zx::eventpair view_token,
519519
fuchsia::ui::views::ViewRefControl control_ref,
520520
fuchsia::ui::views::ViewRef view_ref) {
@@ -542,7 +542,7 @@ void Component::CreateViewWithViewRef(
542542
));
543543
}
544544

545-
void Component::CreateView2(fuchsia::ui::app::CreateView2Args view_args) {
545+
void ComponentV1::CreateView2(fuchsia::ui::app::CreateView2Args view_args) {
546546
if (!svc_) {
547547
FML_DLOG(ERROR)
548548
<< "Component incoming services was invalid when attempting to "
@@ -566,7 +566,7 @@ void Component::CreateView2(fuchsia::ui::app::CreateView2Args view_args) {
566566
}
567567

568568
#if !defined(DART_PRODUCT)
569-
void Component::WriteProfileToTrace() const {
569+
void ComponentV1::WriteProfileToTrace() const {
570570
for (const auto& engine : shell_holders_) {
571571
engine->WriteProfileToTrace();
572572
}

shell/platform/fuchsia/flutter/component.h renamed to shell/platform/fuchsia/flutter/component_v1.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_COMPONENT_H_
6-
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_COMPONENT_H_
5+
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_COMPONENT_V1_H_
6+
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_COMPONENT_V1_H_
77

88
#include <array>
99
#include <memory>
@@ -30,35 +30,35 @@
3030

3131
namespace flutter_runner {
3232

33-
class Component;
33+
class ComponentV1;
3434

35-
struct ActiveComponent {
35+
struct ActiveComponentV1 {
3636
std::unique_ptr<fml::Thread> platform_thread;
37-
std::unique_ptr<Component> component;
37+
std::unique_ptr<ComponentV1> component;
3838

39-
ActiveComponent& operator=(ActiveComponent&& other) noexcept {
39+
ActiveComponentV1& operator=(ActiveComponentV1&& other) noexcept {
4040
if (this != &other) {
4141
this->platform_thread.reset(other.platform_thread.release());
4242
this->component.reset(other.component.release());
4343
}
4444
return *this;
4545
}
4646

47-
~ActiveComponent() = default;
47+
~ActiveComponentV1() = default;
4848
};
4949

50-
// Represents an instance of a Flutter component that contains one of more
50+
// Represents an instance of a CF v1 Flutter component that contains one or more
5151
// Flutter engine instances.
52-
class Component final : public Engine::Delegate,
53-
public fuchsia::sys::ComponentController,
54-
public fuchsia::ui::app::ViewProvider {
52+
class ComponentV1 final : public Engine::Delegate,
53+
public fuchsia::sys::ComponentController,
54+
public fuchsia::ui::app::ViewProvider {
5555
public:
56-
using TerminationCallback = fit::function<void(const Component*)>;
56+
using TerminationCallback = fit::function<void(const ComponentV1*)>;
5757

5858
// Creates a dedicated thread to run the component and creates the
5959
// component on it. The component can be accessed only on this thread.
6060
// This is a synchronous operation.
61-
static ActiveComponent Create(
61+
static ActiveComponentV1 Create(
6262
TerminationCallback termination_callback,
6363
fuchsia::sys::Package package,
6464
fuchsia::sys::StartupInfo startup_info,
@@ -67,7 +67,7 @@ class Component final : public Engine::Delegate,
6767

6868
// Must be called on the same thread returned from the create call. The thread
6969
// may be collected after.
70-
~Component();
70+
~ComponentV1();
7171

7272
static void ParseProgramMetadata(
7373
const fidl::VectorPtr<fuchsia::sys::ProgramMetadata>& program_metadata,
@@ -101,9 +101,9 @@ class Component final : public Engine::Delegate,
101101
fml::RefPtr<flutter::DartSnapshot> isolate_snapshot_;
102102
std::set<std::unique_ptr<Engine>> shell_holders_;
103103
std::pair<bool, uint32_t> last_return_code_;
104-
fml::WeakPtrFactory<Component> weak_factory_;
104+
fml::WeakPtrFactory<ComponentV1> weak_factory_;
105105

106-
Component(
106+
ComponentV1(
107107
TerminationCallback termination_callback,
108108
fuchsia::sys::Package package,
109109
fuchsia::sys::StartupInfo startup_info,
@@ -134,9 +134,9 @@ class Component final : public Engine::Delegate,
134134
// |flutter::Engine::Delegate|
135135
void OnEngineTerminate(const Engine* holder) override;
136136

137-
FML_DISALLOW_COPY_AND_ASSIGN(Component);
137+
FML_DISALLOW_COPY_AND_ASSIGN(ComponentV1);
138138
};
139139

140140
} // namespace flutter_runner
141141

142-
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_COMPONENT_H_
142+
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_COMPONENT_V1_H_

shell/platform/fuchsia/flutter/component_unittest.cc renamed to shell/platform/fuchsia/flutter/component_v1_unittest.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "flutter/shell/platform/fuchsia/flutter/component.h"
5+
#include "component_v1.h"
66

77
#include <gtest/gtest.h>
88

99
namespace flutter_runner {
1010
namespace {
1111

12-
TEST(Component, ParseProgramMetadata) {
12+
TEST(ComponentV1, ParseProgramMetadata) {
1313
std::string data_path;
1414
std::string assets_path;
1515

1616
// The ProgramMetadata field may be null. We should parse this as if no
1717
// fields were specified.
18-
Component::ParseProgramMetadata(nullptr, &data_path, &assets_path);
18+
ComponentV1::ParseProgramMetadata(nullptr, &data_path, &assets_path);
1919

2020
EXPECT_EQ(data_path, "");
2121
EXPECT_EQ(assets_path, "");
2222

2323
// The ProgramMetadata field may be empty. Treat this the same as null.
2424
fidl::VectorPtr<fuchsia::sys::ProgramMetadata> program_metadata(size_t{0});
2525

26-
Component::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
26+
ComponentV1::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
2727

2828
EXPECT_EQ(data_path, "");
2929
EXPECT_EQ(assets_path, "");
3030

3131
// The assets_path defaults to the "data" value if unspecified
3232
program_metadata = {{"data", "foobar"}};
3333

34-
Component::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
34+
ComponentV1::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
3535

3636
EXPECT_EQ(data_path, "pkg/foobar");
3737
EXPECT_EQ(assets_path, "pkg/foobar");
@@ -41,7 +41,7 @@ TEST(Component, ParseProgramMetadata) {
4141

4242
program_metadata = {{"not_data", "foo"}, {"data", "bar"}, {"assets", "baz"}};
4343

44-
Component::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
44+
ComponentV1::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
4545

4646
EXPECT_EQ(data_path, "pkg/bar");
4747
EXPECT_EQ(assets_path, "pkg/baz");

0 commit comments

Comments
 (0)