Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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 ()
 
void handle_unknown_method (uint64_t ordinal, bool method_has_response) override
 

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 98 of file dart_component_controller.cc.

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

References FML_LOG.

◆ ~DartComponentController()

dart_runner::DartComponentController::~DartComponentController ( )
override

Definition at line 135 of file dart_component_controller.cc.

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

Member Function Documentation

◆ handle_unknown_method()

void dart_runner::DartComponentController::handle_unknown_method ( uint64_t  ordinal,
bool  method_has_response 
)
override

Definition at line 635 of file dart_component_controller.cc.

636 {
637 FML_LOG(ERROR) << "Unknown method called on DartComponentController. "
638 "Ordinal: "
639 << ordinal;
640}

References FML_LOG.

◆ 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 423 of file dart_component_controller.cc.

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

◆ SetUp()

bool dart_runner::DartComponentController::SetUp ( )

Sets up the controller.

This should be called before |Run|.

Definition at line 144 of file dart_component_controller.cc.

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

References FML_LOG.


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