Flutter Engine
The Flutter Engine
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
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
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>()) {
44#if !SLIMPELLER
46#endif // !SLIMPELLER
47}
48
50 std::unique_ptr<IsolateConfiguration> configuration,
51 std::shared_ptr<AssetManager> asset_manager)
52 : isolate_configuration_(std::move(configuration)),
53 asset_manager_(std::move(asset_manager)) {
54#if !SLIMPELLER
56#endif // !SLIMPELLER
57}
58
60
62
64 return asset_manager_ && isolate_configuration_;
65}
66
68 std::unique_ptr<AssetResolver> resolver) {
69 if (!resolver || !resolver->IsValid()) {
70 return false;
71 }
72
73 asset_manager_->PushBack(std::move(resolver));
74 return true;
75}
76
77void RunConfiguration::SetEntrypoint(std::string entrypoint) {
78 entrypoint_ = std::move(entrypoint);
79}
80
82 std::string library) {
83 SetEntrypoint(std::move(entrypoint));
84 entrypoint_library_ = std::move(library);
85}
86
88 std::vector<std::string> entrypoint_args) {
89 entrypoint_args_ = std::move(entrypoint_args);
90}
91
92std::shared_ptr<AssetManager> RunConfiguration::GetAssetManager() const {
93 return asset_manager_;
94}
95
96const std::string& RunConfiguration::GetEntrypoint() const {
97 return entrypoint_;
98}
99
100const std::string& RunConfiguration::GetEntrypointLibrary() const {
101 return entrypoint_library_;
102}
103
104const std::vector<std::string>& RunConfiguration::GetEntrypointArgs() const {
105 return entrypoint_args_;
106}
107
108std::unique_ptr<IsolateConfiguration>
110 return std::move(isolate_configuration_);
111}
112
113} // 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)
Definition: file_posix.cc:123
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:97
Definition: ref_ptr.h:256
static bool IsValid(int value)
Definition: unique_fd.h:78