| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 operation->DoomEntry(key); | 340 operation->DoomEntry(key); |
| 327 PostOperation(operation); | 341 PostOperation(operation); |
| 328 } | 342 } |
| 329 | 343 |
| 330 void InFlightBackendIO::DoomAllEntries(OldCompletionCallback* callback) { | 344 void InFlightBackendIO::DoomAllEntries(OldCompletionCallback* callback) { |
| 331 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 345 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 332 operation->DoomAllEntries(); | 346 operation->DoomAllEntries(); |
| 333 PostOperation(operation); | 347 PostOperation(operation); |
| 334 } | 348 } |
| 335 | 349 |
| 350 void InFlightBackendIO::DoomAllEntries( |
| 351 const net::CompletionCallback& callback) { |
| 352 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 353 operation->DoomAllEntries(); |
| 354 PostOperation(operation); |
| 355 } |
| 356 |
| 336 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, | 357 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, |
| 337 const base::Time end_time, | 358 const base::Time end_time, |
| 338 OldCompletionCallback* callback) { | 359 OldCompletionCallback* callback) { |
| 339 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 360 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 340 operation->DoomEntriesBetween(initial_time, end_time); | 361 operation->DoomEntriesBetween(initial_time, end_time); |
| 341 PostOperation(operation); | 362 PostOperation(operation); |
| 342 } | 363 } |
| 343 | 364 |
| 365 void InFlightBackendIO::DoomEntriesBetween(const base::Time initial_time, |
| 366 const base::Time end_time, |
| 367 const net::CompletionCallback& callback) { |
| 368 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 369 operation->DoomEntriesBetween(initial_time, end_time); |
| 370 PostOperation(operation); |
| 371 } |
| 372 |
| 344 void InFlightBackendIO::DoomEntriesSince(const base::Time initial_time, | 373 void InFlightBackendIO::DoomEntriesSince(const base::Time initial_time, |
| 345 OldCompletionCallback* callback) { | 374 OldCompletionCallback* callback) { |
| 346 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 375 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| 347 operation->DoomEntriesSince(initial_time); | 376 operation->DoomEntriesSince(initial_time); |
| 348 PostOperation(operation); | 377 PostOperation(operation); |
| 349 } | 378 } |
| 350 | 379 |
| 351 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, | 380 void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, |
| 352 OldCompletionCallback* callback) { | 381 OldCompletionCallback* callback) { |
| 353 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); | 382 scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback)); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 486 } |
| 458 | 487 |
| 459 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, | 488 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, |
| 460 bool cancel) { | 489 bool cancel) { |
| 461 BackendIO* op = static_cast<BackendIO*>(operation); | 490 BackendIO* op = static_cast<BackendIO*>(operation); |
| 462 | 491 |
| 463 if (op->IsEntryOperation()) { | 492 if (op->IsEntryOperation()) { |
| 464 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); | 493 CACHE_UMA(TIMES, "TotalIOTime", 0, op->ElapsedTime()); |
| 465 } | 494 } |
| 466 | 495 |
| 467 if (op->callback() && (!cancel || op->IsEntryOperation())) | 496 if (op->old_callback() && (!cancel || op->IsEntryOperation())) |
| 468 op->callback()->Run(op->result()); | 497 op->old_callback()->Run(op->result()); |
| 498 else if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) |
| 499 op->callback().Run(op->result()); |
| 469 } | 500 } |
| 470 | 501 |
| 471 void InFlightBackendIO::PostOperation(BackendIO* operation) { | 502 void InFlightBackendIO::PostOperation(BackendIO* operation) { |
| 472 background_thread_->PostTask(FROM_HERE, | 503 background_thread_->PostTask(FROM_HERE, |
| 473 base::Bind(&BackendIO::ExecuteOperation, operation)); | 504 base::Bind(&BackendIO::ExecuteOperation, operation)); |
| 474 OnOperationPosted(operation); | 505 OnOperationPosted(operation); |
| 475 } | 506 } |
| 476 | 507 |
| 477 } // namespace | 508 } // namespace |
| OLD | NEW |