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_RUNTIME_DART_ISOLATE_GROUP_DATA_H_ |
6 | #define FLUTTER_RUNTIME_DART_ISOLATE_GROUP_DATA_H_ |
7 | |
8 | #include <mutex> |
9 | #include <string> |
10 | |
11 | #include "flutter/common/settings.h" |
12 | #include "flutter/fml/closure.h" |
13 | #include "flutter/fml/memory/ref_ptr.h" |
14 | |
15 | namespace flutter { |
16 | |
17 | class DartIsolate; |
18 | class DartSnapshot; |
19 | |
20 | using ChildIsolatePreparer = std::function<bool(DartIsolate*)>; |
21 | |
22 | // Object holding state associated with a Dart isolate group. An instance of |
23 | // this class will be provided to Dart_CreateIsolateGroup as the |
24 | // isolate_group_data. |
25 | // |
26 | // This object must be thread safe because the Dart VM can invoke the isolate |
27 | // group cleanup callback on any thread. |
28 | class DartIsolateGroupData { |
29 | public: |
30 | DartIsolateGroupData(const Settings& settings, |
31 | fml::RefPtr<const DartSnapshot> isolate_snapshot, |
32 | std::string advisory_script_uri, |
33 | std::string advisory_script_entrypoint, |
34 | const ChildIsolatePreparer& child_isolate_preparer, |
35 | const fml::closure& isolate_create_callback, |
36 | const fml::closure& isolate_shutdown_callback); |
37 | |
38 | ~DartIsolateGroupData(); |
39 | |
40 | const Settings& GetSettings() const; |
41 | |
42 | fml::RefPtr<const DartSnapshot> GetIsolateSnapshot() const; |
43 | |
44 | const std::string& GetAdvisoryScriptURI() const; |
45 | |
46 | const std::string& GetAdvisoryScriptEntrypoint() const; |
47 | |
48 | ChildIsolatePreparer GetChildIsolatePreparer() const; |
49 | |
50 | const fml::closure& GetIsolateCreateCallback() const; |
51 | |
52 | const fml::closure& GetIsolateShutdownCallback() const; |
53 | |
54 | void SetChildIsolatePreparer(const ChildIsolatePreparer& value); |
55 | |
56 | private: |
57 | const Settings settings_; |
58 | const fml::RefPtr<const DartSnapshot> isolate_snapshot_; |
59 | const std::string advisory_script_uri_; |
60 | const std::string advisory_script_entrypoint_; |
61 | mutable std::mutex child_isolate_preparer_mutex_; |
62 | ChildIsolatePreparer child_isolate_preparer_; |
63 | const fml::closure isolate_create_callback_; |
64 | const fml::closure isolate_shutdown_callback_; |
65 | |
66 | FML_DISALLOW_COPY_AND_ASSIGN(DartIsolateGroupData); |
67 | }; |
68 | |
69 | } // namespace flutter |
70 | |
71 | #endif // FLUTTER_RUNTIME_DART_ISOLATE_GROUP_DATA_H_ |
72 | |