1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNNER_H_ 6 #define FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNNER_H_ 7 8 #include <memory> 9 #include <unordered_map> 10 11 #include <fuchsia/sys/cpp/fidl.h> 12 #include <lib/async-loop/cpp/loop.h> 13 #include <lib/sys/cpp/component_context.h> 14 #include <lib/trace-engine/instrumentation.h> 15 #include <lib/trace/observer.h> 16 17 #include "component.h" 18 #include "flutter/fml/macros.h" 19 #include "lib/fidl/cpp/binding_set.h" 20 #include "runner_context.h" 21 #include "runtime/dart/utils/vmservice_object.h" 22 #include "thread.h" 23 24 namespace flutter_runner { 25 26 // Publishes the |fuchsia::sys::Runner| service and runs applications on 27 // their own threads. 28 class Runner final : public fuchsia::sys::Runner { 29 public: 30 explicit Runner(async::Loop* loop); 31 32 ~Runner(); 33 34 private: 35 async::Loop* loop_; 36 37 struct ActiveApplication { 38 std::unique_ptr<Thread> thread; 39 std::unique_ptr<Application> application; 40 ActiveApplicationActiveApplication41 ActiveApplication( 42 std::pair<std::unique_ptr<Thread>, std::unique_ptr<Application>> pair) 43 : thread(std::move(pair.first)), application(std::move(pair.second)) {} 44 45 ActiveApplication() = default; 46 }; 47 48 std::unique_ptr<RunnerContext> runner_context_; 49 fidl::BindingSet<fuchsia::sys::Runner> active_applications_bindings_; 50 std::unordered_map<const Application*, ActiveApplication> 51 active_applications_; 52 53 #if !defined(DART_PRODUCT) 54 // The connection between the Dart VM service and The Hub. 55 std::unique_ptr<dart_utils::VMServiceObject> vmservice_object_; 56 57 std::unique_ptr<trace::TraceObserver> trace_observer_; 58 trace_prolonged_context_t* prolonged_context_; 59 #endif // !defined(DART_PRODUCT) 60 61 // |fuchsia::sys::Runner| 62 void StartComponent(fuchsia::sys::Package package, 63 fuchsia::sys::StartupInfo startup_info, 64 fidl::InterfaceRequest<fuchsia::sys::ComponentController> 65 controller) override; 66 67 void RegisterApplication( 68 fidl::InterfaceRequest<fuchsia::sys::Runner> request); 69 70 void UnregisterApplication(const Application* application); 71 72 void OnApplicationTerminate(const Application* application); 73 74 void SetupICU(); 75 76 #if !defined(DART_PRODUCT) 77 void SetupTraceObserver(); 78 #endif // !defined(DART_PRODUCT) 79 80 FML_DISALLOW_COPY_AND_ASSIGN(Runner); 81 }; 82 83 } // namespace flutter_runner 84 85 #endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_RUNNER_H_ 86