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