Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
flutter_runner::ComponentV2 Class Referencefinal

#include <component_v2.h>

Inheritance diagram for flutter_runner::ComponentV2:
flutter_runner::Engine::Delegate

Public Types

using TerminationCallback = fit::function< void(const ComponentV2 *)>
 

Public Member Functions

 ~ComponentV2 ()
 
const std::string & GetDebugLabel () const
 
void WriteProfileToTrace () const
 

Static Public Member Functions

static ActiveComponentV2 Create (TerminationCallback termination_callback, fuchsia::component::runner::ComponentStartInfo start_info, std::shared_ptr< sys::ServiceDirectory > runner_incoming_services, fidl::InterfaceRequest< fuchsia::component::runner::ComponentController > controller)
 
static ProgramMetadata ParseProgramMetadata (const fuchsia::data::Dictionary &program_metadata)
 

Private Member Functions

void Kill () override
 
void Stop () override
 
void CreateView2 (fuchsia::ui::app::CreateView2Args view_args) override
 
void CreateViewWithViewRef (::zx::eventpair token, ::fuchsia::ui::views::ViewRefControl view_ref_control, ::fuchsia::ui::views::ViewRef view_ref) override
 
void OnEngineTerminate (const Engine *holder) override
 

Detailed Description

Definition at line 56 of file component_v2.h.

Member Typedef Documentation

◆ TerminationCallback

Definition at line 61 of file component_v2.h.

Constructor & Destructor Documentation

◆ ~ComponentV2()

flutter_runner::ComponentV2::~ComponentV2 ( )
default

Member Function Documentation

◆ Create()

ActiveComponentV2 flutter_runner::ComponentV2::Create ( TerminationCallback  termination_callback,
fuchsia::component::runner::ComponentStartInfo  start_info,
std::shared_ptr< sys::ServiceDirectory >  runner_incoming_services,
fidl::InterfaceRequest< fuchsia::component::runner::ComponentController >  controller 
)
static

Definition at line 128 of file component_v2.cc.

133 {
134 auto thread = std::make_unique<fml::Thread>();
135 std::unique_ptr<ComponentV2> component;
136
138 thread->GetTaskRunner()->PostTask([&]() mutable {
139 component.reset(
140 new ComponentV2(std::move(termination_callback), std::move(start_info),
141 runner_incoming_services, std::move(controller)));
142 latch.Signal();
143 });
144
145 latch.Wait();
146 return {.platform_thread = std::move(thread),
147 .component = std::move(component)};
148}

◆ CreateView2()

void flutter_runner::ComponentV2::CreateView2 ( fuchsia::ui::app::CreateView2Args  view_args)
overrideprivate

Definition at line 620 of file component_v2.cc.

620 {
621 if (!svc_) {
623 << "Component incoming services was invalid when attempting to "
624 "create a shell for a view provider request.";
625 return;
626 }
627
628 fuchsia::ui::views::ViewRefControl view_ref_control;
629 fuchsia::ui::views::ViewRef view_ref;
630 auto status = zx::eventpair::create(
631 /*options*/ 0u, &view_ref_control.reference, &view_ref.reference);
632 ZX_ASSERT(status == ZX_OK);
633 view_ref_control.reference.replace(
634 ZX_DEFAULT_EVENTPAIR_RIGHTS & (~ZX_RIGHT_DUPLICATE),
635 &view_ref_control.reference);
636 view_ref.reference.replace(ZX_RIGHTS_BASIC, &view_ref.reference);
637 auto view_ref_pair =
638 std::make_pair(std::move(view_ref_control), std::move(view_ref));
639
640 shell_holders_.emplace(std::make_unique<Engine>(
641 *this, // delegate
642 debug_label_, // thread label
643 svc_, // Component incoming services
644 runner_incoming_services_, // Runner incoming services
645 settings_, // settings
646 std::move(
647 *view_args.mutable_view_creation_token()), // view creation token
648 std::move(view_ref_pair), // view ref pair
649 std::move(fdio_ns_), // FDIO namespace
650 std::move(directory_request_), // outgoing request
651 product_config_, // product configuration
652 std::vector<std::string>() // dart entrypoint args
653 ));
654}
#define FML_LOG(severity)
Definition logging.h:82
#define ERROR(message)

◆ CreateViewWithViewRef()

void flutter_runner::ComponentV2::CreateViewWithViewRef ( ::zx::eventpair  token,
::fuchsia::ui::views::ViewRefControl  view_ref_control,
::fuchsia::ui::views::ViewRef  view_ref 
)
inlineoverrideprivate

Definition at line 114 of file component_v2.h.

117 {}

◆ GetDebugLabel()

const std::string & flutter_runner::ComponentV2::GetDebugLabel ( ) const

Definition at line 535 of file component_v2.cc.

535 {
536 return debug_label_;
537}

◆ Kill()

void flutter_runner::ComponentV2::Kill ( )
overrideprivate

Definition at line 539 of file component_v2.cc.

539 {
540 FML_VLOG(1) << "received Kill event";
541
542 // From the documentation for ComponentController, ZX_OK should be sent when
543 // the ComponentController receives a termination request. However, if the
544 // component exited with a non-zero return code, we indicate this by sending
545 // an INTERNAL epitaph instead.
546 //
547 // TODO(fxb/86666): Communicate return code from the ComponentController once
548 // v2 has support.
549 auto [got_return_code, return_code] = last_return_code_;
550 if (got_return_code && return_code == 0) {
551 KillWithEpitaph(ZX_OK);
552 } else {
553 if (got_return_code) {
554 FML_LOG(ERROR) << "Component exited with non-zero return code: "
555 << return_code;
556 } else {
557 FML_LOG(ERROR) << "Failed to get return code for component";
558 }
559
560 KillWithEpitaph(zx_status_t(fuchsia::component::Error::INTERNAL));
561 }
562
563 // WARNING: Don't do anything past this point as this instance may have been
564 // collected.
565}
#define FML_VLOG(verbose_level)
Definition logging.h:98

◆ OnEngineTerminate()

void flutter_runner::ComponentV2::OnEngineTerminate ( const Engine holder)
overrideprivatevirtual

Implements flutter_runner::Engine::Delegate.

Definition at line 584 of file component_v2.cc.

584 {
585 auto found = std::find_if(shell_holders_.begin(), shell_holders_.end(),
586 [shell_holder](const auto& holder) {
587 return holder.get() == shell_holder;
588 });
589
590 if (found == shell_holders_.end()) {
591 // This indicates a deeper issue with memory management and should never
592 // happen.
593 FML_LOG(ERROR) << "Tried to terminate an unregistered shell holder.";
594 FML_DCHECK(false);
595
596 return;
597 }
598
599 // We may launch multiple shells in this component. However, we will
600 // terminate when the last shell goes away. The error code returned to the
601 // component controller will be the last isolate that had an error.
602 auto return_code = shell_holder->GetEngineReturnCode();
603 if (return_code.has_value()) {
604 last_return_code_ = {true, return_code.value()};
605 } else {
606 FML_LOG(ERROR) << "Failed to get return code from terminated shell holder.";
607 }
608
609 shell_holders_.erase(found);
610
611 if (shell_holders_.empty()) {
612 FML_VLOG(1) << "Killing component because all shell holders have been "
613 "terminated.";
614 Kill();
615 // WARNING: Don't do anything past this point because the delegate may have
616 // collected this instance via the termination callback.
617 }
618}
#define FML_DCHECK(condition)
Definition logging.h:103

◆ ParseProgramMetadata()

ProgramMetadata flutter_runner::ComponentV2::ParseProgramMetadata ( const fuchsia::data::Dictionary &  program_metadata)
static

Parses the program metadata that was provided for the component.

|old_gen_heap_size| will be set to -1 if no value was specified.

Definition at line 106 of file component_v2.cc.

107 {
108 ProgramMetadata result;
109
110 for (const auto& entry : program_metadata.entries()) {
111 if (entry.key.compare(kDataKey) == 0 && entry.value != nullptr) {
112 result.data_path = "pkg/" + entry.value->str();
113 } else if (entry.key.compare(kAssetsKey) == 0 && entry.value != nullptr) {
114 result.assets_path = "pkg/" + entry.value->str();
115 } else if (entry.key.compare(kArgsKey) == 0 && entry.value != nullptr) {
116 ParseArgs(entry.value->str_vec(), &result);
117 }
118 }
119
120 // assets_path defaults to the same as data_path if omitted.
121 if (result.assets_path.empty()) {
122 result.assets_path = result.data_path;
123 }
124
125 return result;
126}
static constexpr char kArgsKey[]
GAsyncResult * result
ParseArgs(args)
Definition copy_tree.py:14

◆ Stop()

void flutter_runner::ComponentV2::Stop ( )
overrideprivate

Definition at line 576 of file component_v2.cc.

576 {
577 FML_VLOG(1) << "received Stop event";
578
579 // TODO(fxb/89162): Any other cleanup logic we should do that's appropriate
580 // for Stop but not for Kill?
581 KillWithEpitaph(ZX_OK);
582}

◆ WriteProfileToTrace()

void flutter_runner::ComponentV2::WriteProfileToTrace ( ) const

Definition at line 657 of file component_v2.cc.

657 {
658 for (const auto& engine : shell_holders_) {
659 engine->WriteProfileToTrace();
660 }
661}
FlutterEngine engine
Definition main.cc:68

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