Index: net/disk_cache/blockfile/entry_impl.cc |
diff --git a/net/disk_cache/blockfile/entry_impl.cc b/net/disk_cache/blockfile/entry_impl.cc |
index 6ff52358485dfb82abf5bb46456311734cded7c8..b24a23c77144eca4ca4f38c2c85fb72655b54d38 100644 |
--- a/net/disk_cache/blockfile/entry_impl.cc |
+++ b/net/disk_cache/blockfile/entry_impl.cc |
@@ -32,15 +32,19 @@ const int kKeyFileIndex = 3; |
// This class implements FileIOCallback to buffer the callback from a file IO |
// operation from the actual net class. |
-class SyncCallback: public disk_cache::FileIOCallback { |
+class SyncCallback : public disk_cache::FileIOCallback { |
public: |
// |end_event_type| is the event type to log on completion. Logs nothing on |
// discard, or when the NetLog is not set to log all events. |
- SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer, |
+ SyncCallback(disk_cache::EntryImpl* entry, |
+ net::IOBuffer* buffer, |
const net::CompletionCallback& callback, |
net::NetLog::EventType end_event_type) |
- : entry_(entry), callback_(callback), buf_(buffer), |
- start_(TimeTicks::Now()), end_event_type_(end_event_type) { |
+ : entry_(entry), |
+ callback_(callback), |
+ buf_(buffer), |
+ start_(TimeTicks::Now()), |
+ end_event_type_(end_event_type) { |
entry->AddRef(); |
entry->IncrementIoCount(); |
} |
@@ -296,8 +300,11 @@ bool EntryImpl::UserBuffer::GrowBuffer(int required, int limit) { |
// ------------------------------------------------------------------------ |
EntryImpl::EntryImpl(BackendImpl* backend, Addr address, bool read_only) |
- : entry_(NULL, Addr(0)), node_(NULL, Addr(0)), |
- backend_(backend->GetWeakPtr()), doomed_(false), read_only_(read_only), |
+ : entry_(NULL, Addr(0)), |
+ node_(NULL, Addr(0)), |
+ backend_(backend->GetWeakPtr()), |
+ doomed_(false), |
+ read_only_(read_only), |
dirty_(false) { |
entry_.LazyInit(backend->File(address), address); |
for (int i = 0; i < kNumStreams; i++) { |
@@ -313,7 +320,10 @@ void EntryImpl::DoomImpl() { |
backend_->InternalDoomEntry(this); |
} |
-int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, |
+int EntryImpl::ReadDataImpl(int index, |
+ int offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
if (net_log_.IsLogging()) { |
net_log_.BeginEvent( |
@@ -324,14 +334,16 @@ int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, |
int result = InternalReadData(index, offset, buf, buf_len, callback); |
if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { |
- net_log_.EndEvent( |
- net::NetLog::TYPE_ENTRY_READ_DATA, |
- CreateNetLogReadWriteCompleteCallback(result)); |
+ net_log_.EndEvent(net::NetLog::TYPE_ENTRY_READ_DATA, |
+ CreateNetLogReadWriteCompleteCallback(result)); |
} |
return result; |
} |
-int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, |
+int EntryImpl::WriteDataImpl(int index, |
+ int offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback, |
bool truncate) { |
if (net_log_.IsLogging()) { |
@@ -340,18 +352,19 @@ int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, |
CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); |
} |
- int result = InternalWriteData(index, offset, buf, buf_len, callback, |
- truncate); |
+ int result = |
+ InternalWriteData(index, offset, buf, buf_len, callback, truncate); |
if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { |
- net_log_.EndEvent( |
- net::NetLog::TYPE_ENTRY_WRITE_DATA, |
- CreateNetLogReadWriteCompleteCallback(result)); |
+ net_log_.EndEvent(net::NetLog::TYPE_ENTRY_WRITE_DATA, |
+ CreateNetLogReadWriteCompleteCallback(result)); |
} |
return result; |
} |
-int EntryImpl::ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, |
+int EntryImpl::ReadSparseDataImpl(int64 offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
DCHECK(node_.Data()->dirty || read_only_); |
int result = InitSparseData(); |
@@ -359,13 +372,15 @@ int EntryImpl::ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, |
return result; |
TimeTicks start = TimeTicks::Now(); |
- result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len, |
- callback); |
+ result = sparse_->StartIO( |
+ SparseControl::kReadOperation, offset, buf, buf_len, callback); |
ReportIOTime(kSparseRead, start); |
return result; |
} |
-int EntryImpl::WriteSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, |
+int EntryImpl::WriteSparseDataImpl(int64 offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
DCHECK(node_.Data()->dirty || read_only_); |
int result = InitSparseData(); |
@@ -373,8 +388,8 @@ int EntryImpl::WriteSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, |
return result; |
TimeTicks start = TimeTicks::Now(); |
- result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf, |
- buf_len, callback); |
+ result = sparse_->StartIO( |
+ SparseControl::kWriteOperation, offset, buf, buf_len, callback); |
ReportIOTime(kSparseWrite, start); |
return result; |
} |
@@ -403,7 +418,8 @@ uint32 EntryImpl::GetHash() { |
return entry_.Data()->hash; |
} |
-bool EntryImpl::CreateEntry(Addr node_address, const std::string& key, |
+bool EntryImpl::CreateEntry(Addr node_address, |
+ const std::string& key, |
uint32 hash) { |
Trace("Create entry In"); |
EntryStore* entry_store = entry_.Data(); |
@@ -483,8 +499,8 @@ void EntryImpl::DeleteEntryData(bool everything) { |
for (int index = 0; index < kNumStreams; index++) { |
Addr address(entry_.Data()->data_addr[index]); |
if (address.is_initialized()) { |
- backend_->ModifyStorageSize(entry_.Data()->data_size[index] - |
- unreported_size_[index], 0); |
+ backend_->ModifyStorageSize( |
+ entry_.Data()->data_size[index] - unreported_size_[index], 0); |
entry_.Data()->data_addr[index] = 0; |
entry_.Data()->data_size[index] = 0; |
entry_.Store(); |
@@ -724,11 +740,10 @@ void EntryImpl::ReportIOTime(Operation op, const base::TimeTicks& start) { |
void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) { |
DCHECK(!net_log_.net_log()); |
- net_log_ = net::BoundNetLog::Make( |
- net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); |
- net_log_.BeginEvent( |
- net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, |
- CreateNetLogEntryCreationCallback(this, created)); |
+ net_log_ = |
+ net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); |
+ net_log_.BeginEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, |
+ CreateNetLogEntryCreationCallback(this, created)); |
} |
const net::BoundNetLog& EntryImpl::net_log() const { |
@@ -777,8 +792,8 @@ std::string EntryImpl::GetKey() const { |
offset = address.start_block() * address.BlockSize() + kBlockHeaderSize; |
COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index); |
- File* key_file = const_cast<EntryImpl*>(this)->GetBackingFile(address, |
- kKeyFileIndex); |
+ File* key_file = |
+ const_cast<EntryImpl*>(this)->GetBackingFile(address, kKeyFileIndex); |
if (!key_file) |
return std::string(); |
@@ -809,7 +824,10 @@ int32 EntryImpl::GetDataSize(int index) const { |
return entry->Data()->data_size[index]; |
} |
-int EntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, |
+int EntryImpl::ReadData(int index, |
+ int offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
if (callback.is_null()) |
return ReadDataImpl(index, offset, buf, buf_len, callback); |
@@ -832,8 +850,12 @@ int EntryImpl::ReadData(int index, int offset, IOBuffer* buf, int buf_len, |
return net::ERR_IO_PENDING; |
} |
-int EntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, |
- const CompletionCallback& callback, bool truncate) { |
+int EntryImpl::WriteData(int index, |
+ int offset, |
+ IOBuffer* buf, |
+ int buf_len, |
+ const CompletionCallback& callback, |
+ bool truncate) { |
if (callback.is_null()) |
return WriteDataImpl(index, offset, buf, buf_len, callback, truncate); |
@@ -847,12 +869,14 @@ int EntryImpl::WriteData(int index, int offset, IOBuffer* buf, int buf_len, |
if (!background_queue_.get()) |
return net::ERR_UNEXPECTED; |
- background_queue_->WriteData(this, index, offset, buf, buf_len, truncate, |
- callback); |
+ background_queue_->WriteData( |
+ this, index, offset, buf, buf_len, truncate, callback); |
return net::ERR_IO_PENDING; |
} |
-int EntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, |
+int EntryImpl::ReadSparseData(int64 offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
if (callback.is_null()) |
return ReadSparseDataImpl(offset, buf, buf_len, callback); |
@@ -864,7 +888,9 @@ int EntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, |
return net::ERR_IO_PENDING; |
} |
-int EntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, |
+int EntryImpl::WriteSparseData(int64 offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
if (callback.is_null()) |
return WriteSparseDataImpl(offset, buf, buf_len, callback); |
@@ -876,7 +902,9 @@ int EntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, |
return net::ERR_IO_PENDING; |
} |
-int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start, |
+int EntryImpl::GetAvailableRange(int64 offset, |
+ int len, |
+ int64* start, |
const CompletionCallback& callback) { |
if (!background_queue_.get()) |
return net::ERR_UNEXPECTED; |
@@ -970,8 +998,10 @@ EntryImpl::~EntryImpl() { |
// ------------------------------------------------------------------------ |
-int EntryImpl::InternalReadData(int index, int offset, |
- IOBuffer* buf, int buf_len, |
+int EntryImpl::InternalReadData(int index, |
+ int offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback) { |
DCHECK(node_.Data()->dirty || read_only_); |
DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len; |
@@ -1025,14 +1055,14 @@ int EntryImpl::InternalReadData(int index, int offset, |
size_t file_offset = offset; |
if (address.is_block_file()) { |
DCHECK_LE(offset + buf_len, kMaxBlockSize); |
- file_offset += address.start_block() * address.BlockSize() + |
- kBlockHeaderSize; |
+ file_offset += |
+ address.start_block() * address.BlockSize() + kBlockHeaderSize; |
} |
SyncCallback* io_callback = NULL; |
if (!callback.is_null()) { |
- io_callback = new SyncCallback(this, buf, callback, |
- net::NetLog::TYPE_ENTRY_READ_DATA); |
+ io_callback = new SyncCallback( |
+ this, buf, callback, net::NetLog::TYPE_ENTRY_READ_DATA); |
} |
TimeTicks start_async = TimeTicks::Now(); |
@@ -1055,8 +1085,10 @@ int EntryImpl::InternalReadData(int index, int offset, |
return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING; |
} |
-int EntryImpl::InternalWriteData(int index, int offset, |
- IOBuffer* buf, int buf_len, |
+int EntryImpl::InternalWriteData(int index, |
+ int offset, |
+ IOBuffer* buf, |
+ int buf_len, |
const CompletionCallback& callback, |
bool truncate) { |
DCHECK(node_.Data()->dirty || read_only_); |
@@ -1123,8 +1155,8 @@ int EntryImpl::InternalWriteData(int index, int offset, |
size_t file_offset = offset; |
if (address.is_block_file()) { |
DCHECK_LE(offset + buf_len, kMaxBlockSize); |
- file_offset += address.start_block() * address.BlockSize() + |
- kBlockHeaderSize; |
+ file_offset += |
+ address.start_block() * address.BlockSize() + kBlockHeaderSize; |
} else if (truncate || (extending && !buf_len)) { |
if (!file->SetLength(offset + buf_len)) |
return net::ERR_FAILED; |
@@ -1135,15 +1167,15 @@ int EntryImpl::InternalWriteData(int index, int offset, |
SyncCallback* io_callback = NULL; |
if (!callback.is_null()) { |
- io_callback = new SyncCallback(this, buf, callback, |
- net::NetLog::TYPE_ENTRY_WRITE_DATA); |
+ io_callback = new SyncCallback( |
+ this, buf, callback, net::NetLog::TYPE_ENTRY_WRITE_DATA); |
} |
TimeTicks start_async = TimeTicks::Now(); |
bool completed; |
- if (!file->Write(buf->data(), buf_len, file_offset, io_callback, |
- &completed)) { |
+ if (!file->Write( |
+ buf->data(), buf_len, file_offset, io_callback, &completed)) { |
if (io_callback) |
io_callback->Discard(); |
return net::ERR_CACHE_WRITE_FAILURE; |
@@ -1207,8 +1239,8 @@ void EntryImpl::DeleteData(Addr address, int index) { |
int failure = !DeleteCacheFile(backend_->GetFileName(address)); |
CACHE_UMA(COUNTS, "DeleteFailed", 0, failure); |
if (failure) { |
- LOG(ERROR) << "Failed to delete " << |
- backend_->GetFileName(address).value() << " from the cache."; |
+ LOG(ERROR) << "Failed to delete " << backend_->GetFileName(address) |
+ .value() << " from the cache."; |
} |
if (files_[index].get()) |
files_[index] = NULL; // Releases the object. |
@@ -1270,7 +1302,9 @@ File* EntryImpl::GetExternalFile(Addr address, int index) { |
// reuse it for the new data. Keep in mind that the normal use pattern is quite |
// simple (write sequentially from the beginning), so we optimize for handling |
// that case. |
-bool EntryImpl::PrepareTarget(int index, int offset, int buf_len, |
+bool EntryImpl::PrepareTarget(int index, |
+ int offset, |
+ int buf_len, |
bool truncate) { |
if (truncate) |
return HandleTruncation(index, offset, buf_len); |
@@ -1528,8 +1562,8 @@ void EntryImpl::GetData(int index, char** buffer, Addr* address) { |
address->set_value(entry_.Data()->data_addr[index]); |
if (address->is_initialized()) { |
// Prevent us from deleting the block from the backing store. |
- backend_->ModifyStorageSize(entry_.Data()->data_size[index] - |
- unreported_size_[index], 0); |
+ backend_->ModifyStorageSize( |
+ entry_.Data()->data_size[index] - unreported_size_[index], 0); |
entry_.Data()->data_addr[index] = 0; |
entry_.Data()->data_size[index] = 0; |
} |
@@ -1541,11 +1575,16 @@ void EntryImpl::Log(const char* msg) { |
dirty = node_.Data()->dirty; |
} |
- Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), |
- entry_.address().value(), node_.address().value()); |
+ Trace("%s 0x%p 0x%x 0x%x", |
+ msg, |
+ reinterpret_cast<void*>(this), |
+ entry_.address().value(), |
+ node_.address().value()); |
- Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], |
- entry_.Data()->data_addr[1], entry_.Data()->long_key); |
+ Trace(" data: 0x%x 0x%x 0x%x", |
+ entry_.Data()->data_addr[0], |
+ entry_.Data()->data_addr[1], |
+ entry_.Data()->long_key); |
Trace(" doomed: %d 0x%x", doomed_, dirty); |
} |