diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 19:11:51 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 19:11:51 +0000 |
commit | 8ebf9b135df2b2a79cf130d39a48185b8f851338 (patch) | |
tree | b1f393ed627e91bf098bffff4fac3b9f3696e59b /net/disk_cache | |
parent | 0b349ba539020caa0201c6523813a16fa41a3448 (diff) | |
download | chromium_src-8ebf9b135df2b2a79cf130d39a48185b8f851338.zip chromium_src-8ebf9b135df2b2a79cf130d39a48185b8f851338.tar.gz chromium_src-8ebf9b135df2b2a79cf130d39a48185b8f851338.tar.bz2 |
base::Bind: Convert disk_cache_based_ssl_host_info.
BUG=none
TEST=none
R=csilv@chromium.org
Review URL: http://codereview.chromium.org/8794003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 14 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.h | 6 | ||||
-rw-r--r-- | net/disk_cache/disk_cache.h | 9 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.cc | 278 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.h | 14 | ||||
-rw-r--r-- | net/disk_cache/in_flight_backend_io.cc | 53 | ||||
-rw-r--r-- | net/disk_cache/in_flight_backend_io.h | 22 | ||||
-rw-r--r-- | net/disk_cache/mem_backend_impl.cc | 16 | ||||
-rw-r--r-- | net/disk_cache/mem_backend_impl.h | 4 | ||||
-rw-r--r-- | net/disk_cache/mem_entry_impl.cc | 40 | ||||
-rw-r--r-- | net/disk_cache/mem_entry_impl.h | 6 |
11 files changed, 450 insertions, 12 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 14a2722..1c6c92a 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -1381,6 +1381,13 @@ int BackendImpl::OpenEntry(const std::string& key, Entry** entry, return net::ERR_IO_PENDING; } +int BackendImpl::OpenEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) { + DCHECK(!callback.is_null()); + background_queue_.OpenEntry(key, entry, callback); + return net::ERR_IO_PENDING; +} + int BackendImpl::CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) { DCHECK(callback); @@ -1388,6 +1395,13 @@ int BackendImpl::CreateEntry(const std::string& key, Entry** entry, return net::ERR_IO_PENDING; } +int BackendImpl::CreateEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) { + DCHECK(!callback.is_null()); + background_queue_.CreateEntry(key, entry, callback); + return net::ERR_IO_PENDING; +} + int BackendImpl::DoomEntry(const std::string& key, OldCompletionCallback* callback) { DCHECK(callback); diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h index 1e38678..0cf1fac 100644 --- a/net/disk_cache/backend_impl.h +++ b/net/disk_cache/backend_impl.h @@ -65,7 +65,7 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { int SyncInit(); void CleanupCache(); - // Same bahavior as OpenNextEntry but walks the list from back to front. + // Same behavior as OpenNextEntry but walks the list from back to front. int OpenPrevEntry(void** iter, Entry** prev_entry, OldCompletionCallback* callback); @@ -260,8 +260,12 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { virtual int32 GetEntryCount() const OVERRIDE; virtual int OpenEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; + virtual int OpenEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) OVERRIDE; virtual int CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; + virtual int CreateEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntry(const std::string& key, OldCompletionCallback* callback) OVERRIDE; virtual int DoomAllEntries(OldCompletionCallback* callback) OVERRIDE; diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h index 3e0efa6..8fc74b7 100644 --- a/net/disk_cache/disk_cache.h +++ b/net/disk_cache/disk_cache.h @@ -78,6 +78,8 @@ class NET_EXPORT Backend { // |entry| must remain valid until the operation completes. virtual int OpenEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) = 0; + virtual int OpenEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) = 0; // Creates a new entry. Upon success, the out param holds a pointer to an // Entry object representing the newly created disk cache entry. When the @@ -87,6 +89,8 @@ class NET_EXPORT Backend { // receive the |entry| must remain valid until the operation completes. virtual int CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) = 0; + virtual int CreateEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) = 0; // Marks the entry, specified by the given key, for deletion. The return value // is a net error code. If this method returns ERR_IO_PENDING, the |callback| @@ -179,6 +183,8 @@ class NET_EXPORT Entry { // performed from the callback code. virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* completion_callback) = 0; + virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback) = 0; // Copies cache data from the given buffer of length |buf_len|. If // completion_callback is null, then this call blocks until the write @@ -196,6 +202,9 @@ class NET_EXPORT Entry { virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* completion_callback, bool truncate) = 0; + virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback, + bool truncate) = 0; // Sparse entries support: // diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 7e13029..7ba6e94 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -35,6 +35,14 @@ class SyncCallback: public disk_cache::FileIOCallback { SyncCallback(disk_cache::EntryImpl* entry, net::IOBuffer* buffer, net::OldCompletionCallback* callback, net::NetLog::EventType end_event_type) + : entry_(entry), old_callback_(callback), buf_(buffer), + start_(TimeTicks::Now()), end_event_type_(end_event_type) { + entry->AddRef(); + entry->IncrementIoCount(); + } + 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->AddRef(); @@ -47,7 +55,8 @@ class SyncCallback: public disk_cache::FileIOCallback { private: disk_cache::EntryImpl* entry_; - net::OldCompletionCallback* callback_; + net::OldCompletionCallback* old_callback_; + net::CompletionCallback callback_; scoped_refptr<net::IOBuffer> buf_; TimeTicks start_; const net::NetLog::EventType end_event_type_; @@ -57,7 +66,7 @@ class SyncCallback: public disk_cache::FileIOCallback { void SyncCallback::OnFileIOComplete(int bytes_copied) { entry_->DecrementIoCount(); - if (callback_) { + if (old_callback_ || !callback_.is_null()) { if (entry_->net_log().IsLoggingAllEvents()) { entry_->net_log().EndEvent( end_event_type_, @@ -65,14 +74,19 @@ void SyncCallback::OnFileIOComplete(int bytes_copied) { new disk_cache::ReadWriteCompleteParameters(bytes_copied))); } entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_); - callback_->Run(bytes_copied); + + if (old_callback_) + old_callback_->Run(bytes_copied); + else + callback_.Run(bytes_copied); } entry_->Release(); delete this; } void SyncCallback::Discard() { - callback_ = NULL; + old_callback_ = NULL; + callback_.Reset(); buf_ = NULL; OnFileIOComplete(0); } @@ -327,6 +341,26 @@ int EntryImpl::ReadDataImpl(int index, int offset, net::IOBuffer* buf, return result; } +int EntryImpl::ReadDataImpl( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_ENTRY_READ_DATA, + make_scoped_refptr( + new ReadWriteDataParameters(index, offset, buf_len, false))); + } + + int result = InternalReadData(index, offset, buf, buf_len, callback); + + if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_ENTRY_READ_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); + } + return result; +} + int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate) { @@ -348,6 +382,27 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf, return result; } +int EntryImpl::WriteDataImpl( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback, bool truncate) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_ENTRY_WRITE_DATA, + make_scoped_refptr( + new ReadWriteDataParameters(index, offset, buf_len, truncate))); + } + + int result = InternalWriteData(index, offset, buf, buf_len, callback, + truncate); + + if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_ENTRY_WRITE_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); + } + return result; +} + int EntryImpl::ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback) { DCHECK(node_.Data()->dirty || read_only_); @@ -818,6 +873,27 @@ int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, return net::ERR_IO_PENDING; } +int EntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) { + if (callback.is_null()) + return ReadDataImpl(index, offset, buf, buf_len, callback); + + DCHECK(node_.Data()->dirty || read_only_); + 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::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate) { if (!callback) @@ -835,6 +911,24 @@ int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, return net::ERR_IO_PENDING; } +int EntryImpl::WriteData( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback, bool truncate) { + if (callback.is_null()) + return WriteDataImpl(index, offset, buf, buf_len, callback, truncate); + + DCHECK(node_.Data()->dirty || read_only_); + 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::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) { if (!callback) @@ -1013,6 +1107,82 @@ int EntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, return (completed || !callback) ? buf_len : net::ERR_IO_PENDING; } +int EntryImpl::InternalReadData( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) { + DCHECK(node_.Data()->dirty || read_only_); + DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len; + 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; + + TimeTicks start = TimeTicks::Now(); + + if (offset + buf_len > entry_size) + buf_len = entry_size - offset; + + UpdateRank(false); + + backend_->OnEvent(Stats::READ_DATA); + backend_->OnRead(buf_len); + + Addr address(entry_.Data()->data_addr[index]); + int eof = address.is_initialized() ? entry_size : 0; + if (user_buffers_[index].get() && + user_buffers_[index]->PreRead(eof, offset, &buf_len)) { + // Complete the operation locally. + buf_len = user_buffers_[index]->Read(offset, buf, buf_len); + ReportIOTime(kRead, start); + return buf_len; + } + + address.set_value(entry_.Data()->data_addr[index]); + DCHECK(address.is_initialized()); + if (!address.is_initialized()) + return net::ERR_FAILED; + + File* file = GetBackingFile(address, index); + if (!file) + return net::ERR_FAILED; + + size_t file_offset = offset; + if (address.is_block_file()) { + DCHECK_LE(offset + buf_len, kMaxBlockSize); + 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); + } + + TimeTicks start_async = TimeTicks::Now(); + + bool completed; + if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) { + if (io_callback) + io_callback->Discard(); + return net::ERR_FAILED; + } + + if (io_callback && completed) + io_callback->Discard(); + + if (io_callback) + ReportIOTime(kReadAsync1, start_async); + + ReportIOTime(kRead, start); + return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING; +} + int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate) { @@ -1113,6 +1283,106 @@ int EntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, return (completed || !callback) ? 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) { + DCHECK(node_.Data()->dirty || read_only_); + DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len; + 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 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; + if (size <= max_file_size) + size = kint32max; + backend_->TooMuchStorageRequested(size); + return net::ERR_FAILED; + } + + TimeTicks start = TimeTicks::Now(); + + // Read the size at this point (it may change inside prepare). + int entry_size = entry_.Data()->data_size[index]; + bool extending = entry_size < offset + buf_len; + truncate = truncate && entry_size > offset + buf_len; + Trace("To PrepareTarget 0x%x", entry_.address().value()); + if (!PrepareTarget(index, offset, buf_len, truncate)) + return net::ERR_FAILED; + + Trace("From PrepareTarget 0x%x", entry_.address().value()); + if (extending || truncate) + UpdateSize(index, entry_size, offset + buf_len); + + UpdateRank(true); + + backend_->OnEvent(Stats::WRITE_DATA); + backend_->OnWrite(buf_len); + + if (user_buffers_[index].get()) { + // Complete the operation locally. + user_buffers_[index]->Write(offset, buf, buf_len); + ReportIOTime(kWrite, start); + return buf_len; + } + + Addr address(entry_.Data()->data_addr[index]); + if (offset + buf_len == 0) { + if (truncate) { + DCHECK(!address.is_initialized()); + } + return 0; + } + + File* file = GetBackingFile(address, index); + if (!file) + return net::ERR_FAILED; + + size_t file_offset = offset; + if (address.is_block_file()) { + DCHECK_LE(offset + buf_len, kMaxBlockSize); + file_offset += address.start_block() * address.BlockSize() + + kBlockHeaderSize; + } else if (truncate || (extending && !buf_len)) { + if (!file->SetLength(offset + buf_len)) + return net::ERR_FAILED; + } + + if (!buf_len) + return 0; + + SyncCallback* io_callback = NULL; + if (!callback.is_null()) { + 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 (io_callback) + io_callback->Discard(); + return net::ERR_FAILED; + } + + if (io_callback && completed) + io_callback->Discard(); + + if (io_callback) + ReportIOTime(kWriteAsync1, start_async); + + ReportIOTime(kWrite, start); + return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING; +} + // ------------------------------------------------------------------------ bool EntryImpl::CreateDataBlock(int index, int size) { diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h index 62ec9d7..6ff7152 100644 --- a/net/disk_cache/entry_impl.h +++ b/net/disk_cache/entry_impl.h @@ -41,8 +41,12 @@ class NET_EXPORT_PRIVATE EntryImpl void DoomImpl(); int ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback); + int ReadDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback); int WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate); + int WriteDataImpl(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback, bool truncate); int ReadSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback); int WriteSparseDataImpl(int64 offset, net::IOBuffer* buf, int buf_len, @@ -149,9 +153,15 @@ class NET_EXPORT_PRIVATE EntryImpl virtual int ReadData( int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; + virtual int ReadData( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback) OVERRIDE; virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback, bool truncate) OVERRIDE; + virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback, + bool truncate) OVERRIDE; virtual int ReadSparseData( int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; @@ -177,8 +187,12 @@ class NET_EXPORT_PRIVATE EntryImpl // separate functions to make logging of results simpler. int InternalReadData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback); + int InternalReadData(int index, int offset, net::IOBuffer* buf, + int buf_len, const net::CompletionCallback& callback); int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback, bool truncate); + int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback, bool truncate); // Initializes the storage for an internal or external data block. bool CreateDataBlock(int index, int size); diff --git a/net/disk_cache/in_flight_backend_io.cc b/net/disk_cache/in_flight_backend_io.cc index b99d627..d4e208a 100644 --- a/net/disk_cache/in_flight_backend_io.cc +++ b/net/disk_cache/in_flight_backend_io.cc @@ -16,7 +16,21 @@ namespace disk_cache { BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, net::OldCompletionCallback* callback) - : BackgroundIO(controller), backend_(backend), callback_(callback), + : BackgroundIO(controller), + backend_(backend), + old_callback_(callback), + operation_(OP_NONE), + ALLOW_THIS_IN_INITIALIZER_LIST( + my_callback_(this, &BackendIO::OnIOComplete)) { + start_time_ = base::TimeTicks::Now(); +} + +BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, + const net::CompletionCallback& callback) + : BackgroundIO(controller), + backend_(backend), + old_callback_(NULL), + callback_(callback), operation_(OP_NONE), ALLOW_THIS_IN_INITIALIZER_LIST( my_callback_(this, &BackendIO::OnIOComplete)) { @@ -313,6 +327,13 @@ void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, PostOperation(operation); } +void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) { + scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + operation->OpenEntry(key, entry); + PostOperation(operation); +} + void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) { scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); @@ -320,6 +341,13 @@ void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, PostOperation(operation); } +void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) { + scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + operation->CreateEntry(key, entry); + PostOperation(operation); +} + void InFlightBackendIO::DoomEntry(const std::string& key, OldCompletionCallback* callback) { scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); @@ -406,6 +434,14 @@ void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, PostOperation(operation); } +void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, + net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& callback) { + scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + operation->ReadData(entry, index, offset, buf, buf_len); + PostOperation(operation); +} + void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, int buf_len, bool truncate, @@ -415,6 +451,15 @@ void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, PostOperation(operation); } +void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, + net::IOBuffer* buf, int buf_len, + bool truncate, + const net::CompletionCallback& callback) { + scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); + operation->WriteData(entry, index, offset, buf, buf_len, truncate); + PostOperation(operation); +} + void InFlightBackendIO::ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, OldCompletionCallback* callback) { @@ -464,8 +509,10 @@ void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); } - if (op->callback() && (!cancel || op->IsEntryOperation())) - op->callback()->Run(op->result()); + if (op->old_callback() && (!cancel || op->IsEntryOperation())) + op->old_callback()->Run(op->result()); + else if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) + op->callback().Run(op->result()); } void InFlightBackendIO::PostOperation(BackendIO* operation) { diff --git a/net/disk_cache/in_flight_backend_io.h b/net/disk_cache/in_flight_backend_io.h index 17efb1a..96dc3e4 100644 --- a/net/disk_cache/in_flight_backend_io.h +++ b/net/disk_cache/in_flight_backend_io.h @@ -27,6 +27,8 @@ class BackendIO : public BackgroundIO { public: BackendIO(InFlightIO* controller, BackendImpl* backend, net::OldCompletionCallback* callback); + BackendIO(InFlightIO* controller, BackendImpl* backend, + const net::CompletionCallback& callback); // Runs the actual operation on the background thread. void ExecuteOperation(); @@ -37,7 +39,8 @@ class BackendIO : public BackgroundIO { // Returns true if this operation is directed to an entry (vs. the backend). bool IsEntryOperation(); - net::OldCompletionCallback* callback() { return callback_; } + net::OldCompletionCallback* old_callback() const { return old_callback_; } + net::CompletionCallback callback() const { return callback_; } // Grabs an extra reference of entry_. void ReferenceEntry(); @@ -113,7 +116,8 @@ class BackendIO : public BackgroundIO { void ExecuteEntryOperation(); BackendImpl* backend_; - net::OldCompletionCallback* callback_; + net::OldCompletionCallback* old_callback_; + net::CompletionCallback callback_; Operation operation_; net::OldCompletionCallbackImpl<BackendIO> my_callback_; @@ -149,8 +153,12 @@ class InFlightBackendIO : public InFlightIO { void Init(net::OldCompletionCallback* callback); void OpenEntry(const std::string& key, Entry** entry, net::OldCompletionCallback* callback); + void OpenEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback); void CreateEntry(const std::string& key, Entry** entry, net::OldCompletionCallback* callback); + void CreateEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback); void DoomEntry(const std::string& key, net::OldCompletionCallback* callback); void DoomAllEntries(net::OldCompletionCallback* callback); void DoomEntriesBetween(const base::Time initial_time, @@ -170,8 +178,14 @@ class InFlightBackendIO : public InFlightIO { void RunTask(Task* task, net::OldCompletionCallback* callback); void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback); - void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, - int buf_len, bool truncate, net::OldCompletionCallback* callback); + void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, + int buf_len, const net::CompletionCallback& callback); + void WriteData(EntryImpl* entry, int index, int offset, + net::IOBuffer* buf, int buf_len, bool truncate, + net::OldCompletionCallback* callback); + void WriteData(EntryImpl* entry, int index, int offset, + net::IOBuffer* buf, int buf_len, bool truncate, + const net::CompletionCallback& callback); void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback); void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc index f08b316..2c54049 100644 --- a/net/disk_cache/mem_backend_impl.cc +++ b/net/disk_cache/mem_backend_impl.cc @@ -136,6 +136,14 @@ int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry, return net::ERR_FAILED; } +int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) { + if (OpenEntry(key, entry)) + return net::OK; + + return net::ERR_FAILED; +} + int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) { if (CreateEntry(key, entry)) @@ -144,6 +152,14 @@ int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry, return net::ERR_FAILED; } +int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) { + if (CreateEntry(key, entry)) + return net::OK; + + return net::ERR_FAILED; +} + int MemBackendImpl::DoomEntry(const std::string& key, OldCompletionCallback* callback) { if (DoomEntry(key)) diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h index abf1443..022b918 100644 --- a/net/disk_cache/mem_backend_impl.h +++ b/net/disk_cache/mem_backend_impl.h @@ -66,8 +66,12 @@ class NET_EXPORT_PRIVATE MemBackendImpl : public Backend { virtual int32 GetEntryCount() const OVERRIDE; virtual int OpenEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; + virtual int OpenEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) OVERRIDE; virtual int CreateEntry(const std::string& key, Entry** entry, OldCompletionCallback* callback) OVERRIDE; + virtual int CreateEntry(const std::string& key, Entry** entry, + const net::CompletionCallback& callback) OVERRIDE; virtual int DoomEntry(const std::string& key, OldCompletionCallback* callback) OVERRIDE; virtual int DoomAllEntries(OldCompletionCallback* callback) OVERRIDE; diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc index 677cd6a..4874761 100644 --- a/net/disk_cache/mem_entry_impl.cc +++ b/net/disk_cache/mem_entry_impl.cc @@ -185,6 +185,26 @@ int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, return result; } +int MemEntryImpl::ReadData( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_ENTRY_READ_DATA, + make_scoped_refptr( + new ReadWriteDataParameters(index, offset, buf_len, false))); + } + + int result = InternalReadData(index, offset, buf, buf_len); + + if (net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_ENTRY_READ_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); + } + return result; +} + int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback, bool truncate) { if (net_log_.IsLoggingAllEvents()) { @@ -204,6 +224,26 @@ int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, return result; } +int MemEntryImpl::WriteData( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback, bool truncate) { + if (net_log_.IsLoggingAllEvents()) { + net_log_.BeginEvent( + net::NetLog::TYPE_ENTRY_WRITE_DATA, + make_scoped_refptr( + new ReadWriteDataParameters(index, offset, buf_len, truncate))); + } + + int result = InternalWriteData(index, offset, buf, buf_len, truncate); + + if (net_log_.IsLoggingAllEvents()) { + net_log_.EndEvent( + net::NetLog::TYPE_ENTRY_WRITE_DATA, + make_scoped_refptr(new ReadWriteCompleteParameters(result))); + } + return result; +} + int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) { if (net_log_.IsLoggingAllEvents()) { diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h index b1d4703..2967154 100644 --- a/net/disk_cache/mem_entry_impl.h +++ b/net/disk_cache/mem_entry_impl.h @@ -101,9 +101,15 @@ class MemEntryImpl : public Entry { virtual int ReadData( int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; + virtual int ReadData( + int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback) OVERRIDE; virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback, bool truncate) OVERRIDE; + virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, + const net::CompletionCallback& completion_callback, + bool truncate) OVERRIDE; virtual int ReadSparseData( int64 offset, net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* completion_callback) OVERRIDE; |