| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/disk_cache/backend_impl.h" | 11 #include "net/disk_cache/backend_impl.h" |
| 12 #include "net/disk_cache/entry_impl.h" | 12 #include "net/disk_cache/entry_impl.h" |
| 13 #include "net/disk_cache/histogram_macros.h" | 13 #include "net/disk_cache/histogram_macros.h" |
| 14 | 14 |
| 15 namespace disk_cache { | 15 namespace disk_cache { |
| 16 | 16 |
| 17 BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, | 17 BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, |
| 18 net::OldCompletionCallback* callback) | 18 net::OldCompletionCallback* callback) |
| 19 : BackgroundIO(controller), backend_(backend), callback_(callback), | 19 : BackgroundIO(controller), |
| 20 backend_(backend), |
| 21 old_callback_(callback), |
| 20 operation_(OP_NONE), | 22 operation_(OP_NONE), |
| 21 ALLOW_THIS_IN_INITIALIZER_LIST( | 23 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 22 my_callback_(this, &BackendIO::OnIOComplete)) { | 24 my_callback_(this, &BackendIO::OnIOComplete)) { |
| 25 start_time_ = base::TimeTicks::Now(); |
| 26 } |
| 27 |
| 28 BackendIO::BackendIO(InFlightIO* controller, BackendImpl* backend, |
| 29 const net::CompletionCallback& callback) |
| 30 : BackgroundIO(controller), |
| 31 backend_(backend), |
| 32 old_callback_(NULL), |
| 33 callback_(callback), |
| 34 operation_(OP_NONE), |
| 35 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 36 my_callback_(this, &BackendIO::OnIOComplete)) { |
| 23 start_time_ = base::TimeTicks::Now(); | 37 start_time_ = base::TimeTicks::Now(); |
| 24 } | 38 } |
| 25 | 39 |
| 26 // Runs on the background thread. | 40 // Runs on the background thread. |
| 27 void BackendIO::ExecuteOperation() { | 41 void BackendIO::ExecuteOperation() { |
| 28 if (IsEntryOperation()) | 42 if (IsEntryOperation()) |
| 29 return ExecuteEntryOperation(); | 43 return ExecuteEntryOperation(); |
| 30 | 44 |
| 31 ExecuteBackendOperation(); | 45 ExecuteBackendOperation(); |
| 32 } | 46 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 PostOperation(operation); | 320 PostOperation(operation); |
| 307 } | 321 } |
| 308 | 322 |
| 309 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, | 323 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, |
| 310 OldCompletionCallback* callback) { | 324 OldCompletionCallback* callback) { |
| 311 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 325 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 312 operation->OpenEntry(key, entry); | 326 operation->OpenEntry(key, entry); |
| 313 PostOperation(operation); | 327 PostOperation(operation); |
| 314 } | 328 } |
| 315 | 329 |
| 330 void InFlightBackendIO::OpenEntry(const std::string& key, Entry** entry, |
| 331 const net::CompletionCallback& callback) { |
| 332 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 333 operation->OpenEntry(key, entry); |
| 334 PostOperation(operation); |
| 335 } |
| 336 |
| 316 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, | 337 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, |
| 317 OldCompletionCallback* callback) { | 338 OldCompletionCallback* callback) { |
| 318 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 339 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 319 operation->CreateEntry(key, entry); | 340 operation->CreateEntry(key, entry); |
| 320 PostOperation(operation); | 341 PostOperation(operation); |
| 321 } | 342 } |
| 322 | 343 |
| 344 void InFlightBackendIO::CreateEntry(const std::string& key, Entry** entry, |
| 345 const net::CompletionCallback& callback) { |
| 346 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 347 operation->CreateEntry(key, entry); |
| 348 PostOperation(operation); |
| 349 } |
| 350 |
| 323 void InFlightBackendIO::DoomEntry(const std::string& key, | 351 void InFlightBackendIO::DoomEntry(const std::string& key, |
| 324 OldCompletionCallback* callback) { | 352 OldCompletionCallback* callback) { |
| 325 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 353 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 326 operation->DoomEntry(key); | 354 operation->DoomEntry(key); |
| 327 PostOperation(operation); | 355 PostOperation(operation); |
| 328 } | 356 } |
| 329 | 357 |
| 330 void InFlightBackendIO::DoomAllEntries(OldCompletionCallback* callback) { | 358 void InFlightBackendIO::DoomAllEntries(OldCompletionCallback* callback) { |
| 331 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 359 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 332 operation->DoomAllEntries(); | 360 operation->DoomAllEntries(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 427 } |
| 400 | 428 |
| 401 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, | 429 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, |
| 402 net::IOBuffer* buf, int buf_len, | 430 net::IOBuffer* buf, int buf_len, |
| 403 OldCompletionCallback* callback) { | 431 OldCompletionCallback* callback) { |
| 404 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 432 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 405 operation->ReadData(entry, index, offset, buf, buf_len); | 433 operation->ReadData(entry, index, offset, buf, buf_len); |
| 406 PostOperation(operation); | 434 PostOperation(operation); |
| 407 } | 435 } |
| 408 | 436 |
| 437 void InFlightBackendIO::ReadData(EntryImpl* entry, int index, int offset, |
| 438 net::IOBuffer* buf, int buf_len, |
| 439 const net::CompletionCallback& callback) { |
| 440 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 441 operation->ReadData(entry, index, offset, buf, buf_len); |
| 442 PostOperation(operation); |
| 443 } |
| 444 |
| 409 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, | 445 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, |
| 410 net::IOBuffer* buf, int buf_len, | 446 net::IOBuffer* buf, int buf_len, |
| 411 bool truncate, | 447 bool truncate, |
| 412 OldCompletionCallback* callback) { | 448 OldCompletionCallback* callback) { |
| 413 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 449 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 414 operation->WriteData(entry, index, offset, buf, buf_len, truncate); | 450 operation->WriteData(entry, index, offset, buf, buf_len, truncate); |
| 415 PostOperation(operation); | 451 PostOperation(operation); |
| 416 } | 452 } |
| 417 | 453 |
| 454 void InFlightBackendIO::WriteData(EntryImpl* entry, int index, int offset, |
| 455 net::IOBuffer* buf, int buf_len, |
| 456 bool truncate, |
| 457 const net::CompletionCallback& callback) { |
| 458 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 459 operation->WriteData(entry, index, offset, buf, buf_len, truncate); |
| 460 PostOperation(operation); |
| 461 } |
| 462 |
| 418 void InFlightBackendIO::ReadSparseData(EntryImpl* entry, int64 offset, | 463 void InFlightBackendIO::ReadSparseData(EntryImpl* entry, int64 offset, |
| 419 net::IOBuffer* buf, int buf_len, | 464 net::IOBuffer* buf, int buf_len, |
| 420 OldCompletionCallback* callback) { | 465 OldCompletionCallback* callback) { |
| 421 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 466 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 422 operation->ReadSparseData(entry, offset, buf, buf_len); | 467 operation->ReadSparseData(entry, offset, buf, buf_len); |
| 423 PostOperation(operation); | 468 PostOperation(operation); |
| 424 } | 469 } |
| 425 | 470 |
| 426 void InFlightBackendIO::WriteSparseData(EntryImpl* entry, int64 offset, | 471 void InFlightBackendIO::WriteSparseData(EntryImpl* entry, int64 offset, |
| 427 net::IOBuffer* buf, int buf_len, | 472 net::IOBuffer* buf, int buf_len, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 457 } | 502 } |
| 458 | 503 |
| 459 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, | 504 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, |
| 460 bool cancel) { | 505 bool cancel) { |
| 461 BackendIO* op = static_cast<BackendIO*>(operation); | 506 BackendIO* op = static_cast<BackendIO*>(operation); |
| 462 | 507 |
| 463 if (op->IsEntryOperation()) { | 508 if (op->IsEntryOperation()) { |
| 464 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); | 509 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); |
| 465 } | 510 } |
| 466 | 511 |
| 467 if (op->callback() && (!cancel || op->IsEntryOperation())) | 512 if (op->old_callback() && (!cancel || op->IsEntryOperation())) |
| 468 op->callback()->Run(op->result()); | 513 op->old_callback()->Run(op->result()); |
| 514 else if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) |
| 515 op->callback().Run(op->result()); |
| 469 } | 516 } |
| 470 | 517 |
| 471 void InFlightBackendIO::PostOperation(BackendIO* operation) { | 518 void InFlightBackendIO::PostOperation(BackendIO* operation) { |
| 472 background_thread_->PostTask(FROM_HERE, | 519 background_thread_->PostTask(FROM_HERE, |
| 473 base::Bind(&BackendIO::ExecuteOperation, operation)); | 520 base::Bind(&BackendIO::ExecuteOperation, operation)); |
| 474 OnOperationPosted(operation); | 521 OnOperationPosted(operation); |
| 475 } | 522 } |
| 476 | 523 |
| 477 } // namespace | 524 } // namespace |
| OLD | NEW |