| Index: net/disk_cache/entry_impl.cc
|
| ===================================================================
|
| --- net/disk_cache/entry_impl.cc (revision 126788)
|
| +++ net/disk_cache/entry_impl.cc (working copy)
|
| @@ -106,7 +106,7 @@
|
| void Truncate(int offset);
|
|
|
| // Writes |len| bytes from |buf| at the given |offset|.
|
| - void Write(int offset, net::IOBuffer* buf, int len);
|
| + void Write(int offset, IOBuffer* buf, int len);
|
|
|
| // Returns true if we can read |len| bytes from |offset|, given that the
|
| // actual file has |eof| bytes stored. Note that the number of bytes to read
|
| @@ -115,7 +115,7 @@
|
| bool PreRead(int eof, int offset, int* len);
|
|
|
| // Read |len| bytes from |buf| at the given |offset|.
|
| - int Read(int offset, net::IOBuffer* buf, int len);
|
| + int Read(int offset, IOBuffer* buf, int len);
|
|
|
| // Prepare this buffer for reuse.
|
| void Reset();
|
| @@ -168,7 +168,7 @@
|
| buffer_.resize(offset);
|
| }
|
|
|
| -void EntryImpl::UserBuffer::Write(int offset, net::IOBuffer* buf, int len) {
|
| +void EntryImpl::UserBuffer::Write(int offset, IOBuffer* buf, int len) {
|
| DCHECK_GE(offset, 0);
|
| DCHECK_GE(len, 0);
|
| DCHECK_GE(offset + len, 0);
|
| @@ -225,7 +225,7 @@
|
| return (offset - offset_ < Size());
|
| }
|
|
|
| -int EntryImpl::UserBuffer::Read(int offset, net::IOBuffer* buf, int len) {
|
| +int EntryImpl::UserBuffer::Read(int offset, IOBuffer* buf, int len) {
|
| DCHECK_GE(offset, 0);
|
| DCHECK_GT(len, 0);
|
| DCHECK(Size() || offset < offset_);
|
| @@ -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,16 +302,15 @@
|
| }
|
|
|
| void EntryImpl::DoomImpl() {
|
| - if (doomed_)
|
| + if (doomed_ || !backend_)
|
| return;
|
|
|
| SetPointerForInvalidEntry(backend_->GetCurrentEntryId());
|
| backend_->InternalDoomEntry(this);
|
| }
|
|
|
| -int EntryImpl::ReadDataImpl(
|
| - int index, int offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback) {
|
| +int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback) {
|
| if (net_log_.IsLoggingAllEvents()) {
|
| net_log_.BeginEvent(
|
| net::NetLog::TYPE_ENTRY_READ_DATA,
|
| @@ -328,9 +328,9 @@
|
| return result;
|
| }
|
|
|
| -int EntryImpl::WriteDataImpl(
|
| - int index, int offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback, bool truncate) {
|
| +int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback,
|
| + bool truncate) {
|
| if (net_log_.IsLoggingAllEvents()) {
|
| net_log_.BeginEvent(
|
| net::NetLog::TYPE_ENTRY_WRITE_DATA,
|
| @@ -349,8 +349,8 @@
|
| return result;
|
| }
|
|
|
| -int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback) {
|
| +int EntryImpl::ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback) {
|
| DCHECK(node_.Data()->dirty || read_only_);
|
| int result = InitSparseData();
|
| if (net::OK != result)
|
| @@ -363,9 +363,8 @@
|
| return result;
|
| }
|
|
|
| -int EntryImpl::WriteSparseDataImpl(
|
| - int64 offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback) {
|
| +int EntryImpl::WriteSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback) {
|
| DCHECK(node_.Data()->dirty || read_only_);
|
| int result = InitSparseData();
|
| if (net::OK != result)
|
| @@ -393,7 +392,7 @@
|
| sparse_->CancelIO();
|
| }
|
|
|
| -int EntryImpl::ReadyForSparseIOImpl(const net::CompletionCallback& callback) {
|
| +int EntryImpl::ReadyForSparseIOImpl(const CompletionCallback& callback) {
|
| DCHECK(sparse_.get());
|
| return sparse_->ReadyToUse(callback);
|
| }
|
| @@ -678,9 +677,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 +693,9 @@
|
| }
|
|
|
| void EntryImpl::ReportIOTime(Operation op, const base::TimeTicks& start) {
|
| + if (!backend_)
|
| + return;
|
| +
|
| int group = backend_->GetSizeGroup();
|
| switch (op) {
|
| case kRead:
|
| @@ -744,11 +752,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 {
|
| @@ -801,8 +811,8 @@
|
| return entry->Data()->data_size[index];
|
| }
|
|
|
| -int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback) {
|
| +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);
|
|
|
| @@ -817,14 +827,15 @@
|
| 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;
|
| }
|
|
|
| -int EntryImpl::WriteData(
|
| - int index, int offset, net::IOBuffer* buf, int buf_len,
|
| - const net::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);
|
|
|
| @@ -835,35 +846,44 @@
|
| 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;
|
| }
|
|
|
| -int EntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback) {
|
| +int EntryImpl::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback) {
|
| 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;
|
| }
|
|
|
| -int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback) {
|
| +int EntryImpl::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback) {
|
| 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);
|
| + const CompletionCallback& callback) {
|
| + if (!background_queue_)
|
| + return net::ERR_UNEXPECTED;
|
| +
|
| + background_queue_->GetAvailableRange(this, offset, len, start, callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| @@ -877,14 +897,18 @@
|
| }
|
|
|
| void EntryImpl::CancelSparseIO() {
|
| - backend_->background_queue()->CancelSparseIO(this);
|
| + if (background_queue_)
|
| + background_queue_->CancelSparseIO(this);
|
| }
|
|
|
| -int EntryImpl::ReadyForSparseIO(const net::CompletionCallback& callback) {
|
| +int EntryImpl::ReadyForSparseIO(const 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;
|
| }
|
|
|
| @@ -896,6 +920,11 @@
|
| // written before).
|
| EntryImpl::~EntryImpl() {
|
| Log("~EntryImpl in");
|
| + if (!backend_) {
|
| + entry_.clear_modified();
|
| + node_.clear_modified();
|
| + return;
|
| + }
|
|
|
| // Save the sparse info to disk. This will generate IO for this entry and
|
| // maybe for a child entry, so it is important to do it before deleting this
|
| @@ -943,9 +972,9 @@
|
|
|
| // ------------------------------------------------------------------------
|
|
|
| -int EntryImpl::InternalReadData(
|
| - int index, int offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback) {
|
| +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;
|
| if (index < 0 || index >= kNumStreams)
|
| @@ -958,6 +987,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)
|
| @@ -1024,9 +1056,10 @@
|
| return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING;
|
| }
|
|
|
| -int EntryImpl::InternalWriteData(
|
| - int index, int offset, net::IOBuffer* buf, int buf_len,
|
| - const net::CompletionCallback& callback, bool truncate) {
|
| +int EntryImpl::InternalWriteData(int index, int offset,
|
| + IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback,
|
| + bool truncate) {
|
| DCHECK(node_.Data()->dirty || read_only_);
|
| DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len;
|
| if (index < 0 || index >= kNumStreams)
|
| @@ -1035,6 +1068,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 +1176,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 +1202,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 +1220,9 @@
|
| }
|
|
|
| void EntryImpl::UpdateRank(bool modified) {
|
| + if (!backend_)
|
| + return;
|
| +
|
| if (!doomed_) {
|
| // Everything is handled by the backend.
|
| backend_->UpdateRank(this, modified);
|
| @@ -1195,6 +1237,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 +1511,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.
|
|
|