diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 23:02:37 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-13 23:02:37 +0000 |
commit | 4317c71c37dab54c55788bb68f56acf9273410c5 (patch) | |
tree | e0a4d13fb86c89a732783f6b5c4fad9b868f86b5 | |
parent | ba4c78e5b07788094ec02c6a1b44eebd7a727926 (diff) | |
download | chromium_src-4317c71c37dab54c55788bb68f56acf9273410c5.zip chromium_src-4317c71c37dab54c55788bb68f56acf9273410c5.tar.gz chromium_src-4317c71c37dab54c55788bb68f56acf9273410c5.tar.bz2 |
Move disk_cache::MappedFile to use FilePath instead of wstring.
Also add some FilePath methods in disk_cache_util.h and obsolete
the old.
BUG=24444
Review URL: http://codereview.chromium.org/266069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28910 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/disk_cache/backend_impl.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/block_files.cc | 2 | ||||
-rw-r--r-- | net/disk_cache/cache_util.h | 2 | ||||
-rw-r--r-- | net/disk_cache/cache_util_posix.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/cache_util_win.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.cc | 10 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_test_util.h | 4 | ||||
-rw-r--r-- | net/disk_cache/mapped_file.h | 4 | ||||
-rw-r--r-- | net/disk_cache/mapped_file_posix.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/mapped_file_unittest.cc | 10 | ||||
-rw-r--r-- | net/disk_cache/mapped_file_win.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/storage_block_unittest.cc | 15 | ||||
-rw-r--r-- | net/tools/dump_cache/dump_files.cc | 4 |
13 files changed, 34 insertions, 35 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 3c48d8e..0ce7214 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -1011,7 +1011,7 @@ bool BackendImpl::InitBackingStore(bool* file_created) { return false; index_ = new MappedFile(); - data_ = reinterpret_cast<Index*>(index_->Init(index_name.ToWStringHack(), 0)); + data_ = reinterpret_cast<Index*>(index_->Init(index_name, 0)); if (!data_) { LOG(ERROR) << "Unable to map Index file"; return false; diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc index 9cdb2e0..fe02f67 100644 --- a/net/disk_cache/block_files.cc +++ b/net/disk_cache/block_files.cc @@ -236,7 +236,7 @@ bool BlockFiles::OpenBlockFile(int index) { FilePath name = Name(index); scoped_refptr<MappedFile> file(new MappedFile()); - if (!file->Init(name.ToWStringHack(), kBlockHeaderSize)) { + if (!file->Init(name, kBlockHeaderSize)) { LOG(ERROR) << "Failed to open " << name.value(); return false; } diff --git a/net/disk_cache/cache_util.h b/net/disk_cache/cache_util.h index 1caac8c..cb78f16 100644 --- a/net/disk_cache/cache_util.h +++ b/net/disk_cache/cache_util.h @@ -20,8 +20,6 @@ bool MoveCache(const FilePath& from_path, const FilePath& to_path); // Deletes the cache files stored on |path|, and optionally also attempts to // delete the folder itself. void DeleteCache(const FilePath& path, bool remove_folder); -// Deprecated. -void DeleteCache(const std::wstring& path, bool remove_folder); // Deletes a cache file. bool DeleteCacheFile(const FilePath& name); diff --git a/net/disk_cache/cache_util_posix.cc b/net/disk_cache/cache_util_posix.cc index 97d3a4e..a272cb8 100644 --- a/net/disk_cache/cache_util_posix.cc +++ b/net/disk_cache/cache_util_posix.cc @@ -34,8 +34,4 @@ bool DeleteCacheFile(const FilePath& name) { return file_util::Delete(name, false); } -void DeleteCache(const std::wstring& path, bool remove_folder) { - DeleteCache(FilePath::FromWStringHack(path), remove_folder); -} - } // namespace disk_cache diff --git a/net/disk_cache/cache_util_win.cc b/net/disk_cache/cache_util_win.cc index 182e818..aefce30 100644 --- a/net/disk_cache/cache_util_win.cc +++ b/net/disk_cache/cache_util_win.cc @@ -61,8 +61,4 @@ bool DeleteCacheFile(const FilePath& name) { return DeleteFile(name.value().c_str()) ? true : false; } -void DeleteCache(const std::wstring& path, bool remove_folder) { - DeleteCache(FilePath::FromWStringHack(path), remove_folder); -} - } // namespace disk_cache diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc index ddc9799..f16c578 100644 --- a/net/disk_cache/disk_cache_test_util.cc +++ b/net/disk_cache/disk_cache_test_util.cc @@ -58,7 +58,11 @@ std::wstring GetCachePath() { return BuildCachePath(L"cache_test"); } -bool CreateCacheTestFile(const wchar_t* name) { +FilePath GetCacheFilePath() { + return FilePath::FromWStringHack(GetCachePath()); +} + +bool CreateCacheTestFile(const FilePath& name) { int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE; @@ -72,6 +76,10 @@ bool CreateCacheTestFile(const wchar_t* 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; diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h index 24c5567..f680470 100644 --- a/net/disk_cache/disk_cache_test_util.h +++ b/net/disk_cache/disk_cache_test_util.h @@ -16,6 +16,8 @@ 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. @@ -24,6 +26,8 @@ bool DeleteCache(const FilePath& path); 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). diff --git a/net/disk_cache/mapped_file.h b/net/disk_cache/mapped_file.h index b05e470..7d58532 100644 --- a/net/disk_cache/mapped_file.h +++ b/net/disk_cache/mapped_file.h @@ -13,6 +13,8 @@ #include "net/disk_cache/file.h" #include "net/disk_cache/file_block.h" +class FilePath; + namespace disk_cache { // This class implements a memory mapped file used to access block-files. The @@ -26,7 +28,7 @@ class MappedFile : public File { // Performs object initialization. name is the file to use, and size is the // ammount of data to memory map from th efile. If size is 0, the whole file // will be mapped in memory. - void* Init(const std::wstring& name, size_t size); + void* Init(const FilePath& name, size_t size); void* buffer() const { return buffer_; diff --git a/net/disk_cache/mapped_file_posix.cc b/net/disk_cache/mapped_file_posix.cc index 6370ca6..f9a361b 100644 --- a/net/disk_cache/mapped_file_posix.cc +++ b/net/disk_cache/mapped_file_posix.cc @@ -13,9 +13,9 @@ namespace disk_cache { -void* MappedFile::Init(const std::wstring& name, size_t size) { +void* MappedFile::Init(const FilePath& name, size_t size) { DCHECK(!init_); - if (init_ || !File::Init(FilePath::FromWStringHack(name))) + if (init_ || !File::Init(name)) return NULL; if (!size) diff --git a/net/disk_cache/mapped_file_unittest.cc b/net/disk_cache/mapped_file_unittest.cc index c2fb884..ea28f32 100644 --- a/net/disk_cache/mapped_file_unittest.cc +++ b/net/disk_cache/mapped_file_unittest.cc @@ -69,10 +69,9 @@ void WaitForCallbacks(int expected) { } // namespace TEST_F(DiskCacheTest, MappedFile_SyncIO) { - std::wstring filename = GetCachePath(); - file_util::AppendToPath(&filename, L"a_test"); + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); - ASSERT_TRUE(CreateCacheTestFile(filename.c_str())); + ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); char buffer1[20]; @@ -85,10 +84,9 @@ TEST_F(DiskCacheTest, MappedFile_SyncIO) { } TEST_F(DiskCacheTest, MappedFile_AsyncIO) { - std::wstring filename = GetCachePath(); - file_util::AppendToPath(&filename, L"a_test"); + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); - ASSERT_TRUE(CreateCacheTestFile(filename.c_str())); + ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); FileCallbackTest callback(1); diff --git a/net/disk_cache/mapped_file_win.cc b/net/disk_cache/mapped_file_win.cc index 0692961..69c13a4 100644 --- a/net/disk_cache/mapped_file_win.cc +++ b/net/disk_cache/mapped_file_win.cc @@ -10,9 +10,9 @@ namespace disk_cache { -void* MappedFile::Init(const std::wstring& name, size_t size) { +void* MappedFile::Init(const FilePath& name, size_t size) { DCHECK(!init_); - if (init_ || !File::Init(FilePath::FromWStringHack(name))) + if (init_ || !File::Init(name)) return NULL; buffer_ = NULL; diff --git a/net/disk_cache/storage_block_unittest.cc b/net/disk_cache/storage_block_unittest.cc index 8543e3d..c9406b6 100644 --- a/net/disk_cache/storage_block_unittest.cc +++ b/net/disk_cache/storage_block_unittest.cc @@ -10,10 +10,9 @@ #include "testing/gtest/include/gtest/gtest.h" TEST_F(DiskCacheTest, StorageBlock_LoadStore) { - std::wstring filename = GetCachePath(); - file_util::AppendToPath(&filename, L"a_test"); + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); - ASSERT_TRUE(CreateCacheTestFile(filename.c_str())); + ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); disk_cache::CacheEntryBlock entry1(file, disk_cache::Addr(0xa0010001)); @@ -31,10 +30,9 @@ TEST_F(DiskCacheTest, StorageBlock_LoadStore) { } TEST_F(DiskCacheTest, StorageBlock_SetData) { - std::wstring filename = GetCachePath(); - file_util::AppendToPath(&filename, L"a_test"); + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); - ASSERT_TRUE(CreateCacheTestFile(filename.c_str())); + ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); disk_cache::CacheEntryBlock entry1(file, disk_cache::Addr(0xa0010001)); @@ -52,10 +50,9 @@ TEST_F(DiskCacheTest, StorageBlock_SetData) { } TEST_F(DiskCacheTest, StorageBlock_SetModified) { - std::wstring filename = GetCachePath(); - file_util::AppendToPath(&filename, L"a_test"); + FilePath filename = GetCacheFilePath().AppendASCII("a_test"); scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); - ASSERT_TRUE(CreateCacheTestFile(filename.c_str())); + ASSERT_TRUE(CreateCacheTestFile(filename)); ASSERT_TRUE(file->Init(filename, 8192)); disk_cache::CacheEntryBlock* entry1 = diff --git a/net/tools/dump_cache/dump_files.cc b/net/tools/dump_cache/dump_files.cc index 45b647c..8a9abca 100644 --- a/net/tools/dump_cache/dump_files.cc +++ b/net/tools/dump_cache/dump_files.cc @@ -140,8 +140,8 @@ bool CacheDumper::Init() { std::wstring index_name(path_); file_util::AppendToPath(&index_name, kIndexName); index_file_ = new disk_cache::MappedFile; - index_ = - reinterpret_cast<disk_cache::Index*>(index_file_->Init(index_name, 0)); + index_ = reinterpret_cast<disk_cache::Index*>(index_file_->Init( + FilePath::FromWStringHack(index_name), 0)); if (!index_) { printf("Unable to map index\n"); return false; |