| 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_io.h" | 5 #include "net/disk_cache/blockfile/in_flight_io.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/profiler/scoped_profile.h" |
| 10 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 11 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
| 14 | 15 |
| 15 namespace disk_cache { | 16 namespace disk_cache { |
| 16 | 17 |
| 17 BackgroundIO::BackgroundIO(InFlightIO* controller) | 18 BackgroundIO::BackgroundIO(InFlightIO* controller) |
| 18 : result_(-1), io_completed_(true, false), controller_(controller) { | 19 : result_(-1), io_completed_(true, false), controller_(controller) { |
| 19 } | 20 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 #endif | 81 #endif |
| 81 | 82 |
| 82 callback_task_runner_->PostTask( | 83 callback_task_runner_->PostTask( |
| 83 FROM_HERE, base::Bind(&BackgroundIO::OnIOSignalled, operation)); | 84 FROM_HERE, base::Bind(&BackgroundIO::OnIOSignalled, operation)); |
| 84 operation->io_completed()->Signal(); | 85 operation->io_completed()->Signal(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 // Runs on the primary thread. | 88 // Runs on the primary thread. |
| 88 void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) { | 89 void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) { |
| 89 { | 90 { |
| 91 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422516 is fixed. |
| 92 tracked_objects::ScopedProfile tracking_profile( |
| 93 FROM_HERE_WITH_EXPLICIT_FUNCTION("422516 InFlightIO::InvokeCallback")); |
| 94 |
| 90 // http://crbug.com/74623 | 95 // http://crbug.com/74623 |
| 91 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 96 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 92 operation->io_completed()->Wait(); | 97 operation->io_completed()->Wait(); |
| 93 } | 98 } |
| 94 running_ = true; | 99 running_ = true; |
| 95 | 100 |
| 96 if (cancel_task) | 101 if (cancel_task) |
| 97 operation->Cancel(); | 102 operation->Cancel(); |
| 98 | 103 |
| 99 // Make sure that we remove the operation from the list before invoking the | 104 // Make sure that we remove the operation from the list before invoking the |
| 100 // callback (so that a subsequent cancel does not invoke the callback again). | 105 // callback (so that a subsequent cancel does not invoke the callback again). |
| 101 DCHECK(io_list_.find(operation) != io_list_.end()); | 106 DCHECK(io_list_.find(operation) != io_list_.end()); |
| 102 DCHECK(!operation->HasOneRef()); | 107 DCHECK(!operation->HasOneRef()); |
| 103 io_list_.erase(make_scoped_refptr(operation)); | 108 io_list_.erase(make_scoped_refptr(operation)); |
| 104 OnOperationComplete(operation, cancel_task); | 109 OnOperationComplete(operation, cancel_task); |
| 105 } | 110 } |
| 106 | 111 |
| 107 // Runs on the primary thread. | 112 // Runs on the primary thread. |
| 108 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { | 113 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { |
| 109 DCHECK(callback_task_runner_->RunsTasksOnCurrentThread()); | 114 DCHECK(callback_task_runner_->RunsTasksOnCurrentThread()); |
| 110 io_list_.insert(make_scoped_refptr(operation)); | 115 io_list_.insert(make_scoped_refptr(operation)); |
| 111 } | 116 } |
| 112 | 117 |
| 113 } // namespace disk_cache | 118 } // namespace disk_cache |
| OLD | NEW |