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 #ifndef NET_DISK_CACHE_IN_FLIGHT_IO_H_ | 5 #ifndef NET_DISK_CACHE_IN_FLIGHT_IO_H_ |
6 #define NET_DISK_CACHE_IN_FLIGHT_IO_H_ | 6 #define NET_DISK_CACHE_IN_FLIGHT_IO_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/waitable_event.h" | 11 #include "base/waitable_event.h" |
12 | 12 |
13 namespace disk_cache { | 13 namespace disk_cache { |
14 | 14 |
15 class InFlightIO; | 15 class InFlightIO; |
16 | 16 |
17 // This class represents a single asynchronous IO operation while it is being | 17 // This class represents a single asynchronous IO operation while it is being |
18 // bounced between threads. | 18 // bounced between threads. |
19 class BackgroundIO : public base::RefCountedThreadSafe<BackgroundIO> { | 19 class BackgroundIO : public base::RefCountedThreadSafe<BackgroundIO> { |
20 public: | 20 public: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // 8. BackgroundIO::OnIOSignalled() | 82 // 8. BackgroundIO::OnIOSignalled() |
83 // 9. InFlightIO::InvokeCallback() | 83 // 9. InFlightIO::InvokeCallback() |
84 // 10. DerivedInFlightIO::OnOperationComplete() | 84 // 10. DerivedInFlightIO::OnOperationComplete() |
85 // 11. invoke callback | 85 // 11. invoke callback |
86 // | 86 // |
87 // Shutdown is a special case that is handled though WaitForPendingIO() instead | 87 // Shutdown is a special case that is handled though WaitForPendingIO() instead |
88 // of just waiting for step 7. | 88 // of just waiting for step 7. |
89 class InFlightIO { | 89 class InFlightIO { |
90 public: | 90 public: |
91 InFlightIO() | 91 InFlightIO() |
92 : callback_thread_(MessageLoop::current()), running_(false), | 92 : callback_thread_(base::MessageLoopProxy::CreateForCurrentThread()), |
93 single_thread_(false) {} | 93 running_(false), single_thread_(false) {} |
94 virtual ~InFlightIO() {} | 94 virtual ~InFlightIO() {} |
95 | 95 |
96 // Blocks the current thread until all IO operations tracked by this object | 96 // Blocks the current thread until all IO operations tracked by this object |
97 // complete. | 97 // complete. |
98 void WaitForPendingIO(); | 98 void WaitForPendingIO(); |
99 | 99 |
100 // Called on a background thread when |operation| completes. | 100 // Called on a background thread when |operation| completes. |
101 void OnIOComplete(BackgroundIO* operation); | 101 void OnIOComplete(BackgroundIO* operation); |
102 | 102 |
103 // Invokes the users' completion callback at the end of the IO operation. | 103 // Invokes the users' completion callback at the end of the IO operation. |
(...skipping 10 matching lines...) Expand all Loading... |
114 | 114 |
115 // Signals this object that the derived class just posted the |operation| to | 115 // Signals this object that the derived class just posted the |operation| to |
116 // be executed on a background thread. This method must be called on the same | 116 // be executed on a background thread. This method must be called on the same |
117 // thread used to create this object. | 117 // thread used to create this object. |
118 void OnOperationPosted(BackgroundIO* operation); | 118 void OnOperationPosted(BackgroundIO* operation); |
119 | 119 |
120 private: | 120 private: |
121 typedef std::set<scoped_refptr<BackgroundIO> > IOList; | 121 typedef std::set<scoped_refptr<BackgroundIO> > IOList; |
122 | 122 |
123 IOList io_list_; // List of pending, in-flight io operations. | 123 IOList io_list_; // List of pending, in-flight io operations. |
124 MessageLoop* callback_thread_; | 124 scoped_refptr<base::MessageLoopProxy> callback_thread_; |
125 | 125 |
126 bool running_; // True after the first posted operation completes. | 126 bool running_; // True after the first posted operation completes. |
127 bool single_thread_; // True if we only have one thread. | 127 bool single_thread_; // True if we only have one thread. |
128 | 128 |
129 DISALLOW_COPY_AND_ASSIGN(InFlightIO); | 129 DISALLOW_COPY_AND_ASSIGN(InFlightIO); |
130 }; | 130 }; |
131 | 131 |
132 } // namespace disk_cache | 132 } // namespace disk_cache |
133 | 133 |
134 #endif // NET_DISK_CACHE_IN_FLIGHT_IO_H_ | 134 #endif // NET_DISK_CACHE_IN_FLIGHT_IO_H_ |
OLD | NEW |