diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-16 04:56:06 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-16 04:56:06 +0000 |
commit | 6b0349ef4ab90a6b99fc568f40e872a7f2ca39c9 (patch) | |
tree | 9ba478afe564003c74927c1530741846f6aa1336 /base | |
parent | b679032aef9317482f87ceaf67ee138aaa67a152 (diff) | |
download | chromium_src-6b0349ef4ab90a6b99fc568f40e872a7f2ca39c9.zip chromium_src-6b0349ef4ab90a6b99fc568f40e872a7f2ca39c9.tar.gz chromium_src-6b0349ef4ab90a6b99fc568f40e872a7f2ca39c9.tar.bz2 |
Move xdg_util into base/nix. I originally wanted to use base/linux, but you
can't have a namespace called "linux" because it's ifdefed by GCC to be a
number. Same for "unix". "x11" was discarded because some future stuff in
here will not be related to x11.
This also renames base_paths_posix to base_paths_linux since this does not
apply to mac, and normally posix applies to mac (this confused me when I had to
edit it for the XDG stuff).
TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/3778007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62848 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gyp | 2 | ||||
-rw-r--r-- | base/base.gypi | 10 | ||||
-rw-r--r-- | base/base_paths_linux.cc (renamed from base/base_paths_posix.cc) | 20 | ||||
-rw-r--r-- | base/nix/xdg_util.cc (renamed from base/xdg_util.cc) | 4 | ||||
-rw-r--r-- | base/nix/xdg_util.h (renamed from base/xdg_util.h) | 20 | ||||
-rw-r--r-- | base/nix/xdg_util_unittest.cc (renamed from base/xdg_util_unittest.cc) | 26 |
6 files changed, 50 insertions, 32 deletions
diff --git a/base/base.gyp b/base/base.gyp index dee0040..e432815 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -189,7 +189,7 @@ 'worker_pool_linux_unittest.cc', ], 'sources': [ - 'xdg_util_unittest.cc', + 'nix/xdg_util_unittest.cc', ], 'dependencies': [ '../build/linux/system.gyp:gtk', diff --git a/base/base.gypi b/base/base.gypi index fee14af..b608e82 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -31,7 +31,7 @@ 'base_paths.h', 'base_paths_mac.h', 'base_paths_mac.mm', - 'base_paths_posix.cc', + 'base_paths_linux.cc', 'base_paths_win.cc', 'base_paths_win.h', 'base_switches.cc', @@ -315,8 +315,8 @@ 'worker_pool_mac.h', 'worker_pool_mac.mm', 'worker_pool_win.cc', - 'xdg_util.h', - 'xdg_util.cc', + 'nix/xdg_util.h', + 'nix/xdg_util.cc', ], 'include_dirs': [ '..', @@ -331,13 +331,11 @@ 'conditions': [ [ 'OS != "linux" and OS != "freebsd" and OS != "openbsd" and OS != "solaris"', { 'sources/': [ - ['exclude', '/xdg_[^/]*\\.cc$'], + ['exclude', '^nix/'], ], 'sources!': [ 'atomicops_internals_x86_gcc.cc', - 'base_paths_posix.cc', 'message_pump_glib.cc', - 'xdg_util.cc', ], }], [ 'OS != "linux"', { diff --git a/base/base_paths_posix.cc b/base/base_paths_linux.cc index 45b397e..6d837f2 100644 --- a/base/base_paths_posix.cc +++ b/base/base_paths_linux.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// This is really Posix minus Mac. Mac code is in base_paths_mac.mm. - #include "base/base_paths.h" #include <unistd.h> @@ -19,7 +17,7 @@ #include "base/path_service.h" #include "base/scoped_ptr.h" #include "base/sys_string_conversions.h" -#include "base/xdg_util.h" +#include "base/nix/xdg_util.h" namespace base { @@ -29,6 +27,10 @@ const char kSelfExe[] = "/proc/self/exe"; const char kSelfExe[] = getexecname(); #endif +// The name of this file relative to the source root. This is used for checking +// that the source checkout is in the correct place. +static const char kThisSourceFile[] = "base/base_paths_linux.cc"; + bool PathProviderPosix(int key, FilePath* result) { FilePath path; switch (key) { @@ -65,7 +67,7 @@ bool PathProviderPosix(int key, FilePath* result) { std::string cr_source_root; if (env->GetVar("CR_SOURCE_ROOT", &cr_source_root)) { path = FilePath(cr_source_root); - if (file_util::PathExists(path.Append("base/base_paths_posix.cc"))) { + if (file_util::PathExists(path.Append(kThisSourceFile))) { *result = path; return true; } else { @@ -77,7 +79,7 @@ bool PathProviderPosix(int key, FilePath* result) { // For example: sconsbuild/{Debug|Release}/net_unittest if (PathService::Get(base::DIR_EXE, &path)) { path = path.DirName().DirName(); - if (file_util::PathExists(path.Append("base/base_paths_posix.cc"))) { + if (file_util::PathExists(path.Append(kThisSourceFile))) { *result = path; return true; } @@ -87,7 +89,7 @@ bool PathProviderPosix(int key, FilePath* result) { // for DIR_SOURCE_ROOT. if (PathService::Get(base::DIR_EXE, &path)) { path = path.DirName().DirName().Append("WebKit/chromium"); - if (file_util::PathExists(path.Append("base/base_paths_posix.cc"))) { + if (file_util::PathExists(path.Append(kThisSourceFile))) { *result = path; return true; } @@ -95,7 +97,7 @@ bool PathProviderPosix(int key, FilePath* result) { // If that failed (maybe the build output is symlinked to a different // drive) try assuming the current directory is the source root. if (file_util::GetCurrentDirectory(&path) && - file_util::PathExists(path.Append("base/base_paths_posix.cc"))) { + file_util::PathExists(path.Append(kThisSourceFile))) { *result = path; return true; } @@ -105,8 +107,8 @@ bool PathProviderPosix(int key, FilePath* result) { } case base::DIR_USER_CACHE: scoped_ptr<base::Environment> env(base::Environment::Create()); - FilePath cache_dir(base::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", - ".cache")); + FilePath cache_dir(base::nix::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", + ".cache")); *result = cache_dir; return true; } diff --git a/base/xdg_util.cc b/base/nix/xdg_util.cc index 017ae7a..b39a07d 100644 --- a/base/xdg_util.cc +++ b/base/nix/xdg_util.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/xdg_util.h" +#include "base/nix/xdg_util.h" #include "base/environment.h" #include "base/file_path.h" @@ -10,6 +10,7 @@ #include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h" namespace base { +namespace nix { FilePath GetXDGDirectory(Environment* env, const char* env_name, const char* fallback_dir) { @@ -80,4 +81,5 @@ const char* GetDesktopEnvironmentName(Environment* env) { return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); } +} // namespace nix } // namespace base diff --git a/base/xdg_util.h b/base/nix/xdg_util.h index c0788c8e..5e711d5 100644 --- a/base/xdg_util.h +++ b/base/nix/xdg_util.h @@ -2,13 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef BASE_XDG_UTIL_H_ -#define BASE_XDG_UTIL_H_ +#ifndef BASE_NIX_XDG_UTIL_H_ +#define BASE_NIX_XDG_UTIL_H_ #pragma once // XDG refers to http://en.wikipedia.org/wiki/Freedesktop.org . -// This file contains utilities found across free desktop -// environments. +// This file contains utilities found across free desktop environments. +// +// TODO(brettw) this file should be in app/x11, but is currently used by +// net. We should have a net API to allow the embedder to specify the behavior +// that it uses XDG for, and then move this file. + +#ifdef nix +#error asdf +#endif class FilePath; @@ -16,6 +23,8 @@ namespace base { class Environment; +namespace nix { + // 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 @@ -52,6 +61,7 @@ const char* GetDesktopEnvironmentName(DesktopEnvironment env); // Convenience wrapper that calls GetDesktopEnvironment() first. const char* GetDesktopEnvironmentName(Environment* env); +} // namespace nix } // namespace base -#endif // BASE_XDG_UTIL_H_ +#endif // BASE_NIX_XDG_UTIL_H_ diff --git a/base/xdg_util_unittest.cc b/base/nix/xdg_util_unittest.cc index c33fca5..2fc9d4c 100644 --- a/base/xdg_util_unittest.cc +++ b/base/nix/xdg_util_unittest.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/xdg_util.h" +#include "base/nix/xdg_util.h" #include "base/environment.h" #include "testing/gmock/include/gmock/gmock.h" @@ -13,9 +13,12 @@ using ::testing::Return; using ::testing::SetArgumentPointee; using ::testing::StrEq; +namespace base { +namespace nix { + namespace { -class MockEnvironment : public base::Environment { +class MockEnvironment : public Environment { public: MOCK_METHOD2(GetVar, bool(const char*, std::string* result)); MOCK_METHOD2(SetVar, bool(const char*, const std::string& new_value)); @@ -35,8 +38,8 @@ TEST(XDGUtilTest, GetDesktopEnvironmentGnome) { EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _)) .WillOnce(DoAll(SetArgumentPointee<1>(kGnome), Return(true))); - EXPECT_EQ(base::DESKTOP_ENVIRONMENT_GNOME, - base::GetDesktopEnvironment(&getter)); + EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, + GetDesktopEnvironment(&getter)); } TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) { @@ -45,8 +48,8 @@ TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) { EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _)) .WillOnce(DoAll(SetArgumentPointee<1>(kKDE4), Return(true))); - EXPECT_EQ(base::DESKTOP_ENVIRONMENT_KDE4, - base::GetDesktopEnvironment(&getter)); + EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE4, + GetDesktopEnvironment(&getter)); } TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) { @@ -55,8 +58,8 @@ TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) { EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _)) .WillOnce(DoAll(SetArgumentPointee<1>(kKDE), Return(true))); - EXPECT_EQ(base::DESKTOP_ENVIRONMENT_KDE3, - base::GetDesktopEnvironment(&getter)); + EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE3, + GetDesktopEnvironment(&getter)); } TEST(XDGUtilTest, GetDesktopEnvironmentXFCE) { @@ -65,6 +68,9 @@ TEST(XDGUtilTest, GetDesktopEnvironmentXFCE) { EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _)) .WillOnce(DoAll(SetArgumentPointee<1>(kXFCE), Return(true))); - EXPECT_EQ(base::DESKTOP_ENVIRONMENT_XFCE, - base::GetDesktopEnvironment(&getter)); + EXPECT_EQ(DESKTOP_ENVIRONMENT_XFCE, + GetDesktopEnvironment(&getter)); } + +} // namespace nix +} // namespace base |