Flutter Engine
The Flutter Engine
runner.h
Go to the documentation of this file.
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_FLUTTER_RUNNER_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_RUNNER_H_
7
8#include <memory>
9#include <unordered_map>
10
11#include <fuchsia/component/runner/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_v2.h"
18#include "flutter/fml/macros.h"
19#include "fml/memory/ref_ptr.h"
20#include "fml/task_runner.h"
21#include "lib/fidl/cpp/binding_set.h"
23
24namespace flutter_runner {
25
26/// Publishes the CF v2 runner service.
27///
28/// Each component will be run on a separate thread dedicated to that component.
29///
30/// TODO(fxb/50694): Add unit tests for CF v2.
31class Runner final
32 : public fuchsia::component::runner::ComponentRunner /* CF v2 */ {
33 public:
34 // Does not take ownership of context.
36 sys::ComponentContext* context);
37
38 ~Runner();
39
40 private:
41 // CF v2 lifecycle methods.
42
43 // |fuchsia::component::runner::ComponentRunner|
44 void Start(
45 fuchsia::component::runner::ComponentStartInfo start_info,
46 fidl::InterfaceRequest<fuchsia::component::runner::ComponentController>
47 controller) override;
48
49 /// Registers a new CF v2 component with this runner, binding the component
50 /// to this runner.
51 void RegisterComponentV2(
52 fidl::InterfaceRequest<fuchsia::component::runner::ComponentRunner>
53 request);
54
55 /// Callback that should be fired when a registered CF v2 component is
56 /// terminated.
57 void OnComponentV2Terminate(const ComponentV2* component);
58
59 void SetupICU();
60
61#if !defined(DART_PRODUCT)
62 void SetupTraceObserver();
63#endif // !defined(DART_PRODUCT)
64
65 // Called from SetupICU, for testing only. Returns false on error.
66 static bool SetupICUInternal();
67 // Called from SetupICU, for testing only. Returns false on error.
68 static bool SetupTZDataInternal();
69#if defined(FRIEND_TEST)
70 FRIEND_TEST(RunnerTZDataTest, LoadsWithTZDataPresent);
71 FRIEND_TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent);
72#endif // defined(FRIEND_TEST)
73
75
76 sys::ComponentContext* context_;
77
78 // CF v2 component state.
79
80 /// The components that are currently bound to this runner.
81 fidl::BindingSet<fuchsia::component::runner::ComponentRunner>
82 active_components_v2_bindings_;
83
84 /// The components that are currently actively running on threads.
85 std::unordered_map<const ComponentV2*, ActiveComponentV2>
86 active_components_v2_;
87
88#if !defined(DART_PRODUCT)
89 // The connection between the Dart VM service and The Hub.
90 std::unique_ptr<dart_utils::VMServiceObject> vmservice_object_;
91
92 std::unique_ptr<trace::TraceObserver> trace_observer_;
93 trace_prolonged_context_t* prolonged_context_;
94#endif // !defined(DART_PRODUCT)
95
96 FML_DISALLOW_COPY_AND_ASSIGN(Runner);
97};
98
99} // namespace flutter_runner
100
101#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_RUNNER_H_
Runner(fml::RefPtr< fml::TaskRunner > task_runner, sys::ComponentContext *context)
Definition: runner.cc:153
sys::ComponentContext * ComponentContext()