diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 17:38:04 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 17:38:04 +0000 |
commit | 5306d118a2880703b2e7d24d1267f7c3e67b376b (patch) | |
tree | 984510292dc91259dad06882d659a36fb337127a /net/disk_cache | |
parent | 42b8c0b39acc727cf56fe6e77dc9d62b6e15e25f (diff) | |
download | chromium_src-5306d118a2880703b2e7d24d1267f7c3e67b376b.zip chromium_src-5306d118a2880703b2e7d24d1267f7c3e67b376b.tar.gz chromium_src-5306d118a2880703b2e7d24d1267f7c3e67b376b.tar.bz2 |
Final patch to convert disk cache to using FilePath instead of
wstring. After this patch, I'm able to start chrome in a
user data dir with non-ascii characters on non-utf8 systems.
BUG=24444
Review URL: http://codereview.chromium.org/267085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 16 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.h | 2 | ||||
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 33 | ||||
-rw-r--r-- | net/disk_cache/block_files_unittest.cc | 10 | ||||
-rw-r--r-- | net/disk_cache/disk_cache.h | 4 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_perftest.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_base.cc | 12 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 33 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.h | 24 | ||||
-rw-r--r-- | net/disk_cache/stress_cache.cc | 6 |
10 files changed, 59 insertions, 85 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 1dc439a..03da960 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -170,7 +170,7 @@ void SetFieldTrialInfo(int size_group) { namespace disk_cache { -Backend* CreateCacheBackend(const std::wstring& full_path, bool force, +Backend* CreateCacheBackend(const FilePath& full_path, bool force, int max_bytes, net::CacheType type) { // Create a backend without extra flags. return BackendImpl::CreateBackend(full_path, force, max_bytes, type, kNone); @@ -214,11 +214,10 @@ int PreferedCacheSize(int64 available) { // desired path) cannot be created. // // Static. -Backend* BackendImpl::CreateBackend(const std::wstring& full_path, bool force, +Backend* BackendImpl::CreateBackend(const FilePath& full_path, bool force, int max_bytes, net::CacheType type, BackendFlags flags) { - FilePath full_cache_path = FilePath::FromWStringHack(full_path); - BackendImpl* cache = new BackendImpl(full_cache_path); + BackendImpl* cache = new BackendImpl(full_path); cache->SetMaxSize(max_bytes); cache->SetType(type); cache->SetFlags(flags); @@ -229,12 +228,12 @@ Backend* BackendImpl::CreateBackend(const std::wstring& full_path, bool force, if (!force) return NULL; - if (!DelayedCacheCleanup(full_cache_path)) + if (!DelayedCacheCleanup(full_path)) return NULL; // The worker thread will start deleting files soon, but the original folder // is not there anymore... let's create a new set of files. - cache = new BackendImpl(full_cache_path); + cache = new BackendImpl(full_path); cache->SetMaxSize(max_bytes); cache->SetType(type); cache->SetFlags(flags); @@ -644,7 +643,7 @@ bool BackendImpl::CreateExternalFile(Addr* address) { base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_EXCLUSIVE_WRITE; scoped_refptr<disk_cache::File> file(new disk_cache::File( - base::CreatePlatformFile(name.ToWStringHack().c_str(), flags, NULL))); + base::CreatePlatformFile(name, flags, NULL))); if (!file->IsValid()) continue; @@ -996,8 +995,7 @@ bool BackendImpl::InitBackingStore(bool* file_created) { base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_EXCLUSIVE_WRITE; scoped_refptr<disk_cache::File> file(new disk_cache::File( - base::CreatePlatformFile(index_name.ToWStringHack().c_str(), flags, - file_created))); + base::CreatePlatformFile(index_name, flags, file_created))); if (!file->IsValid()) return false; diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h index 85075db..283256d 100644 --- a/net/disk_cache/backend_impl.h +++ b/net/disk_cache/backend_impl.h @@ -52,7 +52,7 @@ class BackendImpl : public Backend { // Returns a new backend with the desired flags. See the declaration of // CreateCacheBackend(). - static Backend* CreateBackend(const std::wstring& full_path, bool force, + static Backend* CreateBackend(const FilePath& full_path, bool force, int max_bytes, net::CacheType type, BackendFlags flags); diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 27b091b..5fc4653 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -28,10 +28,10 @@ bool CopyTestCache(const std::wstring& name) { path = path.AppendASCII("cache_tests"); path = path.Append(FilePath::FromWStringHack(name)); - std::wstring dest = GetCachePath(); - if (!DeleteCache(dest.c_str())) + FilePath dest = GetCacheFilePath(); + if (!DeleteCache(dest)) return false; - return file_util::CopyDirectory(path, FilePath::FromWStringHack(dest), false); + return file_util::CopyDirectory(path, dest, false); } } // namespace @@ -188,8 +188,7 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) { TEST_F(DiskCacheBackendTest, ExternalFiles) { InitCache(); // First, lets create a file on the folder. - std::wstring filename = GetCachePath(); - file_util::AppendToPath(&filename, L"f_000001"); + FilePath filename = GetCacheFilePath().AppendASCII("f_000001"); const int kSize = 50; scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); @@ -212,8 +211,8 @@ TEST_F(DiskCacheTest, ShutdownWithPendingIO) { SimpleCallbackTest callback; { - std::wstring path = GetCachePath(); - ASSERT_TRUE(DeleteCache(path.c_str())); + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0, net::DISK_CACHE); @@ -985,7 +984,7 @@ void DiskCacheBackendTest::BackendTransaction(const std::wstring& name, cache_ = NULL; cache_impl_ = NULL; - ASSERT_TRUE(CheckCacheIntegrity(GetCachePath(), new_eviction_)); + ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_)); success_ = true; } @@ -1076,7 +1075,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) { // Tests dealing with cache files that cannot be recovered. TEST_F(DiskCacheTest, Backend_DeleteOld) { ASSERT_TRUE(CopyTestCache(L"wrong_version")); - std::wstring path = GetCachePath(); + FilePath path = GetCacheFilePath(); scoped_ptr<disk_cache::Backend> cache; cache.reset(disk_cache::CreateCacheBackend(path, true, 0, net::DISK_CACHE)); @@ -1147,7 +1146,7 @@ TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { // We want to be able to deal with messed up entries on disk. void DiskCacheBackendTest::BackendInvalidRankings2() { ASSERT_TRUE(CopyTestCache(L"bad_rankings")); - std::wstring path = GetCachePath(); + FilePath path = GetCacheFilePath(); DisableFirstCleanup(); InitCache(); @@ -1428,10 +1427,10 @@ TEST_F(DiskCacheBackendTest, DISABLED_NewEvictionDisableSuccess4) { TEST_F(DiskCacheTest, Backend_UsageStats) { MessageLoopHelper helper; - std::wstring path = GetCachePath(); - ASSERT_TRUE(DeleteCache(path.c_str())); + FilePath path = GetCacheFilePath(); + ASSERT_TRUE(DeleteCache(path)); scoped_ptr<disk_cache::BackendImpl> cache; - cache.reset(new disk_cache::BackendImpl(FilePath::FromWStringHack(path))); + cache.reset(new disk_cache::BackendImpl(path)); ASSERT_TRUE(NULL != cache.get()); cache->SetUnitTestMode(); ASSERT_TRUE(cache->Init()); @@ -1529,15 +1528,15 @@ TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { // of the cache. TEST_F(DiskCacheTest, MultipleInstances) { ScopedTestCache store1; - ScopedTestCache store2(L"cache_test2"); - ScopedTestCache store3(L"cache_test3"); + ScopedTestCache store2("cache_test2"); + ScopedTestCache store3("cache_test3"); const int kNumberOfCaches = 2; scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; - cache[0].reset(disk_cache::CreateCacheBackend(store1.path_wstring(), false, 0, + cache[0].reset(disk_cache::CreateCacheBackend(store1.path(), false, 0, net::DISK_CACHE)); - cache[1].reset(disk_cache::CreateCacheBackend(store2.path_wstring(), false, 0, + cache[1].reset(disk_cache::CreateCacheBackend(store2.path(), false, 0, net::MEDIA_CACHE)); ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL); diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc index 322c10c..054641c 100644 --- a/net/disk_cache/block_files_unittest.cc +++ b/net/disk_cache/block_files_unittest.cc @@ -28,7 +28,7 @@ int NumberOfFiles(const FilePath& path) { namespace disk_cache { TEST_F(DiskCacheTest, BlockFiles_Grow) { - FilePath path = FilePath::FromWStringHack(GetCachePath()); + FilePath path = GetCacheFilePath(); ASSERT_TRUE(DeleteCache(path)); ASSERT_TRUE(file_util::CreateDirectory(path)); @@ -55,7 +55,7 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) { // We should be able to delete empty block files. TEST_F(DiskCacheTest, BlockFiles_Shrink) { - FilePath path = FilePath::FromWStringHack(GetCachePath()); + FilePath path = GetCacheFilePath(); ASSERT_TRUE(DeleteCache(path)); ASSERT_TRUE(file_util::CreateDirectory(path)); @@ -79,7 +79,7 @@ TEST_F(DiskCacheTest, BlockFiles_Shrink) { // Handling of block files not properly closed. TEST_F(DiskCacheTest, BlockFiles_Recover) { - FilePath path = FilePath::FromWStringHack(GetCachePath()); + FilePath path = GetCacheFilePath(); ASSERT_TRUE(DeleteCache(path)); ASSERT_TRUE(file_util::CreateDirectory(path)); @@ -157,7 +157,7 @@ TEST_F(DiskCacheTest, BlockFiles_Recover) { // Handling of truncated files. TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) { - FilePath path = FilePath::FromWStringHack(GetCachePath()); + FilePath path = GetCacheFilePath(); ASSERT_TRUE(DeleteCache(path)); ASSERT_TRUE(file_util::CreateDirectory(path)); @@ -179,7 +179,7 @@ TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) { // An invalid file can be detected after init. TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { - FilePath path = FilePath::FromWStringHack(GetCachePath()); + FilePath path = GetCacheFilePath(); ASSERT_TRUE(DeleteCache(path)); ASSERT_TRUE(file_util::CreateDirectory(path)); diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h index 04c08d6..a322021 100644 --- a/net/disk_cache/disk_cache.h +++ b/net/disk_cache/disk_cache.h @@ -16,6 +16,8 @@ #include "net/base/cache_type.h" #include "net/base/completion_callback.h" +class FilePath; + namespace net { class IOBuffer; } @@ -34,7 +36,7 @@ class Backend; // If zero is passed in as max_bytes, the cache will determine the value to use // based on the available disk space. The returned pointer can be NULL if a // fatal error is found. -Backend* CreateCacheBackend(const std::wstring& path, bool force, +Backend* CreateCacheBackend(const FilePath& path, bool force, int max_bytes, net::CacheType type); // Returns an instance of a Backend implemented only in memory. The returned diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc index e216d69..4064341 100644 --- a/net/disk_cache/disk_cache_perftest.cc +++ b/net/disk_cache/disk_cache_perftest.cc @@ -156,7 +156,7 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) { ScopedTestCache test_cache; disk_cache::Backend* cache = - disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0, + disk_cache::CreateCacheBackend(test_cache.path(), false, 0, net::DISK_CACHE); ASSERT_TRUE(NULL != cache); @@ -183,7 +183,7 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) { ASSERT_TRUE(file_util::EvictFileFromSystemCache( test_cache.path().AppendASCII("data_3"))); - cache = disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0, + cache = disk_cache::CreateCacheBackend(test_cache.path(), false, 0, net::DISK_CACHE); ASSERT_TRUE(NULL != cache); diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc index e2ced30..21352a2 100644 --- a/net/disk_cache/disk_cache_test_base.cc +++ b/net/disk_cache/disk_cache_test_base.cc @@ -52,12 +52,12 @@ void DiskCacheTestWithCache::InitMemoryCache() { } void DiskCacheTestWithCache::InitDiskCache() { - std::wstring path = GetCachePath(); + FilePath path = GetCacheFilePath(); if (first_cleanup_) - ASSERT_TRUE(DeleteCache(path.c_str())); + ASSERT_TRUE(DeleteCache(path)); if (implementation_) - return InitDiskCacheImpl(FilePath::FromWStringHack(path)); + return InitDiskCacheImpl(path); cache_ = disk_cache::BackendImpl::CreateBackend(path, force_creation_, size_, net::DISK_CACHE, @@ -88,7 +88,7 @@ void DiskCacheTestWithCache::TearDown() { delete cache_; if (!memory_only_ && integrity_) { - std::wstring path = GetCachePath(); + FilePath path = GetCacheFilePath(); EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); } @@ -101,10 +101,10 @@ void DiskCacheTestWithCache::SimulateCrash() { cache_impl_->ClearRefCountForTest(); delete cache_impl_; - std::wstring path = GetCachePath(); + FilePath path = GetCacheFilePath(); EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); - InitDiskCacheImpl(FilePath::FromWStringHack(path)); + InitDiskCacheImpl(path); } void DiskCacheTestWithCache::SetTestMode() { diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index f16c578..2293a5e 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -17,14 +17,14 @@ using base::TimeDelta; namespace { -std::wstring BuildCachePath(const std::wstring& name) { +FilePath BuildCachePath(const std::string& name) { FilePath path; PathService::Get(base::DIR_TEMP, &path); // Ignore return value; - path = path.Append(FilePath::FromWStringHack(name)); + path = path.AppendASCII(name); if (!file_util::PathExists(path)) file_util::CreateDirectory(path); - return path.ToWStringHack(); + return path; } } // namespace. @@ -54,12 +54,8 @@ void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls) { buffer[0] = 'g'; } -std::wstring GetCachePath() { - return BuildCachePath(L"cache_test"); -} - FilePath GetCacheFilePath() { - return FilePath::FromWStringHack(GetCachePath()); + return BuildCachePath("cache_test"); } bool CreateCacheTestFile(const FilePath& name) { @@ -76,22 +72,13 @@ bool CreateCacheTestFile(const FilePath& name) { return true; } -bool CreateCacheTestFile(const wchar_t* name) { - return CreateCacheTestFile(FilePath::FromWStringHack(name)); -} - bool DeleteCache(const FilePath& path) { disk_cache::DeleteCache(path, false); return true; } -bool DeleteCache(const wchar_t* path) { - return DeleteCache(FilePath::FromWStringHack(path)); -} - -bool CheckCacheIntegrity(const std::wstring& path, bool new_eviction) { - scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( - FilePath::FromWStringHack(path))); +bool CheckCacheIntegrity(const FilePath& path, bool new_eviction) { + scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl(path)); if (!cache.get()) return false; if (new_eviction) @@ -102,14 +89,14 @@ bool CheckCacheIntegrity(const std::wstring& path, bool new_eviction) { return cache->SelfCheck() >= 0; } -ScopedTestCache::ScopedTestCache() : path_(GetCachePath()) { - bool result = DeleteCache(path_.c_str()); +ScopedTestCache::ScopedTestCache() : path_(GetCacheFilePath()) { + bool result = DeleteCache(path_); DCHECK(result); } -ScopedTestCache::ScopedTestCache(const std::wstring& name) +ScopedTestCache::ScopedTestCache(const std::string& name) : path_(BuildCachePath(name)) { - bool result = DeleteCache(path_.c_str()); + bool result = DeleteCache(path_); DCHECK(result); } diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h index f680470..8e980ab 100644 --- a/net/disk_cache/disk_cache_test_util.h +++ b/net/disk_cache/disk_cache_test_util.h @@ -11,51 +11,41 @@ #include "base/message_loop.h" #include "base/task.h" #include "base/timer.h" +#include "build/build_config.h" #include "net/base/test_completion_callback.h" class FilePath; // Re-creates a given test file inside the cache test folder. bool CreateCacheTestFile(const FilePath& name); -// Deprecated. -bool CreateCacheTestFile(const wchar_t* name); // Deletes all file son the cache. bool DeleteCache(const FilePath& path); -// Deprecated. -bool DeleteCache(const wchar_t* path); // Gets the path to the cache test folder. FilePath GetCacheFilePath(); -// Deprecated. -std::wstring GetCachePath(); // Fills buffer with random values (may contain nulls unless no_nulls is true). void CacheTestFillBuffer(char* buffer, size_t len, bool no_nulls); -// Deletes all files matching a pattern. -// Do not call this function with "*" as search_name. -bool DeleteFiles(const wchar_t* path, const wchar_t* search_name); - // Generates a random key of up to 200 bytes. std::string GenerateKey(bool same_length); // Returns true if the cache is not corrupt. -bool CheckCacheIntegrity(const std::wstring& path, bool new_eviction); +bool CheckCacheIntegrity(const FilePath& path, bool new_eviction); -// Helper class which ensures that the cache dir returned by GetCachePath exists -// and is clear in ctor and that the directory gets deleted in dtor. +// Helper class which ensures that the cache dir returned by GetCacheFilePath +// exists and is clear in ctor and that the directory gets deleted in dtor. class ScopedTestCache { public: ScopedTestCache(); - ScopedTestCache(const std::wstring& name); // Use a specific folder name. + ScopedTestCache(const std::string& name); // Use a specific folder name. ~ScopedTestCache(); - FilePath path() const { return FilePath::FromWStringHack(path_); } - std::wstring path_wstring() const { return path_; } + FilePath path() const { return path_; } private: - const std::wstring path_; // Path to the cache test folder. + const FilePath path_; // Path to the cache test folder. DISALLOW_COPY_AND_ASSIGN(ScopedTestCache); }; diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc index e1f5760..62b1aba 100644 --- a/net/disk_cache/stress_cache.cc +++ b/net/disk_cache/stress_cache.cc @@ -76,10 +76,8 @@ int MasterCode() { // to know which instance of the application wrote them. void StressTheCache(int iteration) { int cache_size = 0x800000; // 8MB - std::wstring path = GetCachePath(); - path.append(L"_stress"); - disk_cache::BackendImpl* cache = - new disk_cache::BackendImpl(FilePath::FromWStringHack(path)); + FilePath path = GetCacheFilePath().AppendASCII("_stress"); + disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(path); cache->SetFlags(disk_cache::kNoLoadProtection | disk_cache::kNoRandom); cache->SetMaxSize(cache_size); cache->SetType(net::DISK_CACHE); |