[flutter_runner] Refactor thread_application pair to ActiveApplication (flutter/engine#12573)

This commit is contained in:
Kaushik Iska 2019-09-27 13:38:25 -07:00 committed by GitHub
parent c24109d884
commit ba2cd2fbed
4 changed files with 28 additions and 25 deletions

View File

@ -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,
@ -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) {

View File

@ -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,
@ -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.

View File

@ -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) {

View File

@ -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> 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>