Index: net/disk_cache/simple/simple_synchronous_entry.cc |
diff --git a/net/disk_cache/simple/simple_synchronous_entry.cc b/net/disk_cache/simple/simple_synchronous_entry.cc |
index 14be1d4d317ae1f9779d7cca22346a1465bd3910..984215a07daace1cbd867761f87310fa01f2047c 100644 |
--- a/net/disk_cache/simple/simple_synchronous_entry.cc |
+++ b/net/disk_cache/simple/simple_synchronous_entry.cc |
@@ -74,33 +74,39 @@ void RecordSyncOpenResult(net::CacheType cache_type, |
OpenEntryResult result, |
bool had_index) { |
DCHECK_GT(OPEN_ENTRY_MAX, result); |
- SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncOpenResult", cache_type, result, OPEN_ENTRY_MAX); |
+ SIMPLE_CACHE_UMA( |
+ ENUMERATION, "SyncOpenResult", cache_type, result, OPEN_ENTRY_MAX); |
if (had_index) { |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncOpenResult_WithIndex", cache_type, |
- result, OPEN_ENTRY_MAX); |
+ "SyncOpenResult_WithIndex", |
+ cache_type, |
+ result, |
+ OPEN_ENTRY_MAX); |
} else { |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncOpenResult_WithoutIndex", cache_type, |
- result, OPEN_ENTRY_MAX); |
+ "SyncOpenResult_WithoutIndex", |
+ cache_type, |
+ result, |
+ OPEN_ENTRY_MAX); |
} |
} |
void RecordWriteResult(net::CacheType cache_type, WriteResult result) { |
- SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncWriteResult", cache_type, result, WRITE_RESULT_MAX); |
+ SIMPLE_CACHE_UMA( |
+ ENUMERATION, "SyncWriteResult", cache_type, result, WRITE_RESULT_MAX); |
} |
void RecordCheckEOFResult(net::CacheType cache_type, CheckEOFResult result) { |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncCheckEOFResult", cache_type, |
- result, CHECK_EOF_RESULT_MAX); |
+ "SyncCheckEOFResult", |
+ cache_type, |
+ result, |
+ CHECK_EOF_RESULT_MAX); |
} |
void RecordCloseResult(net::CacheType cache_type, CloseResult result) { |
- SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncCloseResult", cache_type, result, WRITE_RESULT_MAX); |
+ SIMPLE_CACHE_UMA( |
+ ENUMERATION, "SyncCloseResult", cache_type, result, WRITE_RESULT_MAX); |
} |
bool CanOmitEmptyFile(int file_index) { |
@@ -171,24 +177,21 @@ SimpleEntryCreationResults::SimpleEntryCreationResults( |
SimpleEntryCreationResults::~SimpleEntryCreationResults() { |
} |
-SimpleSynchronousEntry::CRCRecord::CRCRecord() : index(-1), |
- has_crc32(false), |
- data_crc32(0) { |
+SimpleSynchronousEntry::CRCRecord::CRCRecord() |
+ : index(-1), has_crc32(false), data_crc32(0) { |
} |
SimpleSynchronousEntry::CRCRecord::CRCRecord(int index_p, |
bool has_crc32_p, |
uint32 data_crc32_p) |
- : index(index_p), |
- has_crc32(has_crc32_p), |
- data_crc32(data_crc32_p) {} |
+ : index(index_p), has_crc32(has_crc32_p), data_crc32(data_crc32_p) { |
+} |
SimpleSynchronousEntry::EntryOperationData::EntryOperationData(int index_p, |
int offset_p, |
int buf_len_p) |
- : index(index_p), |
- offset(offset_p), |
- buf_len(buf_len_p) {} |
+ : index(index_p), offset(offset_p), buf_len(buf_len_p) { |
+} |
SimpleSynchronousEntry::EntryOperationData::EntryOperationData(int index_p, |
int offset_p, |
@@ -199,13 +202,14 @@ SimpleSynchronousEntry::EntryOperationData::EntryOperationData(int index_p, |
offset(offset_p), |
buf_len(buf_len_p), |
truncate(truncate_p), |
- doomed(doomed_p) {} |
+ doomed(doomed_p) { |
+} |
SimpleSynchronousEntry::EntryOperationData::EntryOperationData( |
int64 sparse_offset_p, |
int buf_len_p) |
- : sparse_offset(sparse_offset_p), |
- buf_len(buf_len_p) {} |
+ : sparse_offset(sparse_offset_p), buf_len(buf_len_p) { |
+} |
// static |
void SimpleSynchronousEntry::OpenEntry( |
@@ -213,7 +217,7 @@ void SimpleSynchronousEntry::OpenEntry( |
const FilePath& path, |
const uint64 entry_hash, |
bool had_index, |
- SimpleEntryCreationResults *out_results) { |
+ SimpleEntryCreationResults* out_results) { |
SimpleSynchronousEntry* sync_entry = |
new SimpleSynchronousEntry(cache_type, path, "", entry_hash); |
out_results->result = |
@@ -238,12 +242,12 @@ void SimpleSynchronousEntry::CreateEntry( |
const std::string& key, |
const uint64 entry_hash, |
bool had_index, |
- SimpleEntryCreationResults *out_results) { |
+ SimpleEntryCreationResults* out_results) { |
DCHECK_EQ(entry_hash, GetEntryHashKey(key)); |
SimpleSynchronousEntry* sync_entry = |
new SimpleSynchronousEntry(cache_type, path, key, entry_hash); |
- out_results->result = sync_entry->InitializeForCreate( |
- had_index, &out_results->entry_stat); |
+ out_results->result = |
+ sync_entry->InitializeForCreate(had_index, &out_results->entry_stat); |
if (out_results->result != net::OK) { |
if (out_results->result != net::ERR_FILE_EXISTS) |
sync_entry->Doom(); |
@@ -255,19 +259,18 @@ void SimpleSynchronousEntry::CreateEntry( |
} |
// static |
-int SimpleSynchronousEntry::DoomEntry( |
- const FilePath& path, |
- uint64 entry_hash) { |
+int SimpleSynchronousEntry::DoomEntry(const FilePath& path, uint64 entry_hash) { |
const bool deleted_well = DeleteFilesForEntryHash(path, entry_hash); |
return deleted_well ? net::OK : net::ERR_FAILED; |
} |
// static |
-int SimpleSynchronousEntry::DoomEntrySet( |
- const std::vector<uint64>* key_hashes, |
- const FilePath& path) { |
+int SimpleSynchronousEntry::DoomEntrySet(const std::vector<uint64>* key_hashes, |
+ const FilePath& path) { |
const size_t did_delete_count = std::count_if( |
- key_hashes->begin(), key_hashes->end(), std::bind1st( |
+ key_hashes->begin(), |
+ key_hashes->end(), |
+ std::bind1st( |
std::ptr_fun(SimpleSynchronousEntry::DeleteFilesForEntryHash), path)); |
return (did_delete_count == key_hashes->size()) ? net::OK : net::ERR_FAILED; |
} |
@@ -412,15 +415,13 @@ void SimpleSynchronousEntry::ReadSparseData( |
DCHECK_GE(kint32max, found_range->length); |
DCHECK_LE(0, offset - found_range->offset); |
DCHECK_GE(kint32max, offset - found_range->offset); |
- int range_len_after_offset = found_range->length - |
- (offset - found_range->offset); |
+ int range_len_after_offset = |
+ found_range->length - (offset - found_range->offset); |
DCHECK_LE(0, range_len_after_offset); |
int len_to_read = std::min(buf_len, range_len_after_offset); |
- if (!ReadSparseRange(found_range, |
- offset - found_range->offset, |
- len_to_read, |
- buf)) { |
+ if (!ReadSparseRange( |
+ found_range, offset - found_range->offset, len_to_read, buf)) { |
*out_result = net::ERR_CACHE_READ_FAILURE; |
return; |
} |
@@ -431,13 +432,12 @@ void SimpleSynchronousEntry::ReadSparseData( |
// Keep reading until the buffer is full or there is not another contiguous |
// range. |
- while (read_so_far < buf_len && |
- it != sparse_ranges_.end() && |
+ while (read_so_far < buf_len && it != sparse_ranges_.end() && |
it->second.offset == offset + read_so_far) { |
SparseRange* found_range = &it->second; |
DCHECK_EQ(it->first, found_range->offset); |
- int range_len = (found_range->length > kint32max) ? |
- kint32max : found_range->length; |
+ int range_len = |
+ (found_range->length > kint32max) ? kint32max : found_range->length; |
int len_to_read = std::min(buf_len - read_so_far, range_len); |
if (!ReadSparseRange(found_range, 0, len_to_read, buf + read_so_far)) { |
*out_result = net::ERR_CACHE_READ_FAILURE; |
@@ -488,15 +488,13 @@ void SimpleSynchronousEntry::WriteSparseData( |
DCHECK_GE(kint32max, found_range->length); |
DCHECK_LE(0, offset - found_range->offset); |
DCHECK_GE(kint32max, offset - found_range->offset); |
- int range_len_after_offset = found_range->length - |
- (offset - found_range->offset); |
+ int range_len_after_offset = |
+ found_range->length - (offset - found_range->offset); |
DCHECK_LE(0, range_len_after_offset); |
int len_to_write = std::min(buf_len, range_len_after_offset); |
- if (!WriteSparseRange(found_range, |
- offset - found_range->offset, |
- len_to_write, |
- buf)) { |
+ if (!WriteSparseRange( |
+ found_range, offset - found_range->offset, len_to_write, buf)) { |
*out_result = net::ERR_CACHE_WRITE_FAILURE; |
return; |
} |
@@ -505,28 +503,23 @@ void SimpleSynchronousEntry::WriteSparseData( |
++it; |
} |
- while (written_so_far < buf_len && |
- it != sparse_ranges_.end() && |
+ while (written_so_far < buf_len && it != sparse_ranges_.end() && |
it->second.offset < offset + buf_len) { |
SparseRange* found_range = &it->second; |
if (offset + written_so_far < found_range->offset) { |
int len_to_append = found_range->offset - (offset + written_so_far); |
- if (!AppendSparseRange(offset + written_so_far, |
- len_to_append, |
- buf + written_so_far)) { |
+ if (!AppendSparseRange( |
+ offset + written_so_far, len_to_append, buf + written_so_far)) { |
*out_result = net::ERR_CACHE_WRITE_FAILURE; |
return; |
} |
written_so_far += len_to_append; |
appended_so_far += len_to_append; |
} |
- int range_len = (found_range->length > kint32max) ? |
- kint32max : found_range->length; |
+ int range_len = |
+ (found_range->length > kint32max) ? kint32max : found_range->length; |
int len_to_write = std::min(buf_len - written_so_far, range_len); |
- if (!WriteSparseRange(found_range, |
- 0, |
- len_to_write, |
- buf + written_so_far)) { |
+ if (!WriteSparseRange(found_range, 0, len_to_write, buf + written_so_far)) { |
*out_result = net::ERR_CACHE_WRITE_FAILURE; |
return; |
} |
@@ -536,9 +529,8 @@ void SimpleSynchronousEntry::WriteSparseData( |
if (written_so_far < buf_len) { |
int len_to_append = buf_len - written_so_far; |
- if (!AppendSparseRange(offset + written_so_far, |
- len_to_append, |
- buf + written_so_far)) { |
+ if (!AppendSparseRange( |
+ offset + written_so_far, len_to_append, buf + written_so_far)) { |
*out_result = net::ERR_CACHE_WRITE_FAILURE; |
return; |
} |
@@ -582,8 +574,7 @@ void SimpleSynchronousEntry::GetAvailableRange( |
++it; |
} |
- while (start + avail_so_far < offset + len && |
- it != sparse_ranges_.end() && |
+ while (start + avail_so_far < offset + len && it != sparse_ranges_.end() && |
it->second.offset == start + avail_so_far) { |
avail_so_far += it->second.length; |
++it; |
@@ -625,16 +616,17 @@ void SimpleSynchronousEntry::Close( |
DCHECK(stream_0_data); |
// Write stream 0 data. |
int stream_0_offset = entry_stat.GetOffsetInFile(key_, 0, 0); |
- if (files_[0].Write(stream_0_offset, stream_0_data->data(), |
- entry_stat.data_size(0)) != |
- entry_stat.data_size(0)) { |
+ if (files_[0].Write(stream_0_offset, |
+ stream_0_data->data(), |
+ entry_stat.data_size(0)) != entry_stat.data_size(0)) { |
RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE); |
DVLOG(1) << "Could not write stream 0 data."; |
Doom(); |
} |
for (std::vector<CRCRecord>::const_iterator it = crc32s_to_write->begin(); |
- it != crc32s_to_write->end(); ++it) { |
+ it != crc32s_to_write->end(); |
+ ++it) { |
const int stream_index = it->index; |
const int file_index = GetFileIndexFromStreamIndex(stream_index); |
if (empty_file_omitted_[file_index]) |
@@ -651,8 +643,7 @@ void SimpleSynchronousEntry::Close( |
// If stream 0 changed size, the file needs to be resized, otherwise the |
// next open will yield wrong stream sizes. On stream 1 and stream 2 proper |
// resizing of the file is handled in SimpleSynchronousEntry::WriteData(). |
- if (stream_index == 0 && |
- !files_[file_index].SetLength(eof_offset)) { |
+ if (stream_index == 0 && !files_[file_index].SetLength(eof_offset)) { |
RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE); |
DVLOG(1) << "Could not truncate stream 0 file."; |
Doom(); |
@@ -660,8 +651,7 @@ void SimpleSynchronousEntry::Close( |
} |
if (files_[file_index].Write(eof_offset, |
reinterpret_cast<const char*>(&eof_record), |
- sizeof(eof_record)) != |
- sizeof(eof_record)) { |
+ sizeof(eof_record)) != sizeof(eof_record)) { |
RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE); |
DVLOG(1) << "Could not write eof record."; |
Doom(); |
@@ -675,11 +665,16 @@ void SimpleSynchronousEntry::Close( |
files_[i].Close(); |
const int64 file_size = entry_stat.GetFileSize(key_, i); |
SIMPLE_CACHE_UMA(CUSTOM_COUNTS, |
- "LastClusterSize", cache_type_, |
- file_size % 4096, 0, 4097, 50); |
+ "LastClusterSize", |
+ cache_type_, |
+ file_size % 4096, |
+ 0, |
+ 4097, |
+ 50); |
const int64 cluster_loss = file_size % 4096 ? 4096 - file_size % 4096 : 0; |
SIMPLE_CACHE_UMA(PERCENTAGE, |
- "LastClusterLossPercent", cache_type_, |
+ "LastClusterLossPercent", |
+ cache_type_, |
cluster_loss * 100 / (cluster_loss + file_size)); |
} |
@@ -688,7 +683,9 @@ void SimpleSynchronousEntry::Close( |
if (files_created_) { |
const int stream2_file_index = GetFileIndexFromStreamIndex(2); |
- SIMPLE_CACHE_UMA(BOOLEAN, "EntryCreatedAndStream2Omitted", cache_type_, |
+ SIMPLE_CACHE_UMA(BOOLEAN, |
+ "EntryCreatedAndStream2Omitted", |
+ cache_type_, |
empty_file_omitted_[stream2_file_index]); |
} |
RecordCloseResult(cache_type_, CLOSE_RESULT_SUCCESS); |
@@ -716,9 +713,8 @@ SimpleSynchronousEntry::~SimpleSynchronousEntry() { |
CloseFiles(); |
} |
-bool SimpleSynchronousEntry::MaybeOpenFile( |
- int file_index, |
- File::Error* out_error) { |
+bool SimpleSynchronousEntry::MaybeOpenFile(int file_index, |
+ File::Error* out_error) { |
DCHECK(out_error); |
FilePath filename = GetFilenameFromFileIndex(file_index); |
@@ -735,10 +731,9 @@ bool SimpleSynchronousEntry::MaybeOpenFile( |
return files_[file_index].IsValid(); |
} |
-bool SimpleSynchronousEntry::MaybeCreateFile( |
- int file_index, |
- FileRequired file_required, |
- File::Error* out_error) { |
+bool SimpleSynchronousEntry::MaybeCreateFile(int file_index, |
+ FileRequired file_required, |
+ File::Error* out_error) { |
DCHECK(out_error); |
if (CanOmitEmptyFile(file_index) && file_required == FILE_NOT_REQUIRED) { |
@@ -756,9 +751,8 @@ bool SimpleSynchronousEntry::MaybeCreateFile( |
return files_[file_index].IsValid(); |
} |
-bool SimpleSynchronousEntry::OpenFiles( |
- bool had_index, |
- SimpleEntryStat* out_entry_stat) { |
+bool SimpleSynchronousEntry::OpenFiles(bool had_index, |
+ SimpleEntryStat* out_entry_stat) { |
for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
File::Error error; |
if (!MaybeOpenFile(i, &error)) { |
@@ -767,17 +761,22 @@ bool SimpleSynchronousEntry::OpenFiles( |
RecordSyncOpenResult( |
cache_type_, OPEN_ENTRY_PLATFORM_FILE_ERROR, had_index); |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncOpenPlatformFileError", cache_type_, |
- -error, -base::File::FILE_ERROR_MAX); |
+ "SyncOpenPlatformFileError", |
+ cache_type_, |
+ -error, |
+ -base::File::FILE_ERROR_MAX); |
if (had_index) { |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncOpenPlatformFileError_WithIndex", cache_type_, |
- -error, -base::File::FILE_ERROR_MAX); |
+ "SyncOpenPlatformFileError_WithIndex", |
+ cache_type_, |
+ -error, |
+ -base::File::FILE_ERROR_MAX); |
} else { |
SIMPLE_CACHE_UMA(ENUMERATION, |
"SyncOpenPlatformFileError_WithoutIndex", |
cache_type_, |
- -error, -base::File::FILE_ERROR_MAX); |
+ -error, |
+ -base::File::FILE_ERROR_MAX); |
} |
while (--i >= 0) |
CloseFile(i); |
@@ -828,17 +827,20 @@ bool SimpleSynchronousEntry::OpenFiles( |
out_entry_stat->set_data_size(i + 1, file_info.size); |
} |
SIMPLE_CACHE_UMA(CUSTOM_COUNTS, |
- "SyncOpenEntryAge", cache_type_, |
- entry_age.InHours(), 1, 1000, 50); |
+ "SyncOpenEntryAge", |
+ cache_type_, |
+ entry_age.InHours(), |
+ 1, |
+ 1000, |
+ 50); |
files_created_ = false; |
return true; |
} |
-bool SimpleSynchronousEntry::CreateFiles( |
- bool had_index, |
- SimpleEntryStat* out_entry_stat) { |
+bool SimpleSynchronousEntry::CreateFiles(bool had_index, |
+ SimpleEntryStat* out_entry_stat) { |
for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
File::Error error; |
if (!MaybeCreateFile(i, FILE_NOT_REQUIRED, &error)) { |
@@ -846,17 +848,22 @@ bool SimpleSynchronousEntry::CreateFiles( |
// We can calculate the third as the sum or difference of the other two. |
RecordSyncCreateResult(CREATE_ENTRY_PLATFORM_FILE_ERROR, had_index); |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncCreatePlatformFileError", cache_type_, |
- -error, -base::File::FILE_ERROR_MAX); |
+ "SyncCreatePlatformFileError", |
+ cache_type_, |
+ -error, |
+ -base::File::FILE_ERROR_MAX); |
if (had_index) { |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncCreatePlatformFileError_WithIndex", cache_type_, |
- -error, -base::File::FILE_ERROR_MAX); |
+ "SyncCreatePlatformFileError_WithIndex", |
+ cache_type_, |
+ -error, |
+ -base::File::FILE_ERROR_MAX); |
} else { |
SIMPLE_CACHE_UMA(ENUMERATION, |
"SyncCreatePlatformFileError_WithoutIndex", |
cache_type_, |
- -error, -base::File::FILE_ERROR_MAX); |
+ -error, |
+ -base::File::FILE_ERROR_MAX); |
} |
while (--i >= 0) |
CloseFile(i); |
@@ -870,7 +877,7 @@ bool SimpleSynchronousEntry::CreateFiles( |
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); |
+ out_entry_stat->set_data_size(i, 0); |
files_created_ = true; |
@@ -933,8 +940,8 @@ int SimpleSynchronousEntry::InitializeForOpen( |
} |
scoped_ptr<char[]> key(new char[header.key_length]); |
- int key_read_result = files_[i].Read(sizeof(header), key.get(), |
- header.key_length); |
+ int key_read_result = |
+ files_[i].Read(sizeof(header), key.get(), header.key_length); |
if (key_read_result != implicit_cast<int>(header.key_length)) { |
DLOG(WARNING) << "Cannot read key from entry."; |
RecordSyncOpenResult(cache_type_, OPEN_ENTRY_CANT_READ_KEY, had_index); |
@@ -969,8 +976,7 @@ int SimpleSynchronousEntry::InitializeForOpen( |
int32 sparse_data_size = 0; |
if (!OpenSparseFileIfExists(&sparse_data_size)) { |
- RecordSyncOpenResult( |
- cache_type_, OPEN_ENTRY_SPARSE_OPEN_FAILED, had_index); |
+ RecordSyncOpenResult(cache_type_, OPEN_ENTRY_SPARSE_OPEN_FAILED, had_index); |
return net::ERR_FAILED; |
} |
out_entry_stat->set_sparse_data_size(sparse_data_size); |
@@ -987,8 +993,8 @@ int SimpleSynchronousEntry::InitializeForOpen( |
removed_stream2 = true; |
} |
- SIMPLE_CACHE_UMA(BOOLEAN, "EntryOpenedAndStream2Removed", cache_type_, |
- removed_stream2); |
+ SIMPLE_CACHE_UMA( |
+ BOOLEAN, "EntryOpenedAndStream2Removed", cache_type_, removed_stream2); |
RecordSyncOpenResult(cache_type_, OPEN_ENTRY_SUCCESS, had_index); |
initialized_ = true; |
@@ -1012,8 +1018,8 @@ bool SimpleSynchronousEntry::InitializeCreatedFile( |
return false; |
} |
- bytes_written = files_[file_index].Write(sizeof(header), key_.data(), |
- key_.size()); |
+ bytes_written = |
+ files_[file_index].Write(sizeof(header), key_.data(), key_.size()); |
if (bytes_written != implicit_cast<int>(key_.size())) { |
*out_result = CREATE_ENTRY_CANT_WRITE_KEY; |
return false; |
@@ -1068,8 +1074,8 @@ int SimpleSynchronousEntry::ReadAndValidateStream0( |
// These are the real values of data size. |
out_entry_stat->set_data_size(0, stream_0_size); |
- out_entry_stat->set_data_size( |
- 1, out_entry_stat->data_size(1) - stream_0_size); |
+ out_entry_stat->set_data_size(1, |
+ out_entry_stat->data_size(1) - stream_0_size); |
// Put stream 0 data in memory. |
*stream_0_data = new net::GrowableIOBuffer(); |
@@ -1107,9 +1113,9 @@ int SimpleSynchronousEntry::GetEOFRecordData(int index, |
int file_offset = entry_stat.GetEOFOffsetInFile(key_, index); |
int file_index = GetFileIndexFromStreamIndex(index); |
File* file = const_cast<File*>(&files_[file_index]); |
- if (file->Read(file_offset, reinterpret_cast<char*>(&eof_record), |
- sizeof(eof_record)) != |
- sizeof(eof_record)) { |
+ if (file->Read(file_offset, |
+ reinterpret_cast<char*>(&eof_record), |
+ sizeof(eof_record)) != sizeof(eof_record)) { |
RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_READ_FAILURE); |
return net::ERR_CACHE_CHECKSUM_READ_FAILURE; |
} |
@@ -1133,26 +1139,24 @@ void SimpleSynchronousEntry::Doom() const { |
} |
// static |
-bool SimpleSynchronousEntry::DeleteFileForEntryHash( |
- const FilePath& path, |
- const uint64 entry_hash, |
- const int file_index) { |
+bool SimpleSynchronousEntry::DeleteFileForEntryHash(const FilePath& path, |
+ const uint64 entry_hash, |
+ const int file_index) { |
FilePath to_delete = path.AppendASCII( |
GetFilenameFromEntryHashAndFileIndex(entry_hash, file_index)); |
return base::DeleteFile(to_delete, false); |
} |
// static |
-bool SimpleSynchronousEntry::DeleteFilesForEntryHash( |
- const FilePath& path, |
- const uint64 entry_hash) { |
+bool SimpleSynchronousEntry::DeleteFilesForEntryHash(const FilePath& path, |
+ const uint64 entry_hash) { |
bool result = true; |
for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
if (!DeleteFileForEntryHash(path, entry_hash, i) && !CanOmitEmptyFile(i)) |
result = false; |
} |
- FilePath to_delete = path.AppendASCII( |
- GetSparseFilenameFromEntryHash(entry_hash)); |
+ FilePath to_delete = |
+ path.AppendASCII(GetSparseFilenameFromEntryHash(entry_hash)); |
base::DeleteFile(to_delete, false); |
return result; |
} |
@@ -1160,16 +1164,20 @@ bool SimpleSynchronousEntry::DeleteFilesForEntryHash( |
void SimpleSynchronousEntry::RecordSyncCreateResult(CreateEntryResult result, |
bool had_index) { |
DCHECK_GT(CREATE_ENTRY_MAX, result); |
- SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncCreateResult", cache_type_, result, CREATE_ENTRY_MAX); |
+ SIMPLE_CACHE_UMA( |
+ ENUMERATION, "SyncCreateResult", cache_type_, result, CREATE_ENTRY_MAX); |
if (had_index) { |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncCreateResult_WithIndex", cache_type_, |
- result, CREATE_ENTRY_MAX); |
+ "SyncCreateResult_WithIndex", |
+ cache_type_, |
+ result, |
+ CREATE_ENTRY_MAX); |
} else { |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "SyncCreateResult_WithoutIndex", cache_type_, |
- result, CREATE_ENTRY_MAX); |
+ "SyncCreateResult_WithoutIndex", |
+ cache_type_, |
+ result, |
+ CREATE_ENTRY_MAX); |
} |
} |
@@ -1182,8 +1190,8 @@ bool SimpleSynchronousEntry::OpenSparseFileIfExists( |
int32* out_sparse_data_size) { |
DCHECK(!sparse_file_open()); |
- FilePath filename = path_.AppendASCII( |
- GetSparseFilenameFromEntryHash(entry_hash_)); |
+ FilePath filename = |
+ path_.AppendASCII(GetSparseFilenameFromEntryHash(entry_hash_)); |
int flags = File::FLAG_OPEN | File::FLAG_READ | File::FLAG_WRITE; |
sparse_file_.Initialize(filename, flags); |
if (sparse_file_.IsValid()) |
@@ -1195,8 +1203,8 @@ bool SimpleSynchronousEntry::OpenSparseFileIfExists( |
bool SimpleSynchronousEntry::CreateSparseFile() { |
DCHECK(!sparse_file_open()); |
- FilePath filename = path_.AppendASCII( |
- GetSparseFilenameFromEntryHash(entry_hash_)); |
+ FilePath filename = |
+ path_.AppendASCII(GetSparseFilenameFromEntryHash(entry_hash_)); |
int flags = File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE; |
sparse_file_.Initialize(filename, flags); |
if (!sparse_file_.IsValid()) |
@@ -1240,8 +1248,8 @@ bool SimpleSynchronousEntry::InitializeSparseFile() { |
return false; |
} |
- int key_write_result = sparse_file_.Write(sizeof(header), key_.data(), |
- key_.size()); |
+ int key_write_result = |
+ sparse_file_.Write(sizeof(header), key_.data(), key_.size()); |
if (key_write_result != implicit_cast<int>(key_.size())) { |
DLOG(WARNING) << "Could not write sparse file key"; |
return false; |
@@ -1318,7 +1326,9 @@ bool SimpleSynchronousEntry::ScanSparseFile(int32* out_sparse_data_size) { |
} |
bool SimpleSynchronousEntry::ReadSparseRange(const SparseRange* range, |
- int offset, int len, char* buf) { |
+ int offset, |
+ int len, |
+ char* buf) { |
DCHECK(range); |
DCHECK(buf); |
DCHECK_GE(range->length, offset); |
@@ -1332,9 +1342,8 @@ bool SimpleSynchronousEntry::ReadSparseRange(const SparseRange* range, |
// If we read the whole range and we have a crc32, check it. |
if (offset == 0 && len == range->length && range->data_crc32 != 0) { |
- uint32 actual_crc32 = crc32(crc32(0L, Z_NULL, 0), |
- reinterpret_cast<const Bytef*>(buf), |
- len); |
+ uint32 actual_crc32 = |
+ crc32(crc32(0L, Z_NULL, 0), reinterpret_cast<const Bytef*>(buf), len); |
if (actual_crc32 != range->data_crc32) { |
DLOG(WARNING) << "Sparse range crc32 mismatch."; |
return false; |
@@ -1346,7 +1355,8 @@ bool SimpleSynchronousEntry::ReadSparseRange(const SparseRange* range, |
} |
bool SimpleSynchronousEntry::WriteSparseRange(SparseRange* range, |
- int offset, int len, |
+ int offset, |
+ int len, |
const char* buf) { |
DCHECK(range); |
DCHECK(buf); |
@@ -1355,9 +1365,8 @@ bool SimpleSynchronousEntry::WriteSparseRange(SparseRange* range, |
uint32 new_crc32 = 0; |
if (offset == 0 && len == range->length) { |
- new_crc32 = crc32(crc32(0L, Z_NULL, 0), |
- reinterpret_cast<const Bytef*>(buf), |
- len); |
+ new_crc32 = |
+ crc32(crc32(0L, Z_NULL, 0), reinterpret_cast<const Bytef*>(buf), len); |
} |
if (new_crc32 != range->data_crc32) { |
@@ -1394,9 +1403,8 @@ bool SimpleSynchronousEntry::AppendSparseRange(int64 offset, |
DCHECK_LT(0, len); |
DCHECK(buf); |
- uint32 data_crc32 = crc32(crc32(0L, Z_NULL, 0), |
- reinterpret_cast<const Bytef*>(buf), |
- len); |
+ uint32 data_crc32 = |
+ crc32(crc32(0L, Z_NULL, 0), reinterpret_cast<const Bytef*>(buf), len); |
SimpleFileSparseRangeHeader header; |
header.sparse_range_magic_number = kSimpleSparseRangeMagicNumber; |
@@ -1404,9 +1412,8 @@ bool SimpleSynchronousEntry::AppendSparseRange(int64 offset, |
header.length = len; |
header.data_crc32 = data_crc32; |
- int bytes_written = sparse_file_.Write(sparse_tail_offset_, |
- reinterpret_cast<char*>(&header), |
- sizeof(header)); |
+ int bytes_written = sparse_file_.Write( |
+ sparse_tail_offset_, reinterpret_cast<char*>(&header), sizeof(header)); |
if (bytes_written != implicit_cast<int>(sizeof(header))) { |
DLOG(WARNING) << "Could not append sparse range header."; |
return false; |