summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 13:32:51 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 13:32:51 +0000
commitac7264cf34b514ff94fcce9a9c7dae0704cd4e10 (patch)
tree0a3a8e68e60c68b892a82d6c3ddbf9ef8902c187
parentae618ad90c5106ed686eedfde7c8f70f2df79b32 (diff)
downloadchromium_src-ac7264cf34b514ff94fcce9a9c7dae0704cd4e10.zip
chromium_src-ac7264cf34b514ff94fcce9a9c7dae0704cd4e10.tar.gz
chromium_src-ac7264cf34b514ff94fcce9a9c7dae0704cd4e10.tar.bz2
base: Add SetEnv() to EnvVarGetter class and get rid of the some ifdefs.
(Note: This was a TODO) BUG=None TEST=included Review URL: http://codereview.chromium.org/2843048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51840 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/env_var.cc17
-rw-r--r--base/env_var.h3
-rw-r--r--base/xdg_util_unittest.cc1
-rw-r--r--chrome/browser/shell_integration_unittest.cc4
-rw-r--r--chrome/common/logging_chrome_uitest.cc16
-rw-r--r--net/proxy/proxy_config_service_linux_unittest.cc3
6 files changed, 29 insertions, 15 deletions
diff --git a/base/env_var.cc b/base/env_var.cc
index 3075fda..8d32c02 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
diff --git a/base/env_var.h b/base/env_var.h
index af1ec79..6888353 100644
--- a/base/env_var.h
+++ b/base/env_var.h
@@ -24,6 +24,9 @@ class EnvVarGetter {
return GetEnv(variable_name, NULL);
}
+ virtual void SetEnv(const char* variable_name,
+ const std::string& new_value) = 0;
+
// Create an instance of EnvVarGetter
static EnvVarGetter* Create();
};
diff --git a/base/xdg_util_unittest.cc b/base/xdg_util_unittest.cc
index d5ddc86..813242b 100644
--- a/base/xdg_util_unittest.cc
+++ b/base/xdg_util_unittest.cc
@@ -19,6 +19,7 @@ namespace {
class MockEnvVarGetter : public base::EnvVarGetter {
public:
MOCK_METHOD2(GetEnv, bool(const char*, std::string* result));
+ MOCK_METHOD2(SetEnv, void(const char*, const std::string& new_value));
};
const char* kGnome = "gnome";
diff --git a/chrome/browser/shell_integration_unittest.cc b/chrome/browser/shell_integration_unittest.cc
index f17680f..9b95642 100644
--- a/chrome/browser/shell_integration_unittest.cc
+++ b/chrome/browser/shell_integration_unittest.cc
@@ -48,6 +48,10 @@ class MockEnvVarGetter : public base::EnvVarGetter {
return false;
}
+ virtual void SetEnv(const char* variable_name, const std::string& new_value) {
+ NOTIMPLEMENTED();
+ }
+
private:
std::map<std::string, std::string> variables_;
diff --git a/chrome/common/logging_chrome_uitest.cc b/chrome/common/logging_chrome_uitest.cc
index 1b64cae..648aace 100644
--- a/chrome/common/logging_chrome_uitest.cc
+++ b/chrome/common/logging_chrome_uitest.cc
@@ -29,24 +29,14 @@ class ChromeLoggingTest : public testing::Test {
if (!env->GetEnv(env_vars::kLogFileName, &environment_filename_))
environment_filename_ = "";
- // TODO(port) Add base::SetEnv() and get rid of the ifdefs.
-#if defined(OS_WIN)
- SetEnvironmentVariable(ASCIIToWide(env_vars::kLogFileName).c_str(),
- ASCIIToWide(new_value).c_str());
-#else
- setenv(env_vars::kLogFileName, new_value.c_str(), 1);
-#endif
+ env->SetEnv(env_vars::kLogFileName, new_value);
}
// Restores the value of the log file nave environment variable
// previously saved by SaveEnvironmentVariable().
void RestoreEnvironmentVariable() {
-#if defined(OS_WIN)
- SetEnvironmentVariable(ASCIIToWide(env_vars::kLogFileName).c_str(),
- ASCIIToWide(environment_filename_).c_str());
-#else
- setenv(env_vars::kLogFileName, environment_filename_.c_str(), 1);
-#endif
+ scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ env->SetEnv(env_vars::kLogFileName, environment_filename_);
}
private:
diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc
index cf1c810..501a411 100644
--- a/net/proxy/proxy_config_service_linux_unittest.cc
+++ b/net/proxy/proxy_config_service_linux_unittest.cc
@@ -114,6 +114,9 @@ class MockEnvVarGetter : public base::EnvVarGetter {
return false;
}
+ virtual void SetEnv(const char* variable_name, const std::string& new_value) {
+ NOTIMPLEMENTED();
+ }
// Intentionally public, for convenience when setting up a test.
EnvVarValues values;