Commit a967ccf3 authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

SimpleCache: rename kSimpleEntryFileCount -> kSimpleEntryNormalFileCount

This is to permit less-confusing introduction of kSimpleEntryTotalFileCount
which also counts the _s file.

Bug: 636400
Change-Id: Id4bd67d2f2db4ab2c20a064ec49bdaea8c105e97
Reviewed-on: https://chromium-review.googlesource.com/690482Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505079}
parent 2210eb8b
......@@ -3846,7 +3846,7 @@ TEST_F(DiskCacheBackendTest, SimpleCacheOpenMissingFile) {
ASSERT_THAT(OpenEntry(key, &entry), IsError(net::ERR_FAILED));
// Confirm the rest of the files are gone.
for (int i = 1; i < disk_cache::kSimpleEntryFileCount; ++i) {
for (int i = 1; i < disk_cache::kSimpleEntryNormalFileCount; ++i) {
base::FilePath should_be_gone_file(cache_path_.AppendASCII(
disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, i)));
EXPECT_FALSE(base::PathExists(should_be_gone_file));
......
......@@ -3228,7 +3228,7 @@ TEST_F(DiskCacheEntryTest, SimpleCacheCreateDoomRace) {
// operation and destroy the entry object.
base::RunLoop().RunUntilIdle();
for (int i = 0; i < disk_cache::kSimpleEntryFileCount; ++i) {
for (int i = 0; i < disk_cache::kSimpleEntryNormalFileCount; ++i) {
base::FilePath entry_file_path = cache_path_.AppendASCII(
disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, i));
base::File::Info info;
......
......@@ -36,9 +36,15 @@ const uint64_t kSimpleSparseRangeMagicNumber = UINT64_C(0xeb97bf016553676b);
// - the key.
// - the data.
// - at the end, a SimpleFileEOF record.
static const int kSimpleEntryFileCount = 2;
// This is the number of files we can use for representing normal/dense streams.
static const int kSimpleEntryNormalFileCount = 2;
static const int kSimpleEntryStreamCount = 3;
// Total # of files name we can potentially use; this includes both normal
// API and sparse streams.
static const int kSimpleEntryTotalFileCount = kSimpleEntryNormalFileCount + 1;
// Note that stream 0/stream 1 files rely on the footer to verify the entry,
// so if the format changes, it's insufficient to change the version here;
// likely the EOF magic should be updated as well.
......
......@@ -84,7 +84,7 @@ void RecordWhetherOpenDidPrefetch(net::CacheType cache_type, bool result) {
bool CanOmitEmptyFile(int file_index) {
DCHECK_GE(file_index, 0);
DCHECK_LT(file_index, kSimpleEntryFileCount);
DCHECK_LT(file_index, kSimpleEntryNormalFileCount);
return file_index == simple_util::GetFileIndexFromStreamIndex(2);
}
......@@ -789,7 +789,7 @@ void SimpleSynchronousEntry::Close(
break;
}
}
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
if (empty_file_omitted_[i])
continue;
......@@ -835,7 +835,7 @@ SimpleSynchronousEntry::SimpleSynchronousEntry(net::CacheType cache_type,
key_(key),
have_open_files_(false),
initialized_(false) {
for (int i = 0; i < kSimpleEntryFileCount; ++i)
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i)
empty_file_omitted_[i] = false;
}
......@@ -899,7 +899,7 @@ bool SimpleSynchronousEntry::MaybeCreateFile(
}
bool SimpleSynchronousEntry::OpenFiles(SimpleEntryStat* out_entry_stat) {
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
File::Error error;
if (!MaybeOpenFile(i, &error)) {
// TODO(juliatuttle,gavinp): Remove one each of these triplets of
......@@ -929,7 +929,7 @@ bool SimpleSynchronousEntry::OpenFiles(SimpleEntryStat* out_entry_stat) {
have_open_files_ = true;
base::TimeDelta entry_age = base::Time::Now() - base::Time::UnixEpoch();
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
if (empty_file_omitted_[i]) {
out_entry_stat->set_data_size(i + 1, 0);
continue;
......@@ -980,7 +980,7 @@ bool SimpleSynchronousEntry::OpenFiles(SimpleEntryStat* out_entry_stat) {
}
bool SimpleSynchronousEntry::CreateFiles(SimpleEntryStat* out_entry_stat) {
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
File::Error error;
if (!MaybeCreateFile(i, FILE_NOT_REQUIRED, &error)) {
// TODO(juliatuttle,gavinp): Remove one each of these triplets of
......@@ -1011,8 +1011,8 @@ bool SimpleSynchronousEntry::CreateFiles(SimpleEntryStat* out_entry_stat) {
base::Time creation_time = Time::Now();
out_entry_stat->set_last_modified(creation_time);
out_entry_stat->set_last_used(creation_time);
for (int i = 0; i < kSimpleEntryStreamCount; ++i)
out_entry_stat->set_data_size(i, 0);
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i)
out_entry_stat->set_data_size(i, 0);
files_created_ = true;
......@@ -1032,7 +1032,7 @@ void SimpleSynchronousEntry::CloseFile(int index) {
}
void SimpleSynchronousEntry::CloseFiles() {
for (int i = 0; i < kSimpleEntryFileCount; ++i)
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i)
CloseFile(i);
}
......@@ -1112,7 +1112,7 @@ int SimpleSynchronousEntry::InitializeForOpen(
DLOG(WARNING) << "Could not open platform files for entry.";
return net::ERR_FAILED;
}
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
if (empty_file_omitted_[i])
continue;
......@@ -1211,7 +1211,7 @@ int SimpleSynchronousEntry::InitializeForCreate(
DLOG(WARNING) << "Could not create platform files.";
return net::ERR_FILE_EXISTS;
}
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
if (empty_file_omitted_[i])
continue;
......@@ -1402,7 +1402,7 @@ bool SimpleSynchronousEntry::DeleteFilesForEntryHash(
const FilePath& path,
const uint64_t entry_hash) {
bool result = true;
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
if (!DeleteFileForEntryHash(path, entry_hash, i) && !CanOmitEmptyFile(i))
result = false;
}
......@@ -1417,7 +1417,7 @@ bool SimpleSynchronousEntry::TruncateFilesForEntryHash(
const FilePath& path,
const uint64_t entry_hash) {
bool result = true;
for (int i = 0; i < kSimpleEntryFileCount; ++i) {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) {
FilePath filename_to_truncate =
path.AppendASCII(GetFilenameFromEntryHashAndFileIndex(entry_hash, i));
if (!TruncatePath(filename_to_truncate))
......
......@@ -414,15 +414,15 @@ class SimpleSynchronousEntry {
// Normally false. This is set to true when an entry is opened without
// checking the file headers. Any subsequent read will perform the check
// before completing.
bool header_and_key_check_needed_[kSimpleEntryFileCount] = {
bool header_and_key_check_needed_[kSimpleEntryNormalFileCount] = {
false,
};
base::File files_[kSimpleEntryFileCount];
base::File files_[kSimpleEntryNormalFileCount];
// True if the corresponding stream is empty and therefore no on-disk file
// was created to store it.
bool empty_file_omitted_[kSimpleEntryFileCount];
bool empty_file_omitted_[kSimpleEntryNormalFileCount];
typedef std::map<int64_t, SparseRange> SparseRangeOffsetMap;
typedef SparseRangeOffsetMap::iterator SparseRangeIterator;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment