From b684a9826740e6cc7447a62e1feced01210fefd5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 23 Apr 2024 21:13:59 -0500 Subject: [PATCH] refactor: replace base::EndsWith() with std::ends_with() (#41937) --- shell/app/electron_main_delegate_mac.mm | 10 ++++------ shell/browser/api/electron_api_session.cc | 3 +-- shell/browser/browser_linux.cc | 7 ++----- shell/common/mac/main_application_bundle.mm | 11 ++++------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/shell/app/electron_main_delegate_mac.mm b/shell/app/electron_main_delegate_mac.mm index 077693765bc9..98ec5007ed5a 100644 --- a/shell/app/electron_main_delegate_mac.mm +++ b/shell/app/electron_main_delegate_mac.mm @@ -33,14 +33,12 @@ base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path, base::PathService::Get(base::FILE_EXE, &path); std::string helper_name = "Helper"; - if (base::EndsWith(path.value(), content::kMacHelperSuffix_renderer, - base::CompareCase::SENSITIVE)) { + if (const auto& val = path.value(); + val.ends_with(content::kMacHelperSuffix_renderer)) { helper_name += content::kMacHelperSuffix_renderer; - } else if (base::EndsWith(path.value(), content::kMacHelperSuffix_gpu, - base::CompareCase::SENSITIVE)) { + } else if (val.ends_with(content::kMacHelperSuffix_gpu)) { helper_name += content::kMacHelperSuffix_gpu; - } else if (base::EndsWith(path.value(), content::kMacHelperSuffix_plugin, - base::CompareCase::SENSITIVE)) { + } else if (val.ends_with(content::kMacHelperSuffix_plugin)) { helper_name += content::kMacHelperSuffix_plugin; } diff --git a/shell/browser/api/electron_api_session.cc b/shell/browser/api/electron_api_session.cc index 297118b0a225..939ee15ef838 100644 --- a/shell/browser/api/electron_api_session.cc +++ b/shell/browser/api/electron_api_session.cc @@ -1545,8 +1545,7 @@ gin::Handle Session::FromPartition(v8::Isolate* isolate, if (partition.empty()) { browser_context = ElectronBrowserContext::From("", false, std::move(options)); - } else if (base::StartsWith(partition, kPersistPrefix, - base::CompareCase::SENSITIVE)) { + } else if (partition.starts_with(kPersistPrefix)) { std::string name = partition.substr(8); browser_context = ElectronBrowserContext::From(name, false, std::move(options)); diff --git a/shell/browser/browser_linux.cc b/shell/browser/browser_linux.cc index 69c6d1c835aa..5dd2c5efcb00 100644 --- a/shell/browser/browser_linux.cc +++ b/shell/browser/browser_linux.cc @@ -106,12 +106,9 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol, const std::vector argv = {kXdgSettings, "check", kXdgSettingsDefaultSchemeHandler, protocol, desktop_name}; - const auto output = GetXdgAppOutput(argv); - if (!output) - return false; - // Allow any reply that starts with "yes". - return base::StartsWith(output.value(), "yes", base::CompareCase::SENSITIVE); + const std::optional output = GetXdgAppOutput(argv); + return output && output->starts_with("yes"); } // Todo implement diff --git a/shell/common/mac/main_application_bundle.mm b/shell/common/mac/main_application_bundle.mm index cc6cef51609f..4605f929d947 100644 --- a/shell/common/mac/main_application_bundle.mm +++ b/shell/common/mac/main_application_bundle.mm @@ -31,13 +31,10 @@ base::FilePath MainApplicationBundlePath() { // Up to Contents. if (!HasMainProcessKey() && - (base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE) || - base::EndsWith(path.value(), content::kMacHelperSuffix_plugin, - base::CompareCase::SENSITIVE) || - base::EndsWith(path.value(), content::kMacHelperSuffix_renderer, - base::CompareCase::SENSITIVE) || - base::EndsWith(path.value(), content::kMacHelperSuffix_gpu, - base::CompareCase::SENSITIVE))) { + (path.value().ends_with(" Helper") || + path.value().ends_with(content::kMacHelperSuffix_plugin) || + path.value().ends_with(content::kMacHelperSuffix_renderer) || + path.value().ends_with(content::kMacHelperSuffix_gpu))) { // The running executable is the helper. Go up five steps: // Contents/Frameworks/Helper.app/Contents/MacOS/Helper // ^ to here ^ from here