Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
run_configuration.cc
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#include "flutter/shell/common/run_configuration.h"
6
7#include <sstream>
8#include <utility>
9
10#include "flutter/assets/directory_asset_bundle.h"
11#include "flutter/common/graphics/persistent_cache.h"
12#include "flutter/fml/file.h"
13#include "flutter/fml/unique_fd.h"
14#include "flutter/runtime/dart_vm.h"
15#include "flutter/runtime/isolate_configuration.h"
16
17namespace flutter {
18
20 const Settings& settings,
21 const fml::RefPtr<fml::TaskRunner>& io_worker,
22 IsolateLaunchType launch_type) {
23 auto asset_manager = std::make_shared<AssetManager>();
24
25 if (fml::UniqueFD::traits_type::IsValid(settings.assets_dir)) {
26 asset_manager->PushBack(std::make_unique<DirectoryAssetBundle>(
27 fml::Duplicate(settings.assets_dir), true));
28 }
29
30 asset_manager->PushBack(std::make_unique<DirectoryAssetBundle>(
31 fml::OpenDirectory(settings.assets_path.c_str(), false,
33 true));
34
35 return {IsolateConfiguration::InferFromSettings(settings, asset_manager,
36 io_worker, launch_type),
37 asset_manager};
38}
39
41 std::unique_ptr<IsolateConfiguration> configuration)
42 : RunConfiguration(std::move(configuration),
43 std::make_shared<AssetManager>()) {
45}
46
48 std::unique_ptr<IsolateConfiguration> configuration,
49 std::shared_ptr<AssetManager> asset_manager)
50 : isolate_configuration_(std::move(configuration)),
51 asset_manager_(std::move(asset_manager)) {
53}
54
56
58
60 return asset_manager_ && isolate_configuration_;
61}
62
64 std::unique_ptr<AssetResolver> resolver) {
65 if (!resolver || !resolver->IsValid()) {
66 return false;
67 }
68
69 asset_manager_->PushBack(std::move(resolver));
70 return true;
71}
72
73void RunConfiguration::SetEntrypoint(std::string entrypoint) {
74 entrypoint_ = std::move(entrypoint);
75}
76
78 std::string library) {
79 SetEntrypoint(std::move(entrypoint));
80 entrypoint_library_ = std::move(library);
81}
82
84 std::vector<std::string> entrypoint_args) {
85 entrypoint_args_ = std::move(entrypoint_args);
86}
87
88std::shared_ptr<AssetManager> RunConfiguration::GetAssetManager() const {
89 return asset_manager_;
90}
91
92const std::string& RunConfiguration::GetEntrypoint() const {
93 return entrypoint_;
94}
95
96const std::string& RunConfiguration::GetEntrypointLibrary() const {
97 return entrypoint_library_;
98}
99
100const std::vector<std::string>& RunConfiguration::GetEntrypointArgs() const {
101 return entrypoint_args_;
102}
103
104std::unique_ptr<IsolateConfiguration>
106 return std::move(isolate_configuration_);
107}
108
109} // namespace flutter
static std::unique_ptr< IsolateConfiguration > InferFromSettings(const Settings &settings, const std::shared_ptr< AssetManager > &asset_manager=nullptr, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer the isolate configuration from the Settings object. If the VM is configured for AOT...
static void SetAssetManager(std::shared_ptr< AssetManager > value)
Specifies all the configuration required by the runtime library to launch the root isolate....
std::unique_ptr< IsolateConfiguration > TakeIsolateConfiguration()
The engine uses this to take the isolate configuration from the run configuration....
std::shared_ptr< AssetManager > GetAssetManager() const
const std::string & GetEntrypoint() const
void SetEntrypointArgs(std::vector< std::string > entrypoint_args)
Updates the main application entrypoint arguments.
const std::vector< std::string > & GetEntrypointArgs() const
void SetEntrypointAndLibrary(std::string entrypoint, std::string library)
Specifies the main Dart entrypoint and the library to find that entrypoint in. By default,...
bool AddAssetResolver(std::unique_ptr< AssetResolver > resolver)
Asset managers maintain a list of resolvers that are checked in order when attempting to locate an as...
bool IsValid() const
A valid run configuration only guarantees that the engine should be able to find the assets and the i...
void SetEntrypoint(std::string entrypoint)
Updates the main application entrypoint. If this is not set, the "main" method is used as the entrypo...
RunConfiguration(std::unique_ptr< IsolateConfiguration > configuration)
Creates a run configuration with only an isolate configuration. There is no asset manager and default...
~RunConfiguration()
There are no threading restrictions on the destruction of the run configuration.
const std::string & GetEntrypointLibrary() const
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor)
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition file_posix.cc:97
Definition ref_ptr.h:256