[flutter_runner] Refactor thread_application pair to ActiveApplication (flutter/engine#12573)
This commit is contained in:
@@ -38,8 +38,7 @@ constexpr char kDataKey[] = "data";
|
|||||||
constexpr char kTmpPath[] = "/tmp";
|
constexpr char kTmpPath[] = "/tmp";
|
||||||
constexpr char kServiceRootPath[] = "/svc";
|
constexpr char kServiceRootPath[] = "/svc";
|
||||||
|
|
||||||
std::pair<std::unique_ptr<Thread>, std::unique_ptr<Application>>
|
ActiveApplication Application::Create(
|
||||||
Application::Create(
|
|
||||||
TerminationCallback termination_callback,
|
TerminationCallback termination_callback,
|
||||||
fuchsia::sys::Package package,
|
fuchsia::sys::Package package,
|
||||||
fuchsia::sys::StartupInfo startup_info,
|
fuchsia::sys::StartupInfo startup_info,
|
||||||
@@ -58,7 +57,7 @@ Application::Create(
|
|||||||
});
|
});
|
||||||
|
|
||||||
latch.Wait();
|
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) {
|
static std::string DebugLabelForURL(const std::string& url) {
|
||||||
|
|||||||
@@ -30,6 +30,23 @@
|
|||||||
|
|
||||||
namespace flutter_runner {
|
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
|
// Represents an instance of a Flutter application that contains one of more
|
||||||
// Flutter engine instances.
|
// Flutter engine instances.
|
||||||
class Application final : public Engine::Delegate,
|
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
|
// Creates a dedicated thread to run the application and constructions the
|
||||||
// application on it. The application can be accessed only on this thread.
|
// application on it. The application can be accessed only on this thread.
|
||||||
// This is a synchronous operation.
|
// This is a synchronous operation.
|
||||||
static std::pair<std::unique_ptr<Thread>, std::unique_ptr<Application>>
|
static ActiveApplication Create(
|
||||||
Create(TerminationCallback termination_callback,
|
TerminationCallback termination_callback,
|
||||||
fuchsia::sys::Package package,
|
fuchsia::sys::Package package,
|
||||||
fuchsia::sys::StartupInfo startup_info,
|
fuchsia::sys::StartupInfo startup_info,
|
||||||
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
|
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
|
||||||
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller);
|
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller);
|
||||||
|
|
||||||
// Must be called on the same thread returned from the create call. The thread
|
// Must be called on the same thread returned from the create call. The thread
|
||||||
// may be collected after.
|
// may be collected after.
|
||||||
|
|||||||
@@ -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(termination_callback), // termination callback
|
||||||
std::move(package), // application package
|
std::move(package), // application package
|
||||||
std::move(startup_info), // startup info
|
std::move(startup_info), // startup info
|
||||||
@@ -186,9 +186,8 @@ void Runner::StartComponent(
|
|||||||
std::move(controller) // controller request
|
std::move(controller) // controller request
|
||||||
);
|
);
|
||||||
|
|
||||||
auto key = thread_application_pair.second.get();
|
auto key = active_application.application.get();
|
||||||
|
active_applications_[key] = std::move(active_application);
|
||||||
active_applications_[key] = std::move(thread_application_pair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner::OnApplicationTerminate(const Application* application) {
|
void Runner::OnApplicationTerminate(const Application* application) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include "flutter/fml/macros.h"
|
#include "flutter/fml/macros.h"
|
||||||
#include "lib/fidl/cpp/binding_set.h"
|
#include "lib/fidl/cpp/binding_set.h"
|
||||||
#include "runtime/dart/utils/vmservice_object.h"
|
#include "runtime/dart/utils/vmservice_object.h"
|
||||||
#include "thread.h"
|
|
||||||
|
|
||||||
namespace flutter_runner {
|
namespace flutter_runner {
|
||||||
|
|
||||||
@@ -33,17 +32,6 @@ class Runner final : public fuchsia::sys::Runner {
|
|||||||
private:
|
private:
|
||||||
async::Loop* loop_;
|
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_;
|
std::unique_ptr<sys::ComponentContext> context_;
|
||||||
fidl::BindingSet<fuchsia::sys::Runner> active_applications_bindings_;
|
fidl::BindingSet<fuchsia::sys::Runner> active_applications_bindings_;
|
||||||
std::unordered_map<const Application*, ActiveApplication>
|
std::unordered_map<const Application*, ActiveApplication>
|
||||||
|
|||||||
Reference in New Issue
Block a user