[go: nahoru, domu]

blob: 894236b7355b2c8ce2764eda2ba4f6e2d9629076 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2011 The Chromium Authors
thestig@chromium.org9bc8cff2010-04-03 01:05:392// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
tfarina@chromium.org76b90d312010-08-03 03:00:505#ifndef BASE_ENVIRONMENT_H_
6#define BASE_ENVIRONMENT_H_
thestig@chromium.org9bc8cff2010-04-03 01:05:397
brettw@chromium.orgb345c482013-08-30 18:00:398#include <map>
dcheng093de9b2016-04-04 21:25:519#include <memory>
thestig@chromium.org9bc8cff2010-04-03 01:05:3910#include <string>
11
darin@chromium.org0bea7252011-08-05 15:34:0012#include "base/base_export.h"
thestig0c412e852016-06-30 08:04:4013#include "base/strings/string_piece.h"
jhawkins@chromium.org2edc2862011-04-04 18:04:3714#include "build/build_config.h"
thestig@chromium.org9bc8cff2010-04-03 01:05:3915
16namespace base {
17
tfarina@chromium.org574f6f0c2010-07-21 02:59:2818namespace env_vars {
19
Xiaohan Wang38e4ebb2022-01-19 06:57:4320#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
darin@chromium.org0bea7252011-08-05 15:34:0021BASE_EXPORT extern const char kHome[];
tfarina@chromium.org574f6f0c2010-07-21 02:59:2822#endif
23
24} // namespace env_vars
25
darin@chromium.org0bea7252011-08-05 15:34:0026class BASE_EXPORT Environment {
thestig@chromium.org9bc8cff2010-04-03 01:05:3927 public:
tfarina@chromium.org76b90d312010-08-03 03:00:5028 virtual ~Environment();
erg@chromium.org3a3d47472010-07-15 21:03:5429
thestig0c412e852016-06-30 08:04:4030 // Returns the appropriate platform-specific instance.
31 static std::unique_ptr<Environment> Create();
tfarina@chromium.orgfc586c72010-07-31 16:55:4032
thestig@chromium.org9bc8cff2010-04-03 01:05:3933 // Gets an environment variable's value and stores it in |result|.
34 // Returns false if the key is unset.
thestig0c412e852016-06-30 08:04:4035 virtual bool GetVar(StringPiece variable_name, std::string* result) = 0;
thestig@chromium.org9bc8cff2010-04-03 01:05:3936
thestig0c412e852016-06-30 08:04:4037 // Syntactic sugar for GetVar(variable_name, nullptr);
38 virtual bool HasVar(StringPiece variable_name);
thestig@chromium.org9bc8cff2010-04-03 01:05:3939
David Benjamin76ee79eb2019-03-15 17:02:0940 // Returns true on success, otherwise returns false. This method should not
41 // be called in a multi-threaded process.
thestig0c412e852016-06-30 08:04:4042 virtual bool SetVar(StringPiece variable_name,
tfarina@chromium.orgac7264c2010-07-08 13:32:5143 const std::string& new_value) = 0;
44
David Benjamin76ee79eb2019-03-15 17:02:0945 // Returns true on success, otherwise returns false. This method should not
46 // be called in a multi-threaded process.
thestig0c412e852016-06-30 08:04:4047 virtual bool UnSetVar(StringPiece variable_name) = 0;
thestig@chromium.org9bc8cff2010-04-03 01:05:3948};
49
Xiaohan Wang38e4ebb2022-01-19 06:57:4350#if BUILDFLAG(IS_WIN)
Jan Wilken Dörrie6bdce492019-11-05 11:36:5051using NativeEnvironmentString = std::wstring;
Xiaohan Wang38e4ebb2022-01-19 06:57:4352#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
David Benjamin76ee79eb2019-03-15 17:02:0953using NativeEnvironmentString = std::string;
Jan Wilken Dörrie6bdce492019-11-05 11:36:5054#endif
David Benjamin76ee79eb2019-03-15 17:02:0955using EnvironmentMap =
56 std::map<NativeEnvironmentString, NativeEnvironmentString>;
brettw@chromium.orgb345c482013-08-30 18:00:3957
thestig@chromium.org9bc8cff2010-04-03 01:05:3958} // namespace base
59
tfarina@chromium.org76b90d312010-08-03 03:00:5060#endif // BASE_ENVIRONMENT_H_