Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart_runner::DartComponentController Class Reference

Starts a Dart component written in CFv2. More...

#include <dart_component_controller.h>

Inheritance diagram for dart_runner::DartComponentController:

Public Member Functions

 DartComponentController (fuchsia::component::runner::ComponentStartInfo start_info, std::shared_ptr< sys::ServiceDirectory > runner_incoming_services, fidl::InterfaceRequest< fuchsia::component::runner::ComponentController > controller)
 
 ~DartComponentController () override
 
bool SetUp ()
 
void Run ()
 

Detailed Description

Starts a Dart component written in CFv2.

Definition at line 29 of file dart_component_controller.h.

Constructor & Destructor Documentation

◆ DartComponentController()

dart_runner::DartComponentController::DartComponentController ( fuchsia::component::runner::ComponentStartInfo  start_info,
std::shared_ptr< sys::ServiceDirectory >  runner_incoming_services,
fidl::InterfaceRequest< fuchsia::component::runner::ComponentController >  controller 
)

Definition at line 100 of file dart_component_controller.cc.

105 : loop_(new async::Loop(&kLoopConfig)),
106 label_(GetLabelFromUrl(start_info.resolved_url())),
107 url_(start_info.resolved_url()),
108 runner_incoming_services_(std::move(runner_incoming_services)),
109 dart_outgoing_dir_(new vfs::PseudoDir()),
110 start_info_(std::move(start_info)),
111 binding_(this, std::move(controller)) {
112 binding_.set_error_handler([this](zx_status_t status) { Kill(); });
113
114 // TODO(fxb/84537): This data path is configured based how we build Flutter
115 // applications in tree currently, but the way we build the Flutter
116 // application may change. We should avoid assuming the data path and let the
117 // CML file specify this data path instead.
118 const std::string component_name = GetComponentNameFromUrl(url_);
119 data_path_ = "pkg/data/" + component_name;
120
121 zx_status_t idle_timer_status =
122 zx::timer::create(ZX_TIMER_SLACK_LATE, ZX_CLOCK_MONOTONIC, &idle_timer_);
123 if (idle_timer_status != ZX_OK) {
124 FML_LOG(INFO) << "Idle timer creation failed: "
125 << zx_status_get_string(idle_timer_status);
126 } else {
127 idle_wait_.set_object(idle_timer_.get());
128 idle_wait_.set_trigger(ZX_TIMER_SIGNALED);
129 idle_wait_.Begin(async_get_default_dispatcher());
130 }
131
132 // Close the runtime_dir channel if we don't intend to serve it. Otherwise any
133 // access to the runtime_dir will hang forever.
134 start_info_.clear_runtime_dir();
135}
#define FML_LOG(severity)
Definition: logging.h:82
int_closure create

◆ ~DartComponentController()

dart_runner::DartComponentController::~DartComponentController ( )
override

Definition at line 137 of file dart_component_controller.cc.

137 {
138 if (namespace_) {
139 fdio_ns_destroy(namespace_);
140 namespace_ = nullptr;
141 }
142 close(stdout_fd_);
143 close(stderr_fd_);
144}

Member Function Documentation

◆ Run()

void dart_runner::DartComponentController::Run ( )

Runs the Dart component in a task, sending the return code back to the Fuchsia component controller.

This should be called after |SetUp|.

Definition at line 428 of file dart_component_controller.cc.

428 {
429 async::PostTask(loop_->dispatcher(), [loop = loop_.get(), app = this] {
430 if (!app->RunDartMain()) {
431 loop->Quit();
432 }
433 });
434 loop_->Run();
435
436 if (binding_.is_bound()) {
437 // From the documentation for ComponentController, ZX_OK should be sent when
438 // the ComponentController receives a termination request. However, if the
439 // component exited with a non-zero return code, we indicate this by sending
440 // an INTERNAL epitaph instead.
441 //
442 // TODO(fxb/86666): Communicate return code from the ComponentController
443 // once v2 has support.
444 if (return_code_ == 0) {
445 binding_.Close(ZX_OK);
446 } else {
447 FML_LOG(ERROR) << "Component exited with non-zero return code: "
448 << return_code_;
449 binding_.Close(zx_status_t(fuchsia::component::Error::INTERNAL));
450 }
451 }
452}
#define ERROR(message)
Definition: elf_loader.cc:260

◆ SetUp()

bool dart_runner::DartComponentController::SetUp ( )

Sets up the controller.

This should be called before |Run|.

Definition at line 146 of file dart_component_controller.cc.

146 {
147 // Name the thread after the url of the component being launched.
148 zx::thread::self()->set_property(ZX_PROP_NAME, label_.c_str(), label_.size());
149 Dart_SetThreadName(label_.c_str());
150
151 if (!CreateAndBindNamespace()) {
152 return false;
153 }
154
155 if (SetUpFromAppSnapshot()) {
156 FML_LOG(INFO) << url_ << " is running from an app snapshot";
157 } else if (SetUpFromKernel()) {
158 FML_LOG(INFO) << url_ << " is running from kernel";
159 } else {
160 FML_LOG(ERROR) << "Failed to set up component controller for " << url_;
161 return false;
162 }
163
164 return true;
165}
DART_EXPORT void Dart_SetThreadName(const char *name)

The documentation for this class was generated from the following files: