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