OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/blockfile/in_flight_backend_io.h" | 5 #include "net/disk_cache/blockfile/in_flight_backend_io.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/profiler/scoped_profile.h" | 11 #include "base/profiler/scoped_tracker.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/disk_cache/blockfile/backend_impl.h" | 14 #include "net/disk_cache/blockfile/backend_impl.h" |
15 #include "net/disk_cache/blockfile/entry_impl.h" | 15 #include "net/disk_cache/blockfile/entry_impl.h" |
16 #include "net/disk_cache/blockfile/histogram_macros.h" | 16 #include "net/disk_cache/blockfile/histogram_macros.h" |
17 | 17 |
18 // Provide a BackendImpl object to macros from histogram_macros.h. | 18 // Provide a BackendImpl object to macros from histogram_macros.h. |
19 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ | 19 #define CACHE_UMA_BACKEND_IMPL_OBJ backend_ |
20 | 20 |
21 namespace disk_cache { | 21 namespace disk_cache { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 if (IsEntryOperation()) { | 59 if (IsEntryOperation()) { |
60 CACHE_UMA(TIMES, "TotalIOTime", 0, ElapsedTime()); | 60 CACHE_UMA(TIMES, "TotalIOTime", 0, ElapsedTime()); |
61 } | 61 } |
62 | 62 |
63 if (!ReturnsEntry()) | 63 if (!ReturnsEntry()) |
64 return; | 64 return; |
65 | 65 |
66 if (result() == net::OK) { | 66 if (result() == net::OK) { |
67 static_cast<EntryImpl*>(*entry_ptr_)->OnEntryCreated(backend_); | 67 static_cast<EntryImpl*>(*entry_ptr_)->OnEntryCreated(backend_); |
68 if (cancel) { | 68 if (cancel) { |
69 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422516 is | 69 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is |
70 // fixed. | 70 // fixed. |
71 tracked_objects::ScopedProfile tracking_profile( | 71 tracked_objects::ScopedTracker tracking_profile( |
72 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 BackendIO::OnDone")); | 72 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 BackendIO::OnDone")); |
73 | 73 |
74 (*entry_ptr_)->Close(); | 74 (*entry_ptr_)->Close(); |
75 } | 75 } |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 bool BackendIO::IsEntryOperation() { | 79 bool BackendIO::IsEntryOperation() { |
80 return operation_ > OP_MAX_BACKEND; | 80 return operation_ > OP_MAX_BACKEND; |
81 } | 81 } |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 void InFlightBackendIO::WaitForPendingIO() { | 497 void InFlightBackendIO::WaitForPendingIO() { |
498 InFlightIO::WaitForPendingIO(); | 498 InFlightIO::WaitForPendingIO(); |
499 } | 499 } |
500 | 500 |
501 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, | 501 void InFlightBackendIO::OnOperationComplete(BackgroundIO* operation, |
502 bool cancel) { | 502 bool cancel) { |
503 BackendIO* op = static_cast<BackendIO*>(operation); | 503 BackendIO* op = static_cast<BackendIO*>(operation); |
504 op->OnDone(cancel); | 504 op->OnDone(cancel); |
505 | 505 |
506 if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) { | 506 if (!op->callback().is_null() && (!cancel || op->IsEntryOperation())) { |
507 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422516 is fixed. | 507 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422516 is fixed. |
508 tracked_objects::ScopedProfile tracking_profile( | 508 tracked_objects::ScopedTracker tracking_profile( |
509 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 509 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
510 "422516 InFlightBackendIO::OnOperationComplete")); | 510 "422516 InFlightBackendIO::OnOperationComplete")); |
511 | 511 |
512 op->callback().Run(op->result()); | 512 op->callback().Run(op->result()); |
513 } | 513 } |
514 } | 514 } |
515 | 515 |
516 void InFlightBackendIO::PostOperation(BackendIO* operation) { | 516 void InFlightBackendIO::PostOperation(BackendIO* operation) { |
517 background_thread_->PostTask( | 517 background_thread_->PostTask( |
518 FROM_HERE, base::Bind(&BackendIO::ExecuteOperation, operation)); | 518 FROM_HERE, base::Bind(&BackendIO::ExecuteOperation, operation)); |
519 OnOperationPosted(operation); | 519 OnOperationPosted(operation); |
520 } | 520 } |
521 | 521 |
522 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() { | 522 base::WeakPtr<InFlightBackendIO> InFlightBackendIO::GetWeakPtr() { |
523 return ptr_factory_.GetWeakPtr(); | 523 return ptr_factory_.GetWeakPtr(); |
524 } | 524 } |
525 | 525 |
526 } // namespace | 526 } // namespace |
OLD | NEW |