| Index: net/disk_cache/in_flight_backend_io.cc
|
| ===================================================================
|
| --- net/disk_cache/in_flight_backend_io.cc (revision 126788)
|
| +++ net/disk_cache/in_flight_backend_io.cc (working copy)
|
| @@ -42,9 +42,25 @@
|
| DCHECK(IsEntryOperation());
|
| DCHECK_NE(result, net::ERR_IO_PENDING);
|
| result_ = result;
|
| - controller_->OnIOComplete(this);
|
| + NotifyController();
|
| }
|
|
|
| +// Runs on the primary thread.
|
| +void BackendIO::OnDone(bool cancel) {
|
| + if (IsEntryOperation()) {
|
| + CACHE_UMA(TIMES, "TotalIOTime", 0, ElapsedTime());
|
| + }
|
| +
|
| + if (!ReturnsEntry())
|
| + return;
|
| +
|
| + if (result() == net::OK) {
|
| + static_cast<EntryImpl*>(*entry_ptr_)->OnEntryCreated(backend_);
|
| + if (cancel)
|
| + (*entry_ptr_)->Close();
|
| + }
|
| +}
|
| +
|
| bool BackendIO::IsEntryOperation() {
|
| return operation_ > OP_MAX_BACKEND;
|
| }
|
| @@ -54,10 +70,6 @@
|
| entry_->AddRef();
|
| }
|
|
|
| -base::TimeDelta BackendIO::ElapsedTime() const {
|
| - return base::TimeTicks::Now() - start_time_;
|
| -}
|
| -
|
| void BackendIO::Init() {
|
| operation_ = OP_INIT;
|
| }
|
| @@ -196,6 +208,15 @@
|
|
|
| BackendIO::~BackendIO() {}
|
|
|
| +bool BackendIO::ReturnsEntry() {
|
| + return (operation_ == OP_OPEN || operation_ == OP_CREATE ||
|
| + operation_ == OP_OPEN_NEXT || operation_ == OP_OPEN_PREV);
|
| +}
|
| +
|
| +base::TimeDelta BackendIO::ElapsedTime() const {
|
| + return base::TimeTicks::Now() - start_time_;
|
| +}
|
| +
|
| // Runs on the background thread.
|
| void BackendIO::ExecuteBackendOperation() {
|
| switch (operation_) {
|
| @@ -254,7 +275,7 @@
|
| result_ = net::ERR_UNEXPECTED;
|
| }
|
| DCHECK_NE(net::ERR_IO_PENDING, result_);
|
| - controller_->OnIOComplete(this);
|
| + NotifyController();
|
| }
|
|
|
| // Runs on the background thread.
|
| @@ -263,23 +284,23 @@
|
| case OP_READ:
|
| result_ = entry_->ReadDataImpl(
|
| index_, offset_, buf_, buf_len_,
|
| - base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
|
| + base::Bind(&BackendIO::OnIOComplete, this));
|
| break;
|
| case OP_WRITE:
|
| result_ = entry_->WriteDataImpl(
|
| index_, offset_, buf_, buf_len_,
|
| - base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)),
|
| + base::Bind(&BackendIO::OnIOComplete, this),
|
| truncate_);
|
| break;
|
| case OP_READ_SPARSE:
|
| result_ = entry_->ReadSparseDataImpl(
|
| offset64_, buf_, buf_len_,
|
| - base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
|
| + base::Bind(&BackendIO::OnIOComplete, this));
|
| break;
|
| case OP_WRITE_SPARSE:
|
| result_ = entry_->WriteSparseDataImpl(
|
| offset64_, buf_, buf_len_,
|
| - base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
|
| + base::Bind(&BackendIO::OnIOComplete, this));
|
| break;
|
| case OP_GET_RANGE:
|
| result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_);
|
| @@ -290,20 +311,21 @@
|
| break;
|
| case OP_IS_READY:
|
| result_ = entry_->ReadyForSparseIOImpl(
|
| - base::Bind(&BackendIO::OnIOComplete, base::Unretained(this)));
|
| + base::Bind(&BackendIO::OnIOComplete, this));
|
| break;
|
| default:
|
| NOTREACHED() << "Invalid Operation";
|
| result_ = net::ERR_UNEXPECTED;
|
| }
|
| if (result_ != net::ERR_IO_PENDING)
|
| - controller_->OnIOComplete(this);
|
| + NotifyController();
|
| }
|
|
|
| InFlightBackendIO::InFlightBackendIO(BackendImpl* backend,
|
| base::MessageLoopProxy* background_thread)
|
| : backend_(backend),
|
| - background_thread_(background_thread) {
|
| + background_thread_(background_thread),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(ptr_factory_(this)) {
|
| }
|
|
|
| InFlightBackendIO::~InFlightBackendIO() {
|
| @@ -475,11 +497,8 @@
|
| void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation,
|
| bool cancel) {
|
| BackendIO* op = static_cast<BackendIO*>(operation);
|
| + op->OnDone(cancel);
|
|
|
| - if (op->IsEntryOperation()) {
|
| - CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime());
|
| - }
|
| -
|
| if (!op->callback().is_null() && (!cancel || op->IsEntryOperation()))
|
| op->callback().Run(op->result());
|
| }
|
| @@ -490,4 +509,8 @@
|
| OnOperationPosted(operation);
|
| }
|
|
|
| +base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() {
|
| + return ptr_factory_.GetWeakPtr();
|
| +}
|
| +
|
| } // namespace
|
|
|