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 #include "flutter/runtime/dart_vm_data.h"
6
7 namespace flutter {
8
Create(Settings settings,fml::RefPtr<DartSnapshot> vm_snapshot,fml::RefPtr<DartSnapshot> isolate_snapshot,fml::RefPtr<DartSnapshot> shared_snapshot)9 std::shared_ptr<const DartVMData> DartVMData::Create(
10 Settings settings,
11 fml::RefPtr<DartSnapshot> vm_snapshot,
12 fml::RefPtr<DartSnapshot> isolate_snapshot,
13 fml::RefPtr<DartSnapshot> shared_snapshot) {
14 if (!vm_snapshot || !vm_snapshot->IsValid()) {
15 // Caller did not provide a valid VM snapshot. Attempt to infer one
16 // from the settings.
17 vm_snapshot = DartSnapshot::VMSnapshotFromSettings(settings);
18 if (!vm_snapshot) {
19 FML_LOG(ERROR)
20 << "VM snapshot invalid and could not be inferred from settings.";
21 return {};
22 }
23 }
24
25 if (!isolate_snapshot || !isolate_snapshot->IsValid()) {
26 // Caller did not provide a valid isolate snapshot. Attempt to infer one
27 // from the settings.
28 isolate_snapshot = DartSnapshot::IsolateSnapshotFromSettings(settings);
29 if (!isolate_snapshot) {
30 FML_LOG(ERROR) << "Isolate snapshot invalid and could not be inferred "
31 "from settings.";
32 return {};
33 }
34 }
35
36 if (!shared_snapshot || !shared_snapshot->IsValid()) {
37 shared_snapshot = DartSnapshot::Empty();
38 if (!shared_snapshot) {
39 FML_LOG(ERROR) << "Shared snapshot invalid.";
40 return {};
41 }
42 }
43
44 return std::shared_ptr<const DartVMData>(new DartVMData(
45 std::move(settings), //
46 std::move(vm_snapshot), //
47 std::move(isolate_snapshot), //
48 std::move(shared_snapshot) //
49 ));
50 }
51
DartVMData(Settings settings,fml::RefPtr<const DartSnapshot> vm_snapshot,fml::RefPtr<const DartSnapshot> isolate_snapshot,fml::RefPtr<const DartSnapshot> shared_snapshot)52 DartVMData::DartVMData(Settings settings,
53 fml::RefPtr<const DartSnapshot> vm_snapshot,
54 fml::RefPtr<const DartSnapshot> isolate_snapshot,
55 fml::RefPtr<const DartSnapshot> shared_snapshot)
56 : settings_(settings),
57 vm_snapshot_(vm_snapshot),
58 isolate_snapshot_(isolate_snapshot),
59 shared_snapshot_(shared_snapshot) {}
60
61 DartVMData::~DartVMData() = default;
62
GetSettings() const63 const Settings& DartVMData::GetSettings() const {
64 return settings_;
65 }
66
GetVMSnapshot() const67 const DartSnapshot& DartVMData::GetVMSnapshot() const {
68 return *vm_snapshot_;
69 }
70
GetIsolateSnapshot() const71 fml::RefPtr<const DartSnapshot> DartVMData::GetIsolateSnapshot() const {
72 return isolate_snapshot_;
73 }
74
GetSharedSnapshot() const75 fml::RefPtr<const DartSnapshot> DartVMData::GetSharedSnapshot() const {
76 return shared_snapshot_;
77 }
78
79 } // namespace flutter
80