diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 21:50:20 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 21:50:20 +0000 |
commit | 953d7c97a53427d5639728027208c9cb23e52ddd (patch) | |
tree | 308b4b7a6507edf684fe9fdbce11a31e040cfa78 /chrome/common/chrome_paths_unittest.cc | |
parent | cf667c88932398fc44e4821fc6d0b7d88c63a1cd (diff) | |
download | chromium_src-953d7c97a53427d5639728027208c9cb23e52ddd.zip chromium_src-953d7c97a53427d5639728027208c9cb23e52ddd.tar.gz chromium_src-953d7c97a53427d5639728027208c9cb23e52ddd.tar.bz2 |
chrome_paths: refactor and sanitize cache directory handling
Previously we had a bunch of logic in profile_impl.cc that computed
where the cache directory lives. This change relocates it to
chrome_paths.cc.
Some background on cache directories.
There are two possible places to store cache files:
1) in the user data directory
2) in an OS-specific user cache directory
On Windows, we always pick (1). On Mac and Linux, we currently use
(2) in some circumstances. This patch changes both Mac and Linux to
have the same behavior with respect to (2).
The Mac/Linux shared behavior is that if the profile directory
is in the standard location for profiles, we put the cache files
into a matching directory name in the standard system cache directory
(e.g. on Linux if you're using ~/.config/google-chrome, your cache
ends up in ~/.cache/google-chrome; on Mac, the directories are
~/Library/Application Support versus ~/Library/Caches). If your user
data directory is not in the standard location, we use behavior (1).
The semantic changes of this patch should be:
- On Mac, previously we checked whether the (2) directory had some
particular subdirectories already when picking which one to use.
This was removed; which directory is used is solely a question of
whether the profile directory is in the standard location.
I think the previous behavior was unpredictable.
- On Linux, previously we only used behavior (2) if you hadn't changed
your user-data-directory at all. Now, to match Mac, as long as
your user-data-dir is in the standard place, you use the system
cache dir. So e.g. using ~/.config/foobar puts your cache in
~/.cache/foobar.
- On Linux, previously the default cache would end up as directories
under ~/.cache/google-chrome/; now it ends up as directories under
~/.cache/google-chrome/Default/.
(In all instances above, on Linux we continue to obey $XDG_CACHE_HOME.)
BUG=59824
TEST=New test ChromePaths.UserCacheDir
Review URL: http://codereview.chromium.org/5123004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/chrome_paths_unittest.cc')
-rw-r--r-- | chrome/common/chrome_paths_unittest.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/chrome/common/chrome_paths_unittest.cc b/chrome/common/chrome_paths_unittest.cc new file mode 100644 index 0000000..23bc7d4 --- /dev/null +++ b/chrome/common/chrome_paths_unittest.cc @@ -0,0 +1,44 @@ +// 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. + +#include "chrome/common/chrome_paths_internal.h" + +#include <stdlib.h> + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "testing/gtest/include/gtest/gtest.h" + +// Test the behavior of chrome::GetUserCacheDirectory. +// See that function's comments for discussion of the subtleties. +TEST(ChromePaths, UserCacheDir) { + FilePath test_profile_dir, cache_dir; +#if defined(OS_MACOSX) + ASSERT_TRUE(PathService::Get(base::DIR_APP_DATA, &test_profile_dir)); + test_profile_dir = test_profile_dir.Append("foobar"); + FilePath expected_cache_dir; + ASSERT_TRUE(PathService::Get(base::DIR_CACHE, &expected_cache_dir)); + expected_cache_dir = expected_cache_dir.Append("foobar"); +#elif(OS_POSIX) + FilePath homedir = file_util::GetHomeDir(); + // Note: we assume XDG_CACHE_HOME/XDG_CONFIG_HOME are at their + // default settings. + test_profile_dir = homedir.Append(".config/foobar"); + FilePath expected_cache_dir = homedir.Append(".cache/foobar"); +#endif + + // Verify that a profile in the special platform-specific source + // location ends up in the special target location. +#if !defined(OS_WIN) // No special behavior on Windows. + chrome::GetUserCacheDirectory(test_profile_dir, &cache_dir); + EXPECT_EQ(expected_cache_dir.value(), cache_dir.value()); +#endif + + // Verify that a profile in some other random directory doesn't use + // the special cache dir. + test_profile_dir = FilePath(FILE_PATH_LITERAL("/some/other/path")); + chrome::GetUserCacheDirectory(test_profile_dir, &cache_dir); + EXPECT_EQ(test_profile_dir.value(), cache_dir.value()); +} |