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 |
| 11 BackgroundIO::BackgroundIO(InFlightIO* controller) |
| 12 : controller_(controller), result_(-1), io_completed_(true, false) { |
| 13 } |
| 14 |
11 // Runs on the primary thread. | 15 // Runs on the primary thread. |
12 void BackgroundIO::OnIOSignalled() { | 16 void BackgroundIO::OnIOSignalled() { |
13 if (controller_) | 17 if (controller_) |
14 controller_->InvokeCallback(this, false); | 18 controller_->InvokeCallback(this, false); |
15 } | 19 } |
16 | 20 |
17 void BackgroundIO::Cancel() { | 21 void BackgroundIO::Cancel() { |
18 DCHECK(controller_); | 22 DCHECK(controller_); |
19 controller_ = NULL; | 23 controller_ = NULL; |
20 } | 24 } |
21 | 25 |
| 26 BackgroundIO::~BackgroundIO() {} |
| 27 |
22 // Runs on the background thread. | 28 // Runs on the background thread. |
23 void BackgroundIO::NotifyController() { | 29 void BackgroundIO::NotifyController() { |
24 controller_->OnIOComplete(this); | 30 controller_->OnIOComplete(this); |
25 } | 31 } |
26 | 32 |
27 // --------------------------------------------------------------------------- | 33 // --------------------------------------------------------------------------- |
28 | 34 |
| 35 InFlightIO::InFlightIO() |
| 36 : callback_thread_(base::MessageLoopProxy::CreateForCurrentThread()), |
| 37 running_(false), single_thread_(false) { |
| 38 } |
| 39 |
| 40 InFlightIO::~InFlightIO() { |
| 41 } |
| 42 |
29 void InFlightIO::WaitForPendingIO() { | 43 void InFlightIO::WaitForPendingIO() { |
30 while (!io_list_.empty()) { | 44 while (!io_list_.empty()) { |
31 // Block the current thread until all pending IO completes. | 45 // Block the current thread until all pending IO completes. |
32 IOList::iterator it = io_list_.begin(); | 46 IOList::iterator it = io_list_.begin(); |
33 InvokeCallback(*it, true); | 47 InvokeCallback(*it, true); |
34 } | 48 } |
35 } | 49 } |
36 | 50 |
37 // Runs on a background thread. | 51 // Runs on a background thread. |
38 void InFlightIO::OnIOComplete(BackgroundIO* operation) { | 52 void InFlightIO::OnIOComplete(BackgroundIO* operation) { |
(...skipping 25 matching lines...) Expand all Loading... |
64 OnOperationComplete(operation, cancel_task); | 78 OnOperationComplete(operation, cancel_task); |
65 } | 79 } |
66 | 80 |
67 // Runs on the primary thread. | 81 // Runs on the primary thread. |
68 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { | 82 void InFlightIO::OnOperationPosted(BackgroundIO* operation) { |
69 DCHECK(callback_thread_->BelongsToCurrentThread()); | 83 DCHECK(callback_thread_->BelongsToCurrentThread()); |
70 io_list_.insert(operation); | 84 io_list_.insert(operation); |
71 } | 85 } |
72 | 86 |
73 } // namespace disk_cache | 87 } // namespace disk_cache |
OLD | NEW |