Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Unified Diff: net/disk_cache/entry_impl.cc

Issue 2945002: Disk cache: Switch the disk cache to use the cache_thread.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/entry_impl.h ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/entry_impl.cc
===================================================================
--- net/disk_cache/entry_impl.cc (revision 51874)
+++ net/disk_cache/entry_impl.cc (working copy)
@@ -89,7 +89,6 @@
for (int i = 0; i < kNumStreams; i++) {
unreported_size_[i] = 0;
}
- key_file_ = NULL;
}
// When an entry is deleted from the cache, we clean up all the data associated
@@ -131,7 +130,7 @@
backend_->CacheEntryDestroyed(entry_.address());
}
-void EntryImpl::Doom() {
+void EntryImpl::DoomImpl() {
if (doomed_)
return;
@@ -139,8 +138,12 @@
backend_->InternalDoomEntry(this);
}
+void EntryImpl::Doom() {
+ backend_->background_queue()->DoomEntryImpl(this);
+}
+
void EntryImpl::Close() {
- Release();
+ backend_->background_queue()->CloseEntryImpl(this);
}
std::string EntryImpl::GetKey() const {
@@ -148,26 +151,26 @@
if (entry->Data()->key_len <= kMaxInternalKeyLength)
return std::string(entry->Data()->key);
+ // We keep a copy of the key so that we can always return it, even if the
+ // backend is disabled.
+ if (!key_.empty())
+ return key_;
+
Addr address(entry->Data()->long_key);
DCHECK(address.is_initialized());
size_t offset = 0;
if (address.is_block_file())
offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
- if (!key_file_) {
- // We keep a copy of the file needed to access the key so that we can
- // always return this object's key, even if the backend is disabled.
- COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
- key_file_ = const_cast<EntryImpl*>(this)->GetBackingFile(address,
- kKeyFileIndex);
- }
+ COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
+ File* key_file = const_cast<EntryImpl*>(this)->GetBackingFile(address,
+ kKeyFileIndex);
- std::string key;
- if (!key_file_ ||
- !key_file_->Read(WriteInto(&key, entry->Data()->key_len + 1),
- entry->Data()->key_len + 1, offset))
- key.clear();
- return key;
+ if (!key_file ||
+ !key_file->Read(WriteInto(&key_, entry->Data()->key_len + 1),
+ entry->Data()->key_len + 1, offset))
+ key_.clear();
+ return key_;
}
Time EntryImpl::GetLastUsed() const {
@@ -188,8 +191,8 @@
return entry->Data()->data_size[index];
}
-int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback) {
+int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback) {
DCHECK(node_.Data()->dirty);
if (index < 0 || index >= kNumStreams)
return net::ERR_INVALID_ARGUMENT;
@@ -233,8 +236,8 @@
kBlockHeaderSize;
SyncCallback* io_callback = NULL;
- if (completion_callback)
- io_callback = new SyncCallback(this, buf, completion_callback);
+ if (callback)
+ io_callback = new SyncCallback(this, buf, callback);
bool completed;
if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) {
@@ -247,22 +250,43 @@
io_callback->Discard();
ReportIOTime(kRead, start);
- return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING;
+ return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
}
-int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback,
- bool truncate) {
+int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
+ if (!callback)
+ return ReadDataImpl(index, offset, buf, buf_len, callback);
+
DCHECK(node_.Data()->dirty);
if (index < 0 || index >= kNumStreams)
return net::ERR_INVALID_ARGUMENT;
+ int entry_size = entry_.Data()->data_size[index];
+ if (offset >= entry_size || offset < 0 || !buf_len)
+ return 0;
+
+ if (buf_len < 0)
+ return net::ERR_INVALID_ARGUMENT;
+
+ backend_->background_queue()->ReadData(this, index, offset, buf, buf_len,
+ callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback,
+ bool truncate) {
+ DCHECK(node_.Data()->dirty);
+ if (index < 0 || index >= kNumStreams)
+ return net::ERR_INVALID_ARGUMENT;
+
if (offset < 0 || buf_len < 0)
return net::ERR_INVALID_ARGUMENT;
int max_file_size = backend_->MaxFileSize();
- // offset of buf_len could be negative numbers.
+ // offset or buf_len could be negative numbers.
if (offset > max_file_size || buf_len > max_file_size ||
offset + buf_len > max_file_size) {
int size = offset + buf_len;
@@ -332,8 +356,8 @@
return 0;
SyncCallback* io_callback = NULL;
- if (completion_callback)
- io_callback = new SyncCallback(this, buf, completion_callback);
+ if (callback)
+ io_callback = new SyncCallback(this, buf, callback);
bool completed;
if (!file->Write(buf->data(), buf_len, file_offset, io_callback,
@@ -347,25 +371,52 @@
io_callback->Discard();
ReportIOTime(kWrite, start);
- return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING;
+ return (completed || !callback) ? buf_len : net::ERR_IO_PENDING;
}
-int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback) {
+int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
+ CompletionCallback* callback, bool truncate) {
+ if (!callback)
+ return WriteDataImpl(index, offset, buf, buf_len, callback, truncate);
+
DCHECK(node_.Data()->dirty);
+ if (index < 0 || index >= kNumStreams)
+ return net::ERR_INVALID_ARGUMENT;
+
+ if (offset < 0 || buf_len < 0)
+ return net::ERR_INVALID_ARGUMENT;
+
+ backend_->background_queue()->WriteData(this, index, offset, buf, buf_len,
+ truncate, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
+ CompletionCallback* callback) {
+ DCHECK(node_.Data()->dirty);
int result = InitSparseData();
if (net::OK != result)
return result;
TimeTicks start = TimeTicks::Now();
result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len,
- completion_callback);
+ callback);
ReportIOTime(kSparseRead, start);
return result;
}
-int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
- net::CompletionCallback* completion_callback) {
+int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
+ if (!callback)
+ return ReadSparseDataImpl(offset, buf, buf_len, callback);
+
+ backend_->background_queue()->ReadSparseData(this, offset, buf, buf_len,
+ callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::WriteSparseDataImpl(int64 offset, net::IOBuffer* buf,
+ int buf_len, CompletionCallback* callback) {
DCHECK(node_.Data()->dirty);
int result = InitSparseData();
if (net::OK != result)
@@ -373,11 +424,25 @@
TimeTicks start = TimeTicks::Now();
result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf,
- buf_len, completion_callback);
+ buf_len, callback);
ReportIOTime(kSparseWrite, start);
return result;
}
+int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
+ if (!callback)
+ return WriteSparseDataImpl(offset, buf, buf_len, callback);
+
+ backend_->background_queue()->WriteSparseData(this, offset, buf, buf_len,
+ callback);
+ return net::ERR_IO_PENDING;
+}
+
+int EntryImpl::GetAvailableRangeImpl(int64 offset, int len, int64* start) {
+ return GetAvailableRange(offset, len, start);
+}
+
int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start) {
int result = InitSparseData();
if (net::OK != result)
@@ -388,7 +453,9 @@
int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
CompletionCallback* callback) {
- return GetAvailableRange(offset, len, start);
+ backend_->background_queue()->GetAvailableRange(this, offset, len, start,
+ callback);
+ return net::ERR_IO_PENDING;
}
bool EntryImpl::CouldBeSparse() const {
@@ -401,17 +468,27 @@
}
void EntryImpl::CancelSparseIO() {
+ backend_->background_queue()->CancelSparseIO(this);
+}
+
+void EntryImpl::CancelSparseIOImpl() {
if (!sparse_.get())
return;
sparse_->CancelIO();
}
-int EntryImpl::ReadyForSparseIO(net::CompletionCallback* completion_callback) {
+int EntryImpl::ReadyForSparseIOImpl(CompletionCallback* callback) {
+ DCHECK(sparse_.get());
+ return sparse_->ReadyToUse(callback);
+}
+
+int EntryImpl::ReadyForSparseIO(net::CompletionCallback* callback) {
if (!sparse_.get())
return net::OK;
- return sparse_->ReadyToUse(completion_callback);
+ backend_->background_queue()->ReadyForSparseIO(this, callback);
+ return net::ERR_IO_PENDING;
}
// ------------------------------------------------------------------------
@@ -442,19 +519,20 @@
return false;
entry_store->long_key = address.value();
- key_file_ = GetBackingFile(address, kKeyFileIndex);
+ File* key_file = GetBackingFile(address, kKeyFileIndex);
+ key_ = key;
size_t offset = 0;
if (address.is_block_file())
offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
- if (!key_file_ || !key_file_->Write(key.data(), key.size(), offset)) {
+ if (!key_file || !key_file->Write(key.data(), key.size(), offset)) {
DeleteData(address, kKeyFileIndex);
return false;
}
if (address.is_separate_file())
- key_file_->SetLength(key.size() + 1);
+ key_file->SetLength(key.size() + 1);
} else {
memcpy(entry_store->key, key.data(), key.size());
entry_store->key[key.size()] = '\0';
@@ -885,10 +963,12 @@
if (sparse_.get())
return net::OK;
- sparse_.reset(new SparseControl(this));
- int result = sparse_->Init();
- if (net::OK != result)
- sparse_.reset();
+ // Use a local variable so that sparse_ never goes from 'valid' to NULL.
+ scoped_ptr<SparseControl> sparse(new SparseControl(this));
+ int result = sparse->Init();
+ if (net::OK == result)
+ sparse_.swap(sparse);
+
return result;
}
« no previous file with comments | « net/disk_cache/entry_impl.h ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698