1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_ENVIRONMENT_H_
6 #define BASE_ENVIRONMENT_H_
12 #include "base/base_export.h"
13 #include "base/strings/string_piece.h"
14 #include "build/build_config.h"
20 #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
21 BASE_EXPORT extern const char kHome[];
24 } // namespace env_vars
26 class BASE_EXPORT Environment {
28 virtual ~Environment();
30 // Returns the appropriate platform-specific instance.
31 static std::unique_ptr<Environment> Create();
33 // Gets an environment variable's value and stores it in |result|.
34 // Returns false if the key is unset.
35 virtual bool GetVar(StringPiece variable_name, std::string* result) = 0;
37 // Syntactic sugar for GetVar(variable_name, nullptr);
38 virtual bool HasVar(StringPiece variable_name);
40 // Returns true on success, otherwise returns false. This method should not
41 // be called in a multi-threaded process.
42 virtual bool SetVar(StringPiece variable_name,
43 const std::string& new_value) = 0;
45 // Returns true on success, otherwise returns false. This method should not
46 // be called in a multi-threaded process.
47 virtual bool UnSetVar(StringPiece variable_name) = 0;
51 using NativeEnvironmentString = std::wstring;
52 #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
53 using NativeEnvironmentString = std::string;
55 using EnvironmentMap =
56 std::map<NativeEnvironmentString, NativeEnvironmentString>;
60 #endif // BASE_ENVIRONMENT_H_