Skip to content

Commit

Permalink
base: Rename EnvVarGetter to Environment.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tfarina@chromium.org committed Aug 3, 2010
1 parent 7f2a9db commit 76b90d3
Show file tree
Hide file tree
Showing 48 changed files with 192 additions and 197 deletions.
4 changes: 2 additions & 2 deletions app/gtk_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <gtk/gtk.h>

#include "app/l10n_util.h"
#include "base/env_var.h"
#include "base/environment.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/xdg_util.h"
Expand Down Expand Up @@ -77,7 +77,7 @@ void GetWidgetSizeFromCharacters(
void ApplyMessageDialogQuirks(GtkWidget* dialog) {
if (gtk_window_get_modal(GTK_WINDOW(dialog))) {
// Work around a KDE 3 window manager bug.
scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
scoped_ptr<base::Environment> env(base::Environment::Create());
if (base::DESKTOP_ENVIRONMENT_KDE3 == GetDesktopEnvironment(env.get()))
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
}
Expand Down
4 changes: 2 additions & 2 deletions app/l10n_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "app/test/data/resource.h"
#endif
#include "base/basictypes.h"
#include "base/env_var.h"
#include "base/environment.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/stl_util-inl.h"
Expand Down Expand Up @@ -139,7 +139,7 @@ TEST_F(L10nUtilTest, GetAppLocale) {
icu::Locale locale = icu::Locale::getDefault();

#if defined(OS_POSIX) && !defined(OS_CHROMEOS)
scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
scoped_ptr<base::Environment> env(base::Environment::Create());

// Test the support of LANGUAGE environment variable.
SetICUDefaultLocale("en-US");
Expand Down
4 changes: 2 additions & 2 deletions base/base.gyp
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions base/base.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions base/base_paths_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions base/env_var.cc → base/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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))
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions base/env_var.h → base/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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.
Expand All @@ -45,4 +45,4 @@ class EnvVarGetter {

} // namespace base

#endif // BASE_ENV_VAR_H_
#endif // BASE_ENVIRONMENT_H_
20 changes: 10 additions & 10 deletions base/env_var_unittest.cc → base/environment_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
1 change: 0 additions & 1 deletion base/linux_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions base/linux_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions base/nss_util.cc
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions base/xdg_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

#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())
return FilePath(env_value);
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) {
Expand All @@ -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") {
Expand Down Expand Up @@ -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));
}

Expand Down
10 changes: 5 additions & 5 deletions base/xdg_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand Down
12 changes: 6 additions & 6 deletions base/xdg_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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));
Expand All @@ -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)));
Expand All @@ -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)));
Expand All @@ -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)));
Expand All @@ -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)));
Expand Down
Loading

0 comments on commit 76b90d3

Please sign in to comment.