diff --git a/DEPS b/DEPS index 2e0a1ae93c..159be4fa82 100644 --- a/DEPS +++ b/DEPS @@ -63,7 +63,7 @@ deps = { # and not have to specific specific hashes. 'src/lib/ftl': - Var('fuchsia_git') + '/ftl' + '@' + 'f1357b6eaa9a23cffec1645dfeba610b5f926b1d', + Var('fuchsia_git') + '/ftl' + '@' + '81aa1ca480c99caffbc2965deb0a6f7ac7f59f1c', 'src/lib/tonic': Var('fuchsia_git') + '/tonic' + '@' + '5b3d521980ca00274ad7e67f9f8b203cd4b20039', diff --git a/engine/src/flutter/shell/common/switches.cc b/engine/src/flutter/shell/common/switches.cc index 9a3168f735..6ea1bb3dbc 100644 --- a/engine/src/flutter/shell/common/switches.cc +++ b/engine/src/flutter/shell/common/switches.cc @@ -7,6 +7,8 @@ #include #include +#include "lib/ftl/strings/string_view.h" + // Include once for the default enum definition. #include "flutter/shell/common/switches.h" @@ -14,7 +16,7 @@ struct SwitchDesc { shell::Switch sw; - const char* flag; + const ftl::StringView flag; const char* help; }; @@ -46,7 +48,7 @@ void PrintUsage(const std::string& executable_name) { uint32_t max_width = 2; for (uint32_t i = 0; i < flags_count; i++) { auto desc = gSwitchDescs[i]; - max_width = std::max(strlen(desc.flag) + 2, max_width); + max_width = std::max(desc.flag.size() + 2, max_width); } const uint32_t help_width = column_width - max_width - 3; @@ -56,7 +58,7 @@ void PrintUsage(const std::string& executable_name) { auto desc = gSwitchDescs[i]; std::cerr << std::setw(max_width) - << std::string("--") + std::string(desc.flag) << " : "; + << std::string("--") + desc.flag.ToString() << " : "; std::istringstream stream(desc.help); int32_t remaining = help_width; @@ -78,13 +80,13 @@ void PrintUsage(const std::string& executable_name) { std::cerr << std::string(column_width, '-') << std::endl; } -const char* FlagForSwitch(Switch swtch) { +const ftl::StringView FlagForSwitch(Switch swtch) { for (uint32_t i = 0; i < static_cast(Switch::Sentinel); i++) { if (gSwitchDescs[i].sw == swtch) { return gSwitchDescs[i].flag; } } - return nullptr; + return ftl::StringView(); } } // namespace shell diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index c64ee650da..59e44cc3bf 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "lib/ftl/strings/string_view.h" + #ifndef SHELL_COMMON_SWITCHES_H_ #define SHELL_COMMON_SWITCHES_H_ @@ -101,7 +103,7 @@ DEF_SWITCHES_END void PrintUsage(const std::string& executable_name); -const char* FlagForSwitch(Switch sw); +const ftl::StringView FlagForSwitch(Switch sw); } // namespace shell diff --git a/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm b/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm index 66eca97829..6b59e3488b 100644 --- a/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm +++ b/engine/src/flutter/shell/platform/darwin/common/platform_mac.mm @@ -15,6 +15,7 @@ #include "flutter/shell/common/tracing_controller.h" #include "flutter/sky/engine/wtf/MakeUnique.h" #include "lib/ftl/command_line.h" +#include "lib/ftl/strings/string_view.h" namespace shell { @@ -91,7 +92,7 @@ static bool FlagsValidForCommandLineLaunch(const std::string& bundle_path, return true; } -static std::string ResolveCommandLineLaunchFlag(const char* name) { +static std::string ResolveCommandLineLaunchFlag(const ftl::StringView name) { const auto& command_line = shell::Shell::Shared().GetCommandLine(); std::string command_line_option; @@ -100,7 +101,7 @@ static std::string ResolveCommandLineLaunchFlag(const char* name) { } const char* saved_default = - [[NSUserDefaults standardUserDefaults] stringForKey:@(name)].UTF8String; + [[NSUserDefaults standardUserDefaults] stringForKey:@(name.data())].UTF8String; if (saved_default != NULL) { return saved_default; @@ -121,9 +122,9 @@ bool AttemptLaunchFromCommandLineSwitches(Engine* engine) { // one go. We dont want to end up in a situation where we take one value // from the command line and the others from user defaults. In case, any // new flags are specified, forget about all the old ones. - [defaults removeObjectForKey:@(FlagForSwitch(Switch::FLX))]; - [defaults removeObjectForKey:@(FlagForSwitch(Switch::MainDartFile))]; - [defaults removeObjectForKey:@(FlagForSwitch(Switch::Packages))]; + [defaults removeObjectForKey:@(FlagForSwitch(Switch::FLX).data())]; + [defaults removeObjectForKey:@(FlagForSwitch(Switch::MainDartFile).data())]; + [defaults removeObjectForKey:@(FlagForSwitch(Switch::Packages).data())]; [defaults synchronize]; } @@ -139,9 +140,9 @@ bool AttemptLaunchFromCommandLineSwitches(Engine* engine) { // Save the newly resolved dart main file and the package root to user // defaults so that the next time the user launches the application in the // simulator without the tooling, the application boots up. - [defaults setObject:@(bundle_path.c_str()) forKey:@(FlagForSwitch(Switch::FLX))]; - [defaults setObject:@(main.c_str()) forKey:@(FlagForSwitch(Switch::MainDartFile))]; - [defaults setObject:@(packages.c_str()) forKey:@(FlagForSwitch(Switch::Packages))]; + [defaults setObject:@(bundle_path.c_str()) forKey:@(FlagForSwitch(Switch::FLX).data())]; + [defaults setObject:@(main.c_str()) forKey:@(FlagForSwitch(Switch::MainDartFile).data())]; + [defaults setObject:@(packages.c_str()) forKey:@(FlagForSwitch(Switch::Packages).data())]; [defaults synchronize]; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 80f7e59268..1b411654fa 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -10,20 +10,21 @@ #include "flutter/shell/common/switches.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartSource.h" #include "flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h" +#include "lib/ftl/strings/string_view.h" -static NSURL* URLForSwitch(const char* name) { +static NSURL* URLForSwitch(const ftl::StringView name) { const auto& cmd = shell::Shell::Shared().GetCommandLine(); NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; std::string switch_value; if (cmd.GetOptionValue(name, &switch_value)) { auto url = [NSURL fileURLWithPath:@(switch_value.c_str())]; - [defaults setURL:url forKey:@(name)]; + [defaults setURL:url forKey:@(name.data())]; [defaults synchronize]; return url; } - return [defaults URLForKey:@(name)]; + return [defaults URLForKey:@(name.data())]; } @implementation FlutterDartProject {