diff --git a/shell/platform/fuchsia/flutter/component.cc b/shell/platform/fuchsia/flutter/component.cc index 2b0b4fffd4e87..4310a8b58df46 100644 --- a/shell/platform/fuchsia/flutter/component.cc +++ b/shell/platform/fuchsia/flutter/component.cc @@ -38,8 +38,7 @@ constexpr char kDataKey[] = "data"; constexpr char kTmpPath[] = "/tmp"; constexpr char kServiceRootPath[] = "/svc"; -std::pair, std::unique_ptr> -Application::Create( +ActiveApplication Application::Create( TerminationCallback termination_callback, fuchsia::sys::Package package, fuchsia::sys::StartupInfo startup_info, @@ -58,7 +57,7 @@ Application::Create( }); latch.Wait(); - return {std::move(thread), std::move(application)}; + return {.thread = std::move(thread), .application = std::move(application)}; } static std::string DebugLabelForURL(const std::string& url) { diff --git a/shell/platform/fuchsia/flutter/component.h b/shell/platform/fuchsia/flutter/component.h index 55f136b486a7b..b852d3dd6bcd2 100644 --- a/shell/platform/fuchsia/flutter/component.h +++ b/shell/platform/fuchsia/flutter/component.h @@ -30,6 +30,23 @@ namespace flutter_runner { +class Application; + +struct ActiveApplication { + std::unique_ptr thread; + std::unique_ptr application; + + ActiveApplication& operator=(ActiveApplication&& other) noexcept { + if (this != &other) { + this->thread.reset(other.thread.release()); + this->application.reset(other.application.release()); + } + return *this; + } + + ~ActiveApplication() = default; +}; + // Represents an instance of a Flutter application that contains one of more // Flutter engine instances. class Application final : public Engine::Delegate, @@ -41,12 +58,12 @@ class Application final : public Engine::Delegate, // Creates a dedicated thread to run the application and constructions the // application on it. The application can be accessed only on this thread. // This is a synchronous operation. - static std::pair, std::unique_ptr> - Create(TerminationCallback termination_callback, - fuchsia::sys::Package package, - fuchsia::sys::StartupInfo startup_info, - std::shared_ptr runner_incoming_services, - fidl::InterfaceRequest controller); + static ActiveApplication Create( + TerminationCallback termination_callback, + fuchsia::sys::Package package, + fuchsia::sys::StartupInfo startup_info, + std::shared_ptr runner_incoming_services, + fidl::InterfaceRequest controller); // Must be called on the same thread returned from the create call. The thread // may be collected after. diff --git a/shell/platform/fuchsia/flutter/runner.cc b/shell/platform/fuchsia/flutter/runner.cc index 762eddfd4d611..876645b1b1d82 100644 --- a/shell/platform/fuchsia/flutter/runner.cc +++ b/shell/platform/fuchsia/flutter/runner.cc @@ -178,7 +178,7 @@ void Runner::StartComponent( }); }; - auto thread_application_pair = Application::Create( + auto active_application = Application::Create( std::move(termination_callback), // termination callback std::move(package), // application package std::move(startup_info), // startup info @@ -186,9 +186,8 @@ void Runner::StartComponent( std::move(controller) // controller request ); - auto key = thread_application_pair.second.get(); - - active_applications_[key] = std::move(thread_application_pair); + auto key = active_application.application.get(); + active_applications_[key] = std::move(active_application); } void Runner::OnApplicationTerminate(const Application* application) { diff --git a/shell/platform/fuchsia/flutter/runner.h b/shell/platform/fuchsia/flutter/runner.h index 047678c9ce307..ca4cb70d3e530 100644 --- a/shell/platform/fuchsia/flutter/runner.h +++ b/shell/platform/fuchsia/flutter/runner.h @@ -18,7 +18,6 @@ #include "flutter/fml/macros.h" #include "lib/fidl/cpp/binding_set.h" #include "runtime/dart/utils/vmservice_object.h" -#include "thread.h" namespace flutter_runner { @@ -33,17 +32,6 @@ class Runner final : public fuchsia::sys::Runner { private: async::Loop* loop_; - struct ActiveApplication { - std::unique_ptr thread; - std::unique_ptr application; - - ActiveApplication( - std::pair, std::unique_ptr> pair) - : thread(std::move(pair.first)), application(std::move(pair.second)) {} - - ActiveApplication() = default; - }; - std::unique_ptr context_; fidl::BindingSet active_applications_bindings_; std::unordered_map