Chromium Code Reviews| Index: net/disk_cache/disk_cache_test_util.cc |
| =================================================================== |
| --- net/disk_cache/disk_cache_test_util.cc (revision 12520) |
| +++ net/disk_cache/disk_cache_test_util.cc (working copy) |
| @@ -14,6 +14,20 @@ |
| using base::Time; |
| using base::TimeDelta; |
| +namespace { |
| + |
| +std::wstring BuildCachePath(const std::wstring name) { |
|
Alpha Left Google
2009/03/26 00:08:12
Can we name this function GetCachePath(const std::
|
| + std::wstring path; |
| + PathService::Get(base::DIR_TEMP, &path); |
| + file_util::AppendToPath(&path, name); |
| + if (!file_util::PathExists(path)) |
| + file_util::CreateDirectory(path); |
| + |
| + return path; |
| +} |
| + |
| +} // namespace. |
| + |
| std::string GenerateKey(bool same_length) { |
| char key[200]; |
| CacheTestFillBuffer(key, sizeof(key), same_length); |
| @@ -40,13 +54,7 @@ |
| } |
| std::wstring GetCachePath() { |
| - std::wstring path; |
| - PathService::Get(base::DIR_TEMP, &path); |
| - file_util::AppendToPath(&path, L"cache_test"); |
| - if (!file_util::PathExists(path)) |
| - file_util::CreateDirectory(path); |
| - |
| - return path; |
| + return BuildCachePath(L"cache_test"); |
| } |
| bool CreateCacheTestFile(const wchar_t* name) { |
| @@ -83,6 +91,12 @@ |
| DCHECK(result); |
| } |
| +ScopedTestCache::ScopedTestCache(const std::wstring& name) |
| + : path_(BuildCachePath(name)) { |
| + bool result = DeleteCache(path_.c_str()); |
| + DCHECK(result); |
| +} |
| + |
| ScopedTestCache::~ScopedTestCache() { |
| file_util::Delete(path(), true); |
| } |