summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-03 03:00:50 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-03 03:00:50 +0000
commit76b90d310def447b7b5f10d92a69813308150778 (patch)
tree24c61fdccf94360913bfa8f7ac67c24a27bcfb38 /base
parent7f2a9dbe56bfa6189271af808c53ccaee193a961 (diff)
downloadchromium_src-76b90d310def447b7b5f10d92a69813308150778.zip
chromium_src-76b90d310def447b7b5f10d92a69813308150778.tar.gz
chromium_src-76b90d310def447b7b5f10d92a69813308150778.tar.bz2
base: Rename EnvVarGetter to Environment.
Now EnvVarGetter do much more than getting environment variables. Per suggestion from Pawel in http://codereview.chromium.org/3043018/. BUG=None TEST=trybots Signed-off-by: Thiago Farina <tfarina@chromium.org> Review URL: http://codereview.chromium.org/3052034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gyp4
-rw-r--r--base/base.gypi4
-rw-r--r--base/base_paths_posix.cc6
-rw-r--r--base/environment.cc (renamed from base/env_var.cc)12
-rw-r--r--base/environment.h (renamed from base/env_var.h)12
-rw-r--r--base/environment_unittest.cc (renamed from base/env_var_unittest.cc)20
-rw-r--r--base/linux_util.cc1
-rw-r--r--base/linux_util.h2
-rw-r--r--base/nss_util.cc6
-rw-r--r--base/xdg_util.cc10
-rw-r--r--base/xdg_util.h10
-rw-r--r--base/xdg_util_unittest.cc12
12 files changed, 48 insertions, 51 deletions
diff --git a/base/base.gyp b/base/base.gyp
index 77f8de1..213b5f3 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -1,4 +1,4 @@
-# Copyright (c) 2009 The Chromium Authors. All rights reserved.
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -76,7 +76,7 @@
'data_pack_unittest.cc',
'debug_util_unittest.cc',
'dir_reader_posix_unittest.cc',
- 'env_var_unittest.cc',
+ 'environment_unittest.cc',
'event_trace_consumer_win_unittest.cc',
'event_trace_controller_win_unittest.cc',
'event_trace_provider_win_unittest.cc',
diff --git a/base/base.gypi b/base/base.gypi
index 75fcf5b..62b3de3 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -63,8 +63,8 @@
'dir_reader_fallback.h',
'dir_reader_linux.h',
'dir_reader_posix.h',
- 'env_var.cc',
- 'env_var.h',
+ 'environment.cc',
+ 'environment.h',
'event_trace_consumer_win.h',
'event_trace_controller_win.cc',
'event_trace_controller_win.h',
diff --git a/base/base_paths_posix.cc b/base/base_paths_posix.cc
index 710d799..8412009 100644
--- a/base/base_paths_posix.cc
+++ b/base/base_paths_posix.cc
@@ -12,7 +12,7 @@
#include <sys/sysctl.h>
#endif
-#include "base/env_var.h"
+#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
@@ -61,7 +61,7 @@ bool PathProviderPosix(int key, FilePath* result) {
case base::DIR_SOURCE_ROOT: {
// Allow passing this in the environment, for more flexibility in build
// tree configurations (sub-project builds, gyp --output_dir, etc.)
- scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ scoped_ptr<base::Environment> env(base::Environment::Create());
std::string cr_source_root;
if (env->GetEnv("CR_SOURCE_ROOT", &cr_source_root)) {
path = FilePath(cr_source_root);
@@ -104,7 +104,7 @@ bool PathProviderPosix(int key, FilePath* result) {
return false;
}
case base::DIR_USER_CACHE:
- scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ scoped_ptr<base::Environment> env(base::Environment::Create());
FilePath cache_dir(base::GetXDGDirectory(env.get(), "XDG_CACHE_HOME",
".cache"));
*result = cache_dir;
diff --git a/base/env_var.cc b/base/environment.cc
index 71d9c53..2ebdd43 100644
--- a/base/env_var.cc
+++ b/base/environment.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/env_var.h"
+#include "base/environment.h"
#if defined(OS_POSIX)
#include <stdlib.h>
@@ -19,7 +19,7 @@
namespace {
-class EnvVarGetterImpl : public base::EnvVarGetter {
+class EnvironmentImpl : public base::Environment {
public:
virtual bool GetEnv(const char* variable_name, std::string* result) {
if (GetEnvImpl(variable_name, result))
@@ -112,14 +112,14 @@ const char kHome[] = "HOME";
} // namespace env_vars
-EnvVarGetter::~EnvVarGetter() {}
+Environment::~Environment() {}
// static
-EnvVarGetter* EnvVarGetter::Create() {
- return new EnvVarGetterImpl();
+Environment* Environment::Create() {
+ return new EnvironmentImpl();
}
-bool EnvVarGetter::HasEnv(const char* variable_name) {
+bool Environment::HasEnv(const char* variable_name) {
return GetEnv(variable_name, NULL);
}
diff --git a/base/env_var.h b/base/environment.h
index 43d3fd6..a586ae8 100644
--- a/base/env_var.h
+++ b/base/environment.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_ENV_VAR_H_
-#define BASE_ENV_VAR_H_
+#ifndef BASE_ENVIRONMENT_H_
+#define BASE_ENVIRONMENT_H_
#pragma once
#include <string>
@@ -20,13 +20,13 @@ extern const char kHome[];
} // namespace env_vars
-class EnvVarGetter {
+class Environment {
public:
- virtual ~EnvVarGetter();
+ virtual ~Environment();
// Static factory method that returns the implementation that provide the
// appropriate platform-specific instance.
- static EnvVarGetter* Create();
+ static Environment* Create();
// Gets an environment variable's value and stores it in |result|.
// Returns false if the key is unset.
@@ -45,4 +45,4 @@ class EnvVarGetter {
} // namespace base
-#endif // BASE_ENV_VAR_H_
+#endif // BASE_ENVIRONMENT_H_
diff --git a/base/env_var_unittest.cc b/base/environment_unittest.cc
index f05a9b4..5b4ddc3 100644
--- a/base/env_var_unittest.cc
+++ b/base/environment_unittest.cc
@@ -2,29 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/env_var.h"
+#include "base/environment.h"
#include "base/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-typedef PlatformTest EnvVarTest;
+typedef PlatformTest EnvironmentTest;
-TEST_F(EnvVarTest, GetEnvVar) {
+TEST_F(EnvironmentTest, GetEnvVar) {
// Every setup should have non-empty PATH...
- scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ scoped_ptr<base::Environment> env(base::Environment::Create());
std::string env_value;
EXPECT_TRUE(env->GetEnv("PATH", &env_value));
EXPECT_NE(env_value, "");
}
-TEST_F(EnvVarTest, HasEnvVar) {
+TEST_F(EnvironmentTest, HasEnvVar) {
// Every setup should have PATH...
- scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ scoped_ptr<base::Environment> env(base::Environment::Create());
EXPECT_TRUE(env->HasEnv("PATH"));
}
-TEST_F(EnvVarTest, SetEnvVar) {
- scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+TEST_F(EnvironmentTest, SetEnvVar) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
const char kFooUpper[] = "FOO";
const char kFooLower[] = "foo";
@@ -38,8 +38,8 @@ TEST_F(EnvVarTest, SetEnvVar) {
EXPECT_EQ(var_value, kFooLower);
}
-TEST_F(EnvVarTest, UnSetEnvVar) {
- scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+TEST_F(EnvironmentTest, UnSetEnvVar) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
const char kFooUpper[] = "FOO";
const char kFooLower[] = "foo";
diff --git a/base/linux_util.cc b/base/linux_util.cc
index dda6333..b8c78e4 100644
--- a/base/linux_util.cc
+++ b/base/linux_util.cc
@@ -17,7 +17,6 @@
#include <vector>
#include "base/command_line.h"
-#include "base/env_var.h"
#include "base/file_util.h"
#include "base/lock.h"
#include "base/path_service.h"
diff --git a/base/linux_util.h b/base/linux_util.h
index 8216d40..45887db 100644
--- a/base/linux_util.h
+++ b/base/linux_util.h
@@ -15,8 +15,6 @@ class FilePath;
namespace base {
-class EnvVarGetter;
-
static const char kFindInodeSwitch[] = "--find-inode";
// Get the Linux Distro if we can, or return "Unknown", similar to
diff --git a/base/nss_util.cc b/base/nss_util.cc
index cc61bdf..0d7ec07 100644
--- a/base/nss_util.cc
+++ b/base/nss_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -28,7 +28,7 @@
// use NSS for crypto or certificate verification, and we don't use the NSS
// certificate and key databases.
#if defined(USE_NSS)
-#include "base/env_var.h"
+#include "base/environment.h"
#include "base/lock.h"
#include "base/scoped_ptr.h"
#endif // defined(USE_NSS)
@@ -80,7 +80,7 @@ void UseLocalCacheOfNSSDatabaseIfNFS(const FilePath& database_dir) {
struct statfs buf;
if (statfs(database_dir.value().c_str(), &buf) == 0) {
if (buf.f_type == NFS_SUPER_MAGIC) {
- scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
+ scoped_ptr<base::Environment> env(base::Environment::Create());
const char* use_cache_env_var = "NSS_SDB_USE_CACHE";
if (!env->HasEnv(use_cache_env_var))
env->SetEnv(use_cache_env_var, "yes");
diff --git a/base/xdg_util.cc b/base/xdg_util.cc
index 0ff6c47..426ef0e 100644
--- a/base/xdg_util.cc
+++ b/base/xdg_util.cc
@@ -4,14 +4,14 @@
#include "base/xdg_util.h"
-#include "base/env_var.h"
+#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h"
namespace base {
-FilePath GetXDGDirectory(EnvVarGetter* env, const char* env_name,
+FilePath GetXDGDirectory(Environment* env, const char* env_name,
const char* fallback_dir) {
std::string env_value;
if (env->GetEnv(env_name, &env_value) && !env_value.empty())
@@ -19,7 +19,7 @@ FilePath GetXDGDirectory(EnvVarGetter* env, const char* env_name,
return file_util::GetHomeDir().Append(fallback_dir);
}
-FilePath GetXDGUserDirectory(EnvVarGetter* env, const char* dir_name,
+FilePath GetXDGUserDirectory(Environment* env, const char* dir_name,
const char* fallback_dir) {
char* xdg_dir = xdg_user_dir_lookup(dir_name);
if (xdg_dir) {
@@ -30,7 +30,7 @@ FilePath GetXDGUserDirectory(EnvVarGetter* env, const char* dir_name,
return file_util::GetHomeDir().Append(fallback_dir);
}
-DesktopEnvironment GetDesktopEnvironment(EnvVarGetter* env) {
+DesktopEnvironment GetDesktopEnvironment(Environment* env) {
std::string desktop_session;
if (env->GetEnv("DESKTOP_SESSION", &desktop_session)) {
if (desktop_session == "gnome") {
@@ -76,7 +76,7 @@ const char* GetDesktopEnvironmentName(DesktopEnvironment env) {
return NULL;
}
-const char* GetDesktopEnvironmentName(EnvVarGetter* env) {
+const char* GetDesktopEnvironmentName(Environment* env) {
return GetDesktopEnvironmentName(GetDesktopEnvironment(env));
}
diff --git a/base/xdg_util.h b/base/xdg_util.h
index 33d81d8..c0788c8e 100644
--- a/base/xdg_util.h
+++ b/base/xdg_util.h
@@ -14,20 +14,20 @@ class FilePath;
namespace base {
-class EnvVarGetter;
+class Environment;
// Utility function for getting XDG directories.
// |env_name| is the name of an environment variable that we want to use to get
// a directory path. |fallback_dir| is the directory relative to $HOME that we
// use if |env_name| cannot be found or is empty. |fallback_dir| may be NULL.
// Examples of |env_name| are XDG_CONFIG_HOME and XDG_DATA_HOME.
-FilePath GetXDGDirectory(EnvVarGetter* env, const char* env_name,
+FilePath GetXDGDirectory(Environment* env, const char* env_name,
const char* fallback_dir);
// Wrapper around xdg_user_dir_lookup() from src/base/third_party/xdg-user-dirs
// This looks up "well known" user directories like the desktop and music
// folder. Examples of |dir_name| are DESKTOP and MUSIC.
-FilePath GetXDGUserDirectory(EnvVarGetter* env, const char* dir_name,
+FilePath GetXDGUserDirectory(Environment* env, const char* dir_name,
const char* fallback_dir);
enum DesktopEnvironment {
@@ -44,13 +44,13 @@ enum DesktopEnvironment {
// of which desktop environment we're using. We use this to know when
// to attempt to use preferences from the desktop environment --
// proxy settings, password manager, etc.
-DesktopEnvironment GetDesktopEnvironment(EnvVarGetter* env);
+DesktopEnvironment GetDesktopEnvironment(Environment* env);
// Return a string representation of the given desktop environment.
// May return NULL in the case of DESKTOP_ENVIRONMENT_OTHER.
const char* GetDesktopEnvironmentName(DesktopEnvironment env);
// Convenience wrapper that calls GetDesktopEnvironment() first.
-const char* GetDesktopEnvironmentName(EnvVarGetter* env);
+const char* GetDesktopEnvironmentName(Environment* env);
} // namespace base
diff --git a/base/xdg_util_unittest.cc b/base/xdg_util_unittest.cc
index 24671b1..c876466 100644
--- a/base/xdg_util_unittest.cc
+++ b/base/xdg_util_unittest.cc
@@ -4,7 +4,7 @@
#include "base/xdg_util.h"
-#include "base/env_var.h"
+#include "base/environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,7 +15,7 @@ using ::testing::StrEq;
namespace {
-class MockEnvVarGetter : public base::EnvVarGetter {
+class MockEnvironment : public base::Environment {
public:
MOCK_METHOD2(GetEnv, bool(const char*, std::string* result));
MOCK_METHOD2(SetEnv, bool(const char*, const std::string& new_value));
@@ -30,7 +30,7 @@ const char* kXFCE = "xfce";
} // namespace
TEST(XDGUtilTest, GetDesktopEnvironmentGnome) {
- MockEnvVarGetter getter;
+ MockEnvironment getter;
EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kGnome), Return(true)));
@@ -40,7 +40,7 @@ TEST(XDGUtilTest, GetDesktopEnvironmentGnome) {
}
TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) {
- MockEnvVarGetter getter;
+ MockEnvironment getter;
EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kKDE4), Return(true)));
@@ -50,7 +50,7 @@ TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) {
}
TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) {
- MockEnvVarGetter getter;
+ MockEnvironment getter;
EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kKDE), Return(true)));
@@ -60,7 +60,7 @@ TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) {
}
TEST(XDGUtilTest, GetDesktopEnvironmentXFCE) {
- MockEnvVarGetter getter;
+ MockEnvironment getter;
EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
.WillOnce(DoAll(SetArgumentPointee<1>(kXFCE), Return(true)));