[remoting] Modernize Environment::GetVar to use std::optional
Updates GetVar usage to use the modern std::optional API instead of out-parameters. Bug: 400758498 Change-Id: I88e21dd3b21f709722a348ca55f5f070c8951f79 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6426204 Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Colin Blundell <blundell@chromium.org> Reviewed-by: Joe Downing <joedow@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org> Cr-Commit-Position: refs/heads/main@{#1443592}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c2c938d6a9
commit
4e5370c619
media/gpu/vaapi/test/fake_libva_driver
pdf/pdfium
remoting/host
@ -21,9 +21,9 @@ std::unique_ptr<media::internal::ContextDelegate> CreateDelegate(
|
||||
int picture_height) {
|
||||
std::unique_ptr<base::Environment> env = base::Environment::Create();
|
||||
CHECK(env);
|
||||
std::string no_op_flag;
|
||||
if (env->GetVar("USE_NO_OP_CONTEXT_DELEGATE", &no_op_flag) &&
|
||||
no_op_flag == "1") {
|
||||
std::string no_op_flag =
|
||||
env->GetVar("USE_NO_OP_CONTEXT_DELEGATE").value_or(std::string());
|
||||
if (no_op_flag == "1") {
|
||||
return std::make_unique<media::internal::NoOpContextDelegate>();
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,9 @@ namespace {
|
||||
base::FilePath GetTestFontsDir() {
|
||||
// base::TestSuite::Initialize() should have already set this.
|
||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||
std::string fontconfig_sysroot;
|
||||
CHECK(env->GetVar("FONTCONFIG_SYSROOT", &fontconfig_sysroot));
|
||||
return base::FilePath(fontconfig_sysroot).AppendASCII("test_fonts");
|
||||
auto fontconfig_sysroot = env->GetVar("FONTCONFIG_SYSROOT");
|
||||
CHECK(fontconfig_sysroot.has_value());
|
||||
return base::FilePath(fontconfig_sysroot.value()).AppendASCII("test_fonts");
|
||||
}
|
||||
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
||||
|
||||
|
@ -114,8 +114,8 @@ RemoteOpenUrlClientDelegateLinux::~RemoteOpenUrlClientDelegateLinux() = default;
|
||||
|
||||
void RemoteOpenUrlClientDelegateLinux::OpenUrlOnFallbackBrowser(
|
||||
const GURL& url) {
|
||||
std::string current_desktop;
|
||||
environment_->GetVar(kXdgCurrentDesktopEnvVar, ¤t_desktop);
|
||||
std::string current_desktop =
|
||||
environment_->GetVar(kXdgCurrentDesktopEnvVar).value_or(std::string());
|
||||
|
||||
const char* host_setting_key = kLinuxPreviousDefaultWebBrowserGeneric;
|
||||
if (base::Contains(current_desktop, "Cinnamon")) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "remoting/host/webauthn/remote_webauthn_caller_security_utils.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/environment.h"
|
||||
@ -108,9 +109,9 @@ bool IsLaunchedByTrustedProcess() {
|
||||
|
||||
// COMSPEC is generally "C:\WINDOWS\system32\cmd.exe". Note that the casing
|
||||
// does not match the actual file path's casing.
|
||||
std::string comspec_utf8;
|
||||
if (environment->GetVar("COMSPEC", &comspec_utf8)) {
|
||||
base::FilePath::StringType comspec = base::UTF8ToWide(comspec_utf8);
|
||||
std::optional<std::string> comspec_utf8 = environment->GetVar("COMSPEC");
|
||||
if (comspec_utf8.has_value()) {
|
||||
base::FilePath::StringType comspec = base::UTF8ToWide(comspec_utf8.value());
|
||||
if (base::FilePath::CompareEqualIgnoreCase(parent_image_path.value(),
|
||||
comspec)) {
|
||||
// Skip to the grandparent.
|
||||
@ -129,11 +130,13 @@ bool IsLaunchedByTrustedProcess() {
|
||||
|
||||
// Check if the caller's image path is allowlisted.
|
||||
for (std::string_view apps_dir_env_var : kAppsDirectoryEnvVars) {
|
||||
std::string apps_dir_path_utf8;
|
||||
if (!environment->GetVar(apps_dir_env_var, &apps_dir_path_utf8)) {
|
||||
std::optional<std::string> apps_dir_path_utf8 =
|
||||
environment->GetVar(apps_dir_env_var);
|
||||
if (!apps_dir_path_utf8.has_value()) {
|
||||
continue;
|
||||
}
|
||||
auto apps_dir_path = base::FilePath::FromUTF8Unsafe(apps_dir_path_utf8);
|
||||
auto apps_dir_path =
|
||||
base::FilePath::FromUTF8Unsafe(apps_dir_path_utf8.value());
|
||||
if (!apps_dir_path.IsParent(parent_image_path)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "remoting/host/webauthn/remote_webauthn_extension_notifier.h"
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "base/base_paths.h"
|
||||
@ -86,10 +87,11 @@ std::vector<base::FilePath> GetRemoteStateChangeDirPaths() {
|
||||
// See: chrome/common/chrome_paths_linux.cc
|
||||
auto env = base::Environment::Create();
|
||||
base::FilePath base_path;
|
||||
std::string chrome_config_home_str;
|
||||
if (env->GetVar("CHROME_CONFIG_HOME", &chrome_config_home_str) &&
|
||||
base::IsStringUTF8(chrome_config_home_str)) {
|
||||
base_path = base::FilePath::FromUTF8Unsafe(chrome_config_home_str);
|
||||
std::optional<std::string> chrome_config_home_str =
|
||||
env->GetVar("CHROME_CONFIG_HOME");
|
||||
if (chrome_config_home_str.has_value() &&
|
||||
base::IsStringUTF8(chrome_config_home_str.value())) {
|
||||
base_path = base::FilePath::FromUTF8Unsafe(chrome_config_home_str.value());
|
||||
} else {
|
||||
base_path = base::nix::GetXDGDirectory(
|
||||
env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir);
|
||||
|
Reference in New Issue
Block a user