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

Unified Diff: net/disk_cache/entry_impl.cc

Issue 9702059: Disk cache: Remove all non essential synchronization from the cache destructor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
Index: net/disk_cache/entry_impl.cc
===================================================================
--- net/disk_cache/entry_impl.cc (revision 126788)
+++ net/disk_cache/entry_impl.cc (working copy)
@@ -292,8 +292,9 @@
// ------------------------------------------------------------------------
EntryImpl::EntryImpl(BackendImpl* backend, Addr address, bool read_only)
- : entry_(NULL, Addr(0)), node_(NULL, Addr(0)), backend_(backend),
- doomed_(false), read_only_(read_only), dirty_(false) {
+ : 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++) {
unreported_size_[i] = 0;
@@ -301,7 +302,7 @@
}
void EntryImpl::DoomImpl() {
- if (doomed_)
+ if (doomed_ || !backend_)
return;
SetPointerForInvalidEntry(backend_->GetCurrentEntryId());
@@ -678,9 +679,15 @@
}
void EntryImpl::DecrementIoCount() {
- backend_->DecrementIoCount();
+ if (backend_)
+ backend_->DecrementIoCount();
}
+void EntryImpl::OnEntryCreated(BackendImpl* backend) {
+ // Just grab a reference to the backround queue.
+ background_queue_ = backend->GetBackgroundQueue();
+}
+
void EntryImpl::SetTimes(base::Time last_used, base::Time last_modified) {
node_.Data()->last_used = last_used.ToInternalValue();
node_.Data()->last_modified = last_modified.ToInternalValue();
@@ -688,6 +695,9 @@
}
void EntryImpl::ReportIOTime(Operation op, const base::TimeTicks& start) {
+ if (!backend_)
+ return;
+
int group = backend_->GetSizeGroup();
switch (op) {
case kRead:
@@ -744,11 +754,13 @@
// ------------------------------------------------------------------------
void EntryImpl::Doom() {
- backend_->background_queue()->DoomEntryImpl(this);
+ if (background_queue_)
+ background_queue_->DoomEntryImpl(this);
}
void EntryImpl::Close() {
- backend_->background_queue()->CloseEntryImpl(this);
+ if (background_queue_)
+ background_queue_->CloseEntryImpl(this);
}
std::string EntryImpl::GetKey() const {
@@ -817,8 +829,10 @@
if (buf_len < 0)
return net::ERR_INVALID_ARGUMENT;
- backend_->background_queue()->ReadData(this, index, offset, buf, buf_len,
- callback);
+ if (!background_queue_)
+ return net::ERR_UNEXPECTED;
+
+ background_queue_->ReadData(this, index, offset, buf, buf_len, callback);
return net::ERR_IO_PENDING;
}
@@ -835,8 +849,11 @@
if (offset < 0 || buf_len < 0)
return net::ERR_INVALID_ARGUMENT;
- backend_->background_queue()->WriteData(this, index, offset, buf, buf_len,
- truncate, callback);
+ if (!background_queue_)
+ return net::ERR_UNEXPECTED;
+
+ background_queue_->WriteData(this, index, offset, buf, buf_len, truncate,
+ callback);
return net::ERR_IO_PENDING;
}
@@ -845,8 +862,10 @@
if (callback.is_null())
return ReadSparseDataImpl(offset, buf, buf_len, callback);
- backend_->background_queue()->ReadSparseData(this, offset, buf, buf_len,
- callback);
+ if (!background_queue_)
+ return net::ERR_UNEXPECTED;
+
+ background_queue_->ReadSparseData(this, offset, buf, buf_len, callback);
return net::ERR_IO_PENDING;
}
@@ -855,15 +874,19 @@
if (callback.is_null())
return WriteSparseDataImpl(offset, buf, buf_len, callback);
- backend_->background_queue()->WriteSparseData(this, offset, buf, buf_len,
- callback);
+ if (!background_queue_)
+ return net::ERR_UNEXPECTED;
+
+ background_queue_->WriteSparseData(this, offset, buf, buf_len, callback);
return net::ERR_IO_PENDING;
}
int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
const net::CompletionCallback& callback) {
- backend_->background_queue()->GetAvailableRange(this, offset, len, start,
- callback);
+ if (!background_queue_)
+ return net::ERR_UNEXPECTED;
+
+ background_queue_->GetAvailableRange(this, offset, len, start, callback);
return net::ERR_IO_PENDING;
}
@@ -877,14 +900,18 @@
}
void EntryImpl::CancelSparseIO() {
- backend_->background_queue()->CancelSparseIO(this);
+ if (background_queue_)
+ background_queue_->CancelSparseIO(this);
}
int EntryImpl::ReadyForSparseIO(const net::CompletionCallback& callback) {
if (!sparse_.get())
return net::OK;
- backend_->background_queue()->ReadyForSparseIO(this, callback);
+ if (!background_queue_)
+ return net::ERR_UNEXPECTED;
+
+ background_queue_->ReadyForSparseIO(this, callback);
return net::ERR_IO_PENDING;
}
@@ -895,6 +922,11 @@
// data related to a previous cache entry because the range was not fully
// written before).
EntryImpl::~EntryImpl() {
+ if (!backend_) {
+ entry_.clear_modified();
+ node_.clear_modified();
+ return;
+ }
Log("~EntryImpl in");
// Save the sparse info to disk. This will generate IO for this entry and
@@ -958,6 +990,9 @@
if (buf_len < 0)
return net::ERR_INVALID_ARGUMENT;
+ if (!backend_)
+ return net::ERR_UNEXPECTED;
+
TimeTicks start = TimeTicks::Now();
if (offset + buf_len > entry_size)
@@ -1035,6 +1070,9 @@
if (offset < 0 || buf_len < 0)
return net::ERR_INVALID_ARGUMENT;
+ if (!backend_)
+ return net::ERR_UNEXPECTED;
+
int max_file_size = backend_->MaxFileSize();
// offset or buf_len could be negative numbers.
@@ -1140,6 +1178,8 @@
bool EntryImpl::CreateBlock(int size, Addr* address) {
DCHECK(!address->is_initialized());
+ if (!backend_)
+ return false;
FileType file_type = Addr::RequiredFileType(size);
if (EXTERNAL == file_type) {
@@ -1164,6 +1204,7 @@
// important that the entry doesn't keep a reference to this address, or we'll
// end up deleting the contents of |address| once again.
void EntryImpl::DeleteData(Addr address, int index) {
+ DCHECK(backend_);
if (!address.is_initialized())
return;
if (address.is_separate_file()) {
@@ -1181,6 +1222,9 @@
}
void EntryImpl::UpdateRank(bool modified) {
+ if (!backend_)
+ return;
+
if (!doomed_) {
// Everything is handled by the backend.
backend_->UpdateRank(this, modified);
@@ -1195,6 +1239,9 @@
}
File* EntryImpl::GetBackingFile(Addr address, int index) {
+ if (!backend_)
+ return NULL;
+
File* file;
if (address.is_separate_file())
file = GetExternalFile(address, index);
@@ -1466,6 +1513,7 @@
}
void EntryImpl::GetData(int index, char** buffer, Addr* address) {
+ DCHECK(backend_);
if (user_buffers_[index].get() && user_buffers_[index]->Size() &&
!user_buffers_[index]->Start()) {
// The data is already in memory, just copy it and we're done.

Powered by Google App Engine
This is Rietveld 408576698