| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/disk_cache/in_flight_backend_io.h" | 5 #include "net/disk_cache/in_flight_backend_io.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/disk_cache/backend_impl.h" | 10 #include "net/disk_cache/backend_impl.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 void BackendIO::CancelSparseIO(EntryImpl* entry) { | 175 void BackendIO::CancelSparseIO(EntryImpl* entry) { |
| 176 operation_ = OP_CANCEL_IO; | 176 operation_ = OP_CANCEL_IO; |
| 177 entry_ = entry; | 177 entry_ = entry; |
| 178 } | 178 } |
| 179 | 179 |
| 180 void BackendIO::ReadyForSparseIO(EntryImpl* entry) { | 180 void BackendIO::ReadyForSparseIO(EntryImpl* entry) { |
| 181 operation_ = OP_IS_READY; | 181 operation_ = OP_IS_READY; |
| 182 entry_ = entry; | 182 entry_ = entry; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void BackendIO::UpdateRankForExternalCacheHit(EntryImpl* entry) { |
| 186 operation_ = OP_UPDATE_RANK; |
| 187 entry_ = entry; |
| 188 } |
| 189 |
| 185 BackendIO::~BackendIO() {} | 190 BackendIO::~BackendIO() {} |
| 186 | 191 |
| 187 // Runs on the background thread. | 192 // Runs on the background thread. |
| 188 void BackendIO::ExecuteBackendOperation() { | 193 void BackendIO::ExecuteBackendOperation() { |
| 189 switch (operation_) { | 194 switch (operation_) { |
| 190 case OP_INIT: | 195 case OP_INIT: |
| 191 result_ = backend_->SyncInit(); | 196 result_ = backend_->SyncInit(); |
| 192 break; | 197 break; |
| 193 case OP_OPEN: | 198 case OP_OPEN: |
| 194 result_ = backend_->SyncOpenEntry(key_, entry_ptr_); | 199 result_ = backend_->SyncOpenEntry(key_, entry_ptr_); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 case OP_GET_RANGE: | 269 case OP_GET_RANGE: |
| 265 result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_); | 270 result_ = entry_->GetAvailableRangeImpl(offset64_, buf_len_, start_); |
| 266 break; | 271 break; |
| 267 case OP_CANCEL_IO: | 272 case OP_CANCEL_IO: |
| 268 entry_->CancelSparseIOImpl(); | 273 entry_->CancelSparseIOImpl(); |
| 269 result_ = net::OK; | 274 result_ = net::OK; |
| 270 break; | 275 break; |
| 271 case OP_IS_READY: | 276 case OP_IS_READY: |
| 272 result_ = entry_->ReadyForSparseIOImpl(&my_callback_); | 277 result_ = entry_->ReadyForSparseIOImpl(&my_callback_); |
| 273 break; | 278 break; |
| 279 case OP_UPDATE_RANK: |
| 280 entry_->UpdateRankForExternalCacheHitImpl(); |
| 281 result_ = net::OK; |
| 282 break; |
| 274 default: | 283 default: |
| 275 NOTREACHED() << "Invalid Operation"; | 284 NOTREACHED() << "Invalid Operation"; |
| 276 result_ = net::ERR_UNEXPECTED; | 285 result_ = net::ERR_UNEXPECTED; |
| 277 } | 286 } |
| 278 if (result_ != net::ERR_IO_PENDING) | 287 if (result_ != net::ERR_IO_PENDING) |
| 279 controller_->OnIOComplete(this); | 288 controller_->OnIOComplete(this); |
| 280 } | 289 } |
| 281 | 290 |
| 282 // --------------------------------------------------------------------------- | 291 // --------------------------------------------------------------------------- |
| 283 | 292 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 PostOperation(operation); | 438 PostOperation(operation); |
| 430 } | 439 } |
| 431 | 440 |
| 432 void InFlightBackendIO::ReadyForSparseIO(EntryImpl* entry, | 441 void InFlightBackendIO::ReadyForSparseIO(EntryImpl* entry, |
| 433 CompletionCallback* callback) { | 442 CompletionCallback* callback) { |
| 434 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 443 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 435 operation->ReadyForSparseIO(entry); | 444 operation->ReadyForSparseIO(entry); |
| 436 PostOperation(operation); | 445 PostOperation(operation); |
| 437 } | 446 } |
| 438 | 447 |
| 448 void InFlightBackendIO::UpdateRankForExternalCacheHit(EntryImpl* entry) { |
| 449 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, NULL)); |
| 450 operation->UpdateRankForExternalCacheHit(entry); |
| 451 PostOperation(operation); |
| 452 } |
| 453 |
| 439 void InFlightBackendIO::WaitForPendingIO() { | 454 void InFlightBackendIO::WaitForPendingIO() { |
| 440 InFlightIO::WaitForPendingIO(); | 455 InFlightIO::WaitForPendingIO(); |
| 441 } | 456 } |
| 442 | 457 |
| 443 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, | 458 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, |
| 444 bool cancel) { | 459 bool cancel) { |
| 445 BackendIO* op = static_cast<BackendIO*>(operation); | 460 BackendIO* op = static_cast<BackendIO*>(operation); |
| 446 | 461 |
| 447 if (op->IsEntryOperation()) { | 462 if (op->IsEntryOperation()) { |
| 448 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); | 463 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); |
| 449 } | 464 } |
| 450 | 465 |
| 451 if (op->callback() && (!cancel || op->IsEntryOperation())) | 466 if (op->callback() && (!cancel || op->IsEntryOperation())) |
| 452 op->callback()->Run(op->result()); | 467 op->callback()->Run(op->result()); |
| 453 } | 468 } |
| 454 | 469 |
| 455 void InFlightBackendIO::PostOperation(BackendIO* operation) { | 470 void InFlightBackendIO::PostOperation(BackendIO* operation) { |
| 456 background_thread_->PostTask(FROM_HERE, | 471 background_thread_->PostTask(FROM_HERE, |
| 457 NewRunnableMethod(operation, &BackendIO::ExecuteOperation)); | 472 NewRunnableMethod(operation, &BackendIO::ExecuteOperation)); |
| 458 OnOperationPosted(operation); | 473 OnOperationPosted(operation); |
| 459 } | 474 } |
| 460 | 475 |
| 461 } // namespace | 476 } // namespace |
| OLD | NEW |