forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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@67191 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
evan@chromium.org
committed
Nov 24, 2010
1 parent
54c8336
commit 8c61914
Showing
13 changed files
with
123 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters