2727#include < sstream>
2828
2929#include " file_in_namespace_buffer.h"
30+ #include " flutter/fml/command_line.h"
3031#include " flutter/fml/mapping.h"
3132#include " flutter/fml/platform/fuchsia/task_observers.h"
3233#include " flutter/fml/synchronization/waitable_event.h"
4243namespace flutter_runner {
4344namespace {
4445
46+ // "data" and "assets" are arguments that are specific to the Flutter runner.
47+ // They will likely go away if we migrate to the ELF runner.
4548constexpr char kDataKey [] = " data" ;
4649constexpr char kAssetsKey [] = " assets" ;
50+
51+ // "args" are how the component specifies arguments to the runner.
52+ constexpr char kArgsKey [] = " args" ;
53+ constexpr char kOldGenHeapSizeKey [] = " old_gen_heap_size" ;
54+
4755constexpr char kTmpPath [] = " /tmp" ;
4856constexpr char kServiceRootPath [] = " /svc" ;
4957constexpr char kRunnerConfigPath [] = " /config/data/flutter_runner_config" ;
@@ -57,24 +65,53 @@ std::string DebugLabelForUrl(const std::string& url) {
5765 }
5866}
5967
68+ // / Parses the |args| field from the "program" field into
69+ // / |metadata|.
70+ void ParseArgs (std::vector<std::string>& args, ProgramMetadata* metadata) {
71+ // fml::CommandLine expects the first argument to be the name of the program,
72+ // so we prepend a dummy argument so we can use fml::CommandLine to parse the
73+ // arguments for us.
74+ std::vector<std::string> command_line_args = {" " };
75+ command_line_args.insert (command_line_args.end (), args.begin (), args.end ());
76+ fml::CommandLine parsed_args = fml::CommandLineFromIterators (
77+ command_line_args.begin (), command_line_args.end ());
78+
79+ std::string old_gen_heap_size_option;
80+ if (parsed_args.GetOptionValue (kOldGenHeapSizeKey ,
81+ &old_gen_heap_size_option)) {
82+ int64_t specified_old_gen_heap_size = strtol (
83+ old_gen_heap_size_option.c_str (), nullptr /* endptr */ , 10 /* base */ );
84+ if (specified_old_gen_heap_size != 0 ) {
85+ metadata->old_gen_heap_size = specified_old_gen_heap_size;
86+ } else {
87+ FML_LOG (ERROR) << " Invalid old_gen_heap_size: "
88+ << old_gen_heap_size_option;
89+ }
90+ }
91+ }
92+
6093} // namespace
6194
62- void ComponentV2::ParseProgramMetadata (
63- const fuchsia::data::Dictionary& program_metadata,
64- std::string* data_path,
65- std::string* assets_path) {
95+ ProgramMetadata ComponentV2::ParseProgramMetadata (
96+ const fuchsia::data::Dictionary& program_metadata) {
97+ ProgramMetadata result;
98+
6699 for (const auto & entry : program_metadata.entries ()) {
67100 if (entry.key .compare (kDataKey ) == 0 && entry.value != nullptr ) {
68- * data_path = " pkg/" + entry.value ->str ();
101+ result. data_path = " pkg/" + entry.value ->str ();
69102 } else if (entry.key .compare (kAssetsKey ) == 0 && entry.value != nullptr ) {
70- *assets_path = " pkg/" + entry.value ->str ();
103+ result.assets_path = " pkg/" + entry.value ->str ();
104+ } else if (entry.key .compare (kArgsKey ) == 0 && entry.value != nullptr ) {
105+ ParseArgs (entry.value ->str_vec (), &result);
71106 }
72107 }
73108
74109 // assets_path defaults to the same as data_path if omitted.
75- if (assets_path-> empty ()) {
76- * assets_path = * data_path;
110+ if (result. assets_path . empty ()) {
111+ result. assets_path = result. data_path ;
77112 }
113+
114+ return result;
78115}
79116
80117ActiveComponentV2 ComponentV2::Create (
@@ -124,12 +161,9 @@ ComponentV2::ComponentV2(
124161 // TODO(fxb/88391): Dart launch arguments.
125162 FML_LOG (WARNING) << " program() arguments are currently ignored (fxb/88391)." ;
126163
127- // Determine where data and assets are stored within /pkg.
128- std::string data_path;
129- std::string assets_path;
130- ParseProgramMetadata (start_info.program (), &data_path, &assets_path);
164+ ProgramMetadata metadata = ParseProgramMetadata (start_info.program ());
131165
132- if (data_path.empty ()) {
166+ if (metadata. data_path .empty ()) {
133167 FML_DLOG (ERROR) << " Could not find a /pkg/data directory for "
134168 << start_info.resolved_url ();
135169 return ;
@@ -181,11 +215,11 @@ ComponentV2::ComponentV2(
181215 constexpr mode_t mode = O_RDONLY | O_DIRECTORY;
182216
183217 component_assets_directory_.reset (
184- openat (ns_fd.get (), assets_path.c_str (), mode));
218+ openat (ns_fd.get (), metadata. assets_path .c_str (), mode));
185219 FML_DCHECK (component_assets_directory_.is_valid ());
186220
187221 component_data_directory_.reset (
188- openat (ns_fd.get (), data_path.c_str (), mode));
222+ openat (ns_fd.get (), metadata. data_path .c_str (), mode));
189223 FML_DCHECK (component_data_directory_.is_valid ());
190224 }
191225
@@ -398,6 +432,10 @@ ComponentV2::ComponentV2(
398432
399433 settings_.log_tag = debug_label_ + std::string{" (flutter)" };
400434
435+ if (metadata.old_gen_heap_size .has_value ()) {
436+ settings_.old_gen_heap_size = *metadata.old_gen_heap_size ;
437+ }
438+
401439 // No asserts in debug or release product.
402440 // No asserts in release with flutter_profile=true (non-product)
403441 // Yes asserts in non-product debug.
0 commit comments