Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: base/env_var.cc

Issue 2843048: base: Add SetEnv() to EnvVarGetter class and get rid of the some ifdefs. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: filename Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/env_var.h ('k') | base/xdg_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/env_var.cc
diff --git a/base/env_var.cc b/base/env_var.cc
index 3075fdadb29ab448edffcff5e4e091a273f2d030..8d32c02de572ac0e6590fb6549fa93a063c06c1c 100644
--- a/base/env_var.cc
+++ b/base/env_var.cc
@@ -19,8 +19,7 @@
namespace {
-class EnvVarGetterImpl
- : public base::EnvVarGetter {
+class EnvVarGetterImpl : public base::EnvVarGetter {
public:
virtual bool GetEnv(const char* variable_name, std::string* result) {
if (GetEnvImpl(variable_name, result))
@@ -40,6 +39,11 @@ class EnvVarGetterImpl
return false;
return GetEnvImpl(alternate_case_var.c_str(), result);
}
+
+ virtual void SetEnv(const char* variable_name, const std::string& new_value) {
+ SetEnvImpl(variable_name, new_value);
+ }
+
private:
bool GetEnvImpl(const char* variable_name, std::string* result) {
#if defined(OS_POSIX)
@@ -66,6 +70,15 @@ class EnvVarGetterImpl
#error need to port
#endif
}
+
+ void SetEnvImpl(const char* variable_name, const std::string& new_value) {
+#if defined(OS_POSIX)
+ setenv(variable_name, new_value.c_str(), 1);
+#elif defined(OS_WIN)
+ ::SetEnvironmentVariable(ASCIIToWide(variable_name).c_str(),
+ ASCIIToWide(new_value).c_str());
+#endif
+ }
};
} // namespace
« no previous file with comments | « base/env_var.h ('k') | base/xdg_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698