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 
9 #include "flutter/assets/directory_asset_bundle.h"
10 #include "flutter/fml/file.h"
11 #include "flutter/fml/unique_fd.h"
12 #include "flutter/runtime/dart_vm.h"
13 #include "flutter/shell/common/persistent_cache.h"
14 
15 namespace flutter {
16 
18  const Settings& settings,
19  fml::RefPtr<fml::TaskRunner> io_worker) {
20  auto asset_manager = std::make_shared<AssetManager>();
21 
23  asset_manager->PushBack(std::make_unique<DirectoryAssetBundle>(
24  fml::Duplicate(settings.assets_dir), true));
25  }
26 
27  asset_manager->PushBack(std::make_unique<DirectoryAssetBundle>(
28  fml::OpenDirectory(settings.assets_path.c_str(), false,
30  true));
31 
32  return {IsolateConfiguration::InferFromSettings(settings, asset_manager,
33  io_worker),
34  asset_manager};
35 }
36 
38  std::unique_ptr<IsolateConfiguration> configuration)
39  : RunConfiguration(std::move(configuration),
40  std::make_shared<AssetManager>()) {
41  PersistentCache::SetAssetManager(asset_manager_);
42 }
43 
45  std::unique_ptr<IsolateConfiguration> configuration,
46  std::shared_ptr<AssetManager> asset_manager)
47  : isolate_configuration_(std::move(configuration)),
48  asset_manager_(std::move(asset_manager)) {
49  PersistentCache::SetAssetManager(asset_manager_);
50 }
51 
53 
55 
57  return asset_manager_ && isolate_configuration_;
58 }
59 
61  std::unique_ptr<AssetResolver> resolver) {
62  if (!resolver || !resolver->IsValid()) {
63  return false;
64  }
65 
66  asset_manager_->PushBack(std::move(resolver));
67  return true;
68 }
69 
70 void RunConfiguration::SetEntrypoint(std::string entrypoint) {
71  entrypoint_ = std::move(entrypoint);
72 }
73 
74 void RunConfiguration::SetEntrypointAndLibrary(std::string entrypoint,
75  std::string library) {
76  SetEntrypoint(entrypoint);
77  entrypoint_library_ = std::move(library);
78 }
79 
80 std::shared_ptr<AssetManager> RunConfiguration::GetAssetManager() const {
81  return asset_manager_;
82 }
83 
84 const std::string& RunConfiguration::GetEntrypoint() const {
85  return entrypoint_;
86 }
87 
88 const std::string& RunConfiguration::GetEntrypointLibrary() const {
89  return entrypoint_library_;
90 }
91 
92 std::unique_ptr<IsolateConfiguration>
94  return std::move(isolate_configuration_);
95 }
96 
97 } // namespace flutter
bool IsValid() const
A valid run configuration only guarantees that the engine should be able to find the assets and the i...
std::shared_ptr< AssetManager > GetAssetManager() const
std::unique_ptr< IsolateConfiguration > TakeIsolateConfiguration()
The engine uses this to take the isolate configuration from the run configuration. The run configuration is no longer valid after this call is made. The non-copyable nature of some of the snapshots referenced in the isolate configuration is why the run configuration as a whole is not copyable.
fml::UniqueFD::element_type assets_dir
Definition: settings.h:215
Definition: ref_ptr.h:252
const std::string & GetEntrypoint() const
fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor)
Definition: file_posix.cc:120
RunConfiguration(std::unique_ptr< IsolateConfiguration > configuration)
Creates a run configuration with only an isolate configuration. There is no asset manager and default...
const std::string & GetEntrypointLibrary() const
~RunConfiguration()
There are no threading restrictions on the destruction of the run configuration.
static bool IsValid(int value)
Definition: unique_fd.h:39
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:94
void SetEntrypoint(std::string entrypoint)
Updates the main application entrypoint. If this is not set, the "main" method is used as the entrypo...
static RunConfiguration InferFromSettings(const Settings &settings, fml::RefPtr< fml::TaskRunner > io_worker=nullptr)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
static void SetAssetManager(std::shared_ptr< AssetManager > value)
Specifies all the configuration required by the runtime library to launch the root isolate...
static std::unique_ptr< IsolateConfiguration > InferFromSettings(const Settings &settings, std::shared_ptr< AssetManager > asset_manager=nullptr, fml::RefPtr< fml::TaskRunner > io_worker=nullptr)
Attempts to infer the isolate configuration from the Settings object. If the VM is configured for AOT...
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...
std::string assets_path
Definition: settings.h:217