Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions shell/platform/fuchsia/flutter/component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ constexpr char kDataKey[] = "data";
constexpr char kTmpPath[] = "/tmp";
constexpr char kServiceRootPath[] = "/svc";

std::pair<std::unique_ptr<Thread>, std::unique_ptr<Application>>
Application::Create(
ActiveApplication Application::Create(
TerminationCallback termination_callback,
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
Expand All @@ -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) {
Expand Down
29 changes: 23 additions & 6 deletions shell/platform/fuchsia/flutter/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@

namespace flutter_runner {

class Application;

struct ActiveApplication {
std::unique_ptr<Thread> thread;
std::unique_ptr<Application> 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,
Expand All @@ -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<Thread>, std::unique_ptr<Application>>
Create(TerminationCallback termination_callback,
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller);
static ActiveApplication Create(
TerminationCallback termination_callback,
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller);

// Must be called on the same thread returned from the create call. The thread
// may be collected after.
Expand Down
7 changes: 3 additions & 4 deletions shell/platform/fuchsia/flutter/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,16 @@ 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
context_->svc(), // runner incoming services
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) {
Expand Down
12 changes: 0 additions & 12 deletions shell/platform/fuchsia/flutter/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -33,17 +32,6 @@ class Runner final : public fuchsia::sys::Runner {
private:
async::Loop* loop_;

struct ActiveApplication {
std::unique_ptr<Thread> thread;
std::unique_ptr<Application> application;

ActiveApplication(
std::pair<std::unique_ptr<Thread>, std::unique_ptr<Application>> pair)
: thread(std::move(pair.first)), application(std::move(pair.second)) {}

ActiveApplication() = default;
};

std::unique_ptr<sys::ComponentContext> context_;
fidl::BindingSet<fuchsia::sys::Runner> active_applications_bindings_;
std::unordered_map<const Application*, ActiveApplication>
Expand Down