OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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_io.h" | 5 #include "net/disk_cache/in_flight_io.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace disk_cache { | 9 namespace disk_cache { |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 while (!io_list_.empty()) { | 30 while (!io_list_.empty()) { |
31 // Block the current thread until all pending IO completes. | 31 // Block the current thread until all pending IO completes. |
32 IOList::iterator it = io_list_.begin(); | 32 IOList::iterator it = io_list_.begin(); |
33 InvokeCallback(*it, true); | 33 InvokeCallback(*it, true); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 // Runs on a background thread. | 37 // Runs on a background thread. |
38 void InFlightIO::OnIOComplete(BackgroundIO* operation) { | 38 void InFlightIO::OnIOComplete(BackgroundIO* operation) { |
39 #ifndef NDEBUG | 39 #ifndef NDEBUG |
40 if (callback_thread_ == MessageLoop::current()) { | 40 if (callback_thread_->BelongsToCurrentThread()) { |
41 DCHECK(single_thread_ || !running_); | 41 DCHECK(single_thread_ || !running_); |
42 single_thread_ = true; | 42 single_thread_ = true; |
43 } | 43 } |
44 running_ = true; | 44 running_ = true; |
45 #endif | 45 #endif |
46 | 46 |
47 callback_thread_->PostTask(FROM_HERE, | 47 callback_thread_->PostTask(FROM_HERE, |
48 NewRunnableMethod(operation, | 48 NewRunnableMethod(operation, |
49 &BackgroundIO::OnIOSignalled)); | 49 &BackgroundIO::OnIOSignalled)); |
50 operation->io_completed()->Signal(); | 50 operation->io_completed()->Signal(); |
51 } | 51 } |
52 | 52 |
53 // Runs on the primary thread. | 53 // Runs on the primary thread. |
54 void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) { | 54 void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) { |
55 operation->io_completed()->Wait(); | 55 operation->io_completed()->Wait(); |
56 | 56 |
57 if (cancel_task) | 57 if (cancel_task) |
58 operation->Cancel(); | 58 operation->Cancel(); |
59 | 59 |
60 // Make sure that we remove the operation from the list before invoking the | 60 // Make sure that we remove the operation from the list before invoking the |
61 // callback (so that a subsequent cancel does not invoke the callback again). | 61 // callback (so that a subsequent cancel does not invoke the callback again). |
62 DCHECK(io_list_.find(operation) != io_list_.end()); | 62 DCHECK(io_list_.find(operation) != io_list_.end()); |
63 io_list_.erase(operation); | 63 io_list_.erase(operation); |
64 OnOperationComplete(operation, cancel_task); | 64 OnOperationComplete(operation, cancel_task); |
65 } | 65 } |
66 | 66 |
67 // Runs on the primary thread. | 67 // Runs on the primary thread. |
68 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { | 68 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { |
69 DCHECK(callback_thread_ == MessageLoop::current()); | 69 DCHECK(callback_thread_->BelongsToCurrentThread()); |
70 io_list_.insert(operation); | 70 io_list_.insert(operation); |
71 } | 71 } |
72 | 72 |
73 } // namespace disk_cache | 73 } // namespace disk_cache |
OLD | NEW |