summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 20:22:37 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-13 20:22:37 +0000
commitebcb20c7ead50898319724aa42efb0e31acf1877 (patch)
treefc1b9f066fc9ac3aa2faa32ae56e765f9133423a /net
parent55a75d99c6609ed4f6dc7052fcf3d907efaf7137 (diff)
downloadchromium_src-ebcb20c7ead50898319724aa42efb0e31acf1877.zip
chromium_src-ebcb20c7ead50898319724aa42efb0e31acf1877.tar.gz
chromium_src-ebcb20c7ead50898319724aa42efb0e31acf1877.tar.bz2
Convert BlockFiles to use FilePath instead of wstring.
BUG=24444 Review URL: http://codereview.chromium.org/274012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28873 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/disk_cache/backend_impl.h4
-rw-r--r--net/disk_cache/block_files.cc27
-rw-r--r--net/disk_cache/block_files.h7
-rw-r--r--net/disk_cache/block_files_unittest.cc31
-rw-r--r--net/disk_cache/cache_util.h2
-rw-r--r--net/disk_cache/cache_util_posix.cc4
-rw-r--r--net/disk_cache/cache_util_win.cc4
-rw-r--r--net/disk_cache/disk_cache_perftest.cc2
-rw-r--r--net/disk_cache/disk_cache_test_util.cc6
-rw-r--r--net/disk_cache/disk_cache_test_util.h4
-rw-r--r--net/tools/dump_cache/dump_files.cc4
11 files changed, 46 insertions, 49 deletions
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index 00711a9..85075db 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -36,14 +36,14 @@ class BackendImpl : public Backend {
friend class Eviction;
public:
explicit BackendImpl(const FilePath& path)
- : path_(path), block_files_(path.ToWStringHack()), mask_(0), max_size_(0),
+ : path_(path), block_files_(path), mask_(0), max_size_(0),
cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(0),
init_(false), restarted_(false), unit_test_(false), read_only_(false),
new_eviction_(false), first_timer_(true),
ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
// mask can be used to limit the usable size of the hash table, for testing.
BackendImpl(const FilePath& path, uint32 mask)
- : path_(path), block_files_(path.ToWStringHack()), mask_(mask), max_size_(0),
+ : path_(path), block_files_(path), mask_(mask), max_size_(0),
cache_type_(net::DISK_CACHE), uma_report_(0), user_flags_(kMask),
init_(false), restarted_(false), unit_test_(false), read_only_(false),
new_eviction_(false), first_timer_(true),
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc
index ffb74db..9cdb2e0 100644
--- a/net/disk_cache/block_files.cc
+++ b/net/disk_cache/block_files.cc
@@ -15,7 +15,7 @@ using base::Time;
namespace {
-const wchar_t* kBlockName = L"data_";
+const char* kBlockName = "data_";
// This array is used to perform a fast lookup of the nibble bit pattern to the
// type of entry that can be stored there (number of consecutive blocks).
@@ -200,24 +200,21 @@ void BlockFiles::CloseFiles() {
block_files_.clear();
}
-std::wstring BlockFiles::Name(int index) {
+FilePath BlockFiles::Name(int index) {
// The file format allows for 256 files.
DCHECK(index < 256 || index >= 0);
- std::wstring name(path_);
- std::wstring tmp = StringPrintf(L"%ls%d", kBlockName, index);
- file_util::AppendToPath(&name, tmp);
-
- return name;
+ std::string tmp = StringPrintf("%s%d", kBlockName, index);
+ return path_.AppendASCII(tmp);
}
bool BlockFiles::CreateBlockFile(int index, FileType file_type, bool force) {
- std::wstring name = Name(index);
+ FilePath name = Name(index);
int flags =
force ? base::PLATFORM_FILE_CREATE_ALWAYS : base::PLATFORM_FILE_CREATE;
flags |= base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE;
scoped_refptr<File> file(new File(
- base::CreatePlatformFile(name.c_str(), flags, NULL)));
+ base::CreatePlatformFile(name, flags, NULL)));
if (!file->IsValid())
return false;
@@ -236,16 +233,16 @@ bool BlockFiles::OpenBlockFile(int index) {
block_files_.resize(block_files_.size() + to_add);
}
- std::wstring name = Name(index);
+ FilePath name = Name(index);
scoped_refptr<MappedFile> file(new MappedFile());
- if (!file->Init(name, kBlockHeaderSize)) {
- LOG(ERROR) << "Failed to open " << name;
+ if (!file->Init(name.ToWStringHack(), kBlockHeaderSize)) {
+ LOG(ERROR) << "Failed to open " << name.value();
return false;
}
if (file->GetLength() < static_cast<size_t>(kBlockHeaderSize)) {
- LOG(ERROR) << "File too small " << name;
+ LOG(ERROR) << "File too small " << name.value();
return false;
}
@@ -390,11 +387,11 @@ void BlockFiles::RemoveEmptyFile(FileType block_type) {
block_files_[file_index]->Release();
block_files_[file_index] = NULL;
- std::wstring name = Name(file_index);
+ FilePath name = Name(file_index);
int failure = DeleteCacheFile(name) ? 0 : 1;
UMA_HISTOGRAM_COUNTS("DiskCache.DeleteFailed2", failure);
if (failure)
- LOG(ERROR) << "Failed to delete " << name << " from the cache.";
+ LOG(ERROR) << "Failed to delete " << name.value() << " from the cache.";
continue;
}
diff --git a/net/disk_cache/block_files.h b/net/disk_cache/block_files.h
index faf38ef..8503062 100644
--- a/net/disk_cache/block_files.h
+++ b/net/disk_cache/block_files.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "base/file_path.h"
#include "net/disk_cache/addr.h"
#include "net/disk_cache/mapped_file.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
@@ -20,7 +21,7 @@ class EntryImpl;
// This class handles the set of block-files open by the disk cache.
class BlockFiles {
public:
- explicit BlockFiles(const std::wstring& path)
+ explicit BlockFiles(const FilePath& path)
: init_(false), zero_buffer_(NULL), path_(path) {}
~BlockFiles();
@@ -69,11 +70,11 @@ class BlockFiles {
bool FixBlockFileHeader(MappedFile* file);
// Returns the filename for a given file index.
- std::wstring Name(int index);
+ FilePath Name(int index);
bool init_;
char* zero_buffer_; // Buffer to speed-up cleaning deleted entries.
- std::wstring path_; // Path to the backing folder.
+ FilePath path_; // Path to the backing folder.
std::vector<MappedFile*> block_files_; // The actual files.
FRIEND_TEST(DiskCacheTest, BlockFiles_ZeroSizeFile);
diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc
index 2ea930e..322c10c 100644
--- a/net/disk_cache/block_files_unittest.cc
+++ b/net/disk_cache/block_files_unittest.cc
@@ -14,9 +14,8 @@ using base::Time;
namespace {
// Returns the number of files in this folder.
-int NumberOfFiles(const std::wstring& path) {
- file_util::FileEnumerator iter(FilePath::FromWStringHack(path), false,
- file_util::FileEnumerator::FILES);
+int NumberOfFiles(const FilePath& path) {
+ file_util::FileEnumerator iter(path, false, file_util::FileEnumerator::FILES);
int count = 0;
for (FilePath file = iter.Next(); !file.value().empty(); file = iter.Next()) {
count++;
@@ -29,8 +28,8 @@ int NumberOfFiles(const std::wstring& path) {
namespace disk_cache {
TEST_F(DiskCacheTest, BlockFiles_Grow) {
- std::wstring path = GetCachePath();
- ASSERT_TRUE(DeleteCache(path.c_str()));
+ FilePath path = FilePath::FromWStringHack(GetCachePath());
+ ASSERT_TRUE(DeleteCache(path));
ASSERT_TRUE(file_util::CreateDirectory(path));
BlockFiles files(path);
@@ -56,8 +55,8 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) {
// We should be able to delete empty block files.
TEST_F(DiskCacheTest, BlockFiles_Shrink) {
- std::wstring path = GetCachePath();
- ASSERT_TRUE(DeleteCache(path.c_str()));
+ FilePath path = FilePath::FromWStringHack(GetCachePath());
+ ASSERT_TRUE(DeleteCache(path));
ASSERT_TRUE(file_util::CreateDirectory(path));
BlockFiles files(path);
@@ -80,8 +79,8 @@ TEST_F(DiskCacheTest, BlockFiles_Shrink) {
// Handling of block files not properly closed.
TEST_F(DiskCacheTest, BlockFiles_Recover) {
- std::wstring path = GetCachePath();
- ASSERT_TRUE(DeleteCache(path.c_str()));
+ FilePath path = FilePath::FromWStringHack(GetCachePath());
+ ASSERT_TRUE(DeleteCache(path));
ASSERT_TRUE(file_util::CreateDirectory(path));
BlockFiles files(path);
@@ -158,19 +157,19 @@ TEST_F(DiskCacheTest, BlockFiles_Recover) {
// Handling of truncated files.
TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) {
- std::wstring path = GetCachePath();
- ASSERT_TRUE(DeleteCache(path.c_str()));
+ FilePath path = FilePath::FromWStringHack(GetCachePath());
+ ASSERT_TRUE(DeleteCache(path));
ASSERT_TRUE(file_util::CreateDirectory(path));
BlockFiles files(path);
ASSERT_TRUE(files.Init(true));
- std::wstring filename = files.Name(0);
+ FilePath filename = files.Name(0);
files.CloseFiles();
// Truncate one of the files.
{
scoped_refptr<File> file(new File);
- ASSERT_TRUE(file->Init(FilePath::FromWStringHack(filename)));
+ ASSERT_TRUE(file->Init(filename));
EXPECT_TRUE(file->SetLength(0));
}
@@ -180,8 +179,8 @@ TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) {
// An invalid file can be detected after init.
TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
- std::wstring path = GetCachePath();
- ASSERT_TRUE(DeleteCache(path.c_str()));
+ FilePath path = FilePath::FromWStringHack(GetCachePath());
+ ASSERT_TRUE(DeleteCache(path));
ASSERT_TRUE(file_util::CreateDirectory(path));
BlockFiles files(path);
@@ -192,7 +191,7 @@ TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
EXPECT_TRUE(NULL == files.GetFile(addr));
// Let's create an invalid file.
- FilePath filename(FilePath::FromWStringHack(files.Name(5)));
+ FilePath filename(files.Name(5));
char header[kBlockHeaderSize];
memset(header, 'a', kBlockHeaderSize);
EXPECT_EQ(kBlockHeaderSize,
diff --git a/net/disk_cache/cache_util.h b/net/disk_cache/cache_util.h
index 7c91574..1caac8c 100644
--- a/net/disk_cache/cache_util.h
+++ b/net/disk_cache/cache_util.h
@@ -25,8 +25,6 @@ void DeleteCache(const std::wstring& path, bool remove_folder);
// Deletes a cache file.
bool DeleteCacheFile(const FilePath& name);
-// Deprecated.
-bool DeleteCacheFile(const std::wstring& name);
} // namespace disk_cache
diff --git a/net/disk_cache/cache_util_posix.cc b/net/disk_cache/cache_util_posix.cc
index 180e521..97d3a4e 100644
--- a/net/disk_cache/cache_util_posix.cc
+++ b/net/disk_cache/cache_util_posix.cc
@@ -38,8 +38,4 @@ void DeleteCache(const std::wstring& path, bool remove_folder) {
DeleteCache(FilePath::FromWStringHack(path), remove_folder);
}
-bool DeleteCacheFile(const std::wstring& name) {
- return DeleteCacheFile(FilePath::FromWStringHack(name));
-}
-
} // namespace disk_cache
diff --git a/net/disk_cache/cache_util_win.cc b/net/disk_cache/cache_util_win.cc
index 46bffe8..182e818 100644
--- a/net/disk_cache/cache_util_win.cc
+++ b/net/disk_cache/cache_util_win.cc
@@ -65,8 +65,4 @@ void DeleteCache(const std::wstring& path, bool remove_folder) {
DeleteCache(FilePath::FromWStringHack(path), remove_folder);
}
-bool DeleteCacheFile(const std::wstring& name) {
- return DeleteCacheFile(FilePath::FromWStringHack(name));
-}
-
} // namespace disk_cache
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 4eab41d..e216d69 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -207,7 +207,7 @@ TEST_F(DiskCacheTest, BlockFilesPerformance) {
ScopedTestCache test_cache;
- disk_cache::BlockFiles files(test_cache.path_wstring());
+ disk_cache::BlockFiles files(test_cache.path());
ASSERT_TRUE(files.Init(true));
int seed = static_cast<int>(Time::Now().ToInternalValue());
diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc
index 77d731f..ddc9799 100644
--- a/net/disk_cache/disk_cache_test_util.cc
+++ b/net/disk_cache/disk_cache_test_util.cc
@@ -72,11 +72,15 @@ bool CreateCacheTestFile(const wchar_t* name) {
return true;
}
-bool DeleteCache(const wchar_t* path) {
+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)));
diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h
index 9e17512..24c5567 100644
--- a/net/disk_cache/disk_cache_test_util.h
+++ b/net/disk_cache/disk_cache_test_util.h
@@ -13,10 +13,14 @@
#include "base/timer.h"
#include "net/base/test_completion_callback.h"
+class FilePath;
+
// Re-creates a given test file inside the cache test folder.
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.
diff --git a/net/tools/dump_cache/dump_files.cc b/net/tools/dump_cache/dump_files.cc
index 2fcf7a4..45b647c 100644
--- a/net/tools/dump_cache/dump_files.cc
+++ b/net/tools/dump_cache/dump_files.cc
@@ -106,7 +106,9 @@ void DumpBlockHeader(const std::wstring& name) {
class CacheDumper {
public:
explicit CacheDumper(const std::wstring& path)
- : path_(path), block_files_(path), index_(NULL) {}
+ : path_(path),
+ block_files_(FilePath::FromWStringHack(path)),
+ index_(NULL) {}
bool Init();