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/in_flight_io.h" | 5 #include "net/disk_cache/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/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 void BackgroundIO::NotifyController() { | 45 void BackgroundIO::NotifyController() { |
46 base::AutoLock lock(controller_lock_); | 46 base::AutoLock lock(controller_lock_); |
47 if (controller_) | 47 if (controller_) |
48 controller_->OnIOComplete(this); | 48 controller_->OnIOComplete(this); |
49 } | 49 } |
50 | 50 |
51 void InFlightIO::WaitForPendingIO() { | 51 void InFlightIO::WaitForPendingIO() { |
52 while (!io_list_.empty()) { | 52 while (!io_list_.empty()) { |
53 // Block the current thread until all pending IO completes. | 53 // Block the current thread until all pending IO completes. |
54 IOList::iterator it = io_list_.begin(); | 54 IOList::iterator it = io_list_.begin(); |
55 InvokeCallback(*it, true); | 55 InvokeCallback(it->get(), true); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void InFlightIO::DropPendingIO() { | 59 void InFlightIO::DropPendingIO() { |
60 while (!io_list_.empty()) { | 60 while (!io_list_.empty()) { |
61 IOList::iterator it = io_list_.begin(); | 61 IOList::iterator it = io_list_.begin(); |
62 BackgroundIO* operation = *it; | 62 BackgroundIO* operation = it->get(); |
63 operation->Cancel(); | 63 operation->Cancel(); |
64 DCHECK(io_list_.find(operation) != io_list_.end()); | 64 DCHECK(io_list_.find(operation) != io_list_.end()); |
65 io_list_.erase(make_scoped_refptr(operation)); | 65 io_list_.erase(make_scoped_refptr(operation)); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 // Runs on a background thread. | 69 // Runs on a background thread. |
70 void InFlightIO::OnIOComplete(BackgroundIO* operation) { | 70 void InFlightIO::OnIOComplete(BackgroundIO* operation) { |
71 #ifndef NDEBUG | 71 #ifndef NDEBUG |
72 if (callback_thread_->BelongsToCurrentThread()) { | 72 if (callback_thread_->BelongsToCurrentThread()) { |
(...skipping 28 matching lines...) Expand all Loading... |
101 OnOperationComplete(operation, cancel_task); | 101 OnOperationComplete(operation, cancel_task); |
102 } | 102 } |
103 | 103 |
104 // Runs on the primary thread. | 104 // Runs on the primary thread. |
105 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { | 105 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { |
106 DCHECK(callback_thread_->BelongsToCurrentThread()); | 106 DCHECK(callback_thread_->BelongsToCurrentThread()); |
107 io_list_.insert(make_scoped_refptr(operation)); | 107 io_list_.insert(make_scoped_refptr(operation)); |
108 } | 108 } |
109 | 109 |
110 } // namespace disk_cache | 110 } // namespace disk_cache |
OLD | NEW |