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 #ifndef NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ | 5 #ifndef NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ |
6 #define NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ | 6 #define NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 #include "net/disk_cache/blockfile/in_flight_io.h" | 15 #include "net/disk_cache/blockfile/in_flight_io.h" |
16 | 16 |
17 namespace disk_cache { | 17 namespace disk_cache { |
18 | 18 |
19 class BackendImpl; | 19 class BackendImpl; |
20 class Entry; | 20 class Entry; |
21 class EntryImpl; | 21 class EntryImpl; |
22 | 22 |
23 // This class represents a single asynchronous disk cache IO operation while it | 23 // This class represents a single asynchronous disk cache IO operation while it |
24 // is being bounced between threads. | 24 // is being bounced between threads. |
25 class BackendIO : public BackgroundIO { | 25 class BackendIO : public BackgroundIO { |
26 public: | 26 public: |
27 BackendIO(InFlightIO* controller, BackendImpl* backend, | 27 BackendIO(InFlightIO* controller, |
| 28 BackendImpl* backend, |
28 const net::CompletionCallback& callback); | 29 const net::CompletionCallback& callback); |
29 | 30 |
30 // Runs the actual operation on the background thread. | 31 // Runs the actual operation on the background thread. |
31 void ExecuteOperation(); | 32 void ExecuteOperation(); |
32 | 33 |
33 // Callback implementation. | 34 // Callback implementation. |
34 void OnIOComplete(int result); | 35 void OnIOComplete(int result); |
35 | 36 |
36 // Called when we are finishing this operation. If |cancel| is true, the user | 37 // Called when we are finishing this operation. If |cancel| is true, the user |
37 // callback will not be invoked. | 38 // callback will not be invoked. |
(...skipping 17 matching lines...) Expand all Loading... |
55 const base::Time end_time); | 56 const base::Time end_time); |
56 void DoomEntriesSince(const base::Time initial_time); | 57 void DoomEntriesSince(const base::Time initial_time); |
57 void OpenNextEntry(void** iter, Entry** next_entry); | 58 void OpenNextEntry(void** iter, Entry** next_entry); |
58 void OpenPrevEntry(void** iter, Entry** prev_entry); | 59 void OpenPrevEntry(void** iter, Entry** prev_entry); |
59 void EndEnumeration(void* iterator); | 60 void EndEnumeration(void* iterator); |
60 void OnExternalCacheHit(const std::string& key); | 61 void OnExternalCacheHit(const std::string& key); |
61 void CloseEntryImpl(EntryImpl* entry); | 62 void CloseEntryImpl(EntryImpl* entry); |
62 void DoomEntryImpl(EntryImpl* entry); | 63 void DoomEntryImpl(EntryImpl* entry); |
63 void FlushQueue(); // Dummy operation. | 64 void FlushQueue(); // Dummy operation. |
64 void RunTask(const base::Closure& task); | 65 void RunTask(const base::Closure& task); |
65 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 66 void ReadData(EntryImpl* entry, |
| 67 int index, |
| 68 int offset, |
| 69 net::IOBuffer* buf, |
66 int buf_len); | 70 int buf_len); |
67 void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 71 void WriteData(EntryImpl* entry, |
68 int buf_len, bool truncate); | 72 int index, |
69 void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 73 int offset, |
| 74 net::IOBuffer* buf, |
| 75 int buf_len, |
| 76 bool truncate); |
| 77 void ReadSparseData(EntryImpl* entry, |
| 78 int64 offset, |
| 79 net::IOBuffer* buf, |
70 int buf_len); | 80 int buf_len); |
71 void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 81 void WriteSparseData(EntryImpl* entry, |
| 82 int64 offset, |
| 83 net::IOBuffer* buf, |
72 int buf_len); | 84 int buf_len); |
73 void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start); | 85 void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start); |
74 void CancelSparseIO(EntryImpl* entry); | 86 void CancelSparseIO(EntryImpl* entry); |
75 void ReadyForSparseIO(EntryImpl* entry); | 87 void ReadyForSparseIO(EntryImpl* entry); |
76 | 88 |
77 private: | 89 private: |
78 // There are two types of operations to proxy: regular backend operations are | 90 // There are two types of operations to proxy: regular backend operations are |
79 // executed sequentially (queued by the message loop). On the other hand, | 91 // executed sequentially (queued by the message loop). On the other hand, |
80 // operations targeted to a given entry can be long lived and support multiple | 92 // operations targeted to a given entry can be long lived and support multiple |
81 // simultaneous users (multiple reads or writes to the same entry), and they | 93 // simultaneous users (multiple reads or writes to the same entry), and they |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 157 |
146 // The specialized controller that keeps track of current operations. | 158 // The specialized controller that keeps track of current operations. |
147 class InFlightBackendIO : public InFlightIO { | 159 class InFlightBackendIO : public InFlightIO { |
148 public: | 160 public: |
149 InFlightBackendIO(BackendImpl* backend, | 161 InFlightBackendIO(BackendImpl* backend, |
150 base::MessageLoopProxy* background_thread); | 162 base::MessageLoopProxy* background_thread); |
151 virtual ~InFlightBackendIO(); | 163 virtual ~InFlightBackendIO(); |
152 | 164 |
153 // Proxied operations. | 165 // Proxied operations. |
154 void Init(const net::CompletionCallback& callback); | 166 void Init(const net::CompletionCallback& callback); |
155 void OpenEntry(const std::string& key, Entry** entry, | 167 void OpenEntry(const std::string& key, |
| 168 Entry** entry, |
156 const net::CompletionCallback& callback); | 169 const net::CompletionCallback& callback); |
157 void CreateEntry(const std::string& key, Entry** entry, | 170 void CreateEntry(const std::string& key, |
| 171 Entry** entry, |
158 const net::CompletionCallback& callback); | 172 const net::CompletionCallback& callback); |
159 void DoomEntry(const std::string& key, | 173 void DoomEntry(const std::string& key, |
160 const net::CompletionCallback& callback); | 174 const net::CompletionCallback& callback); |
161 void DoomAllEntries(const net::CompletionCallback& callback); | 175 void DoomAllEntries(const net::CompletionCallback& callback); |
162 void DoomEntriesBetween(const base::Time initial_time, | 176 void DoomEntriesBetween(const base::Time initial_time, |
163 const base::Time end_time, | 177 const base::Time end_time, |
164 const net::CompletionCallback& callback); | 178 const net::CompletionCallback& callback); |
165 void DoomEntriesSince(const base::Time initial_time, | 179 void DoomEntriesSince(const base::Time initial_time, |
166 const net::CompletionCallback& callback); | 180 const net::CompletionCallback& callback); |
167 void OpenNextEntry(void** iter, Entry** next_entry, | 181 void OpenNextEntry(void** iter, |
| 182 Entry** next_entry, |
168 const net::CompletionCallback& callback); | 183 const net::CompletionCallback& callback); |
169 void OpenPrevEntry(void** iter, Entry** prev_entry, | 184 void OpenPrevEntry(void** iter, |
| 185 Entry** prev_entry, |
170 const net::CompletionCallback& callback); | 186 const net::CompletionCallback& callback); |
171 void EndEnumeration(void* iterator); | 187 void EndEnumeration(void* iterator); |
172 void OnExternalCacheHit(const std::string& key); | 188 void OnExternalCacheHit(const std::string& key); |
173 void CloseEntryImpl(EntryImpl* entry); | 189 void CloseEntryImpl(EntryImpl* entry); |
174 void DoomEntryImpl(EntryImpl* entry); | 190 void DoomEntryImpl(EntryImpl* entry); |
175 void FlushQueue(const net::CompletionCallback& callback); | 191 void FlushQueue(const net::CompletionCallback& callback); |
176 void RunTask(const base::Closure& task, | 192 void RunTask(const base::Closure& task, |
177 const net::CompletionCallback& callback); | 193 const net::CompletionCallback& callback); |
178 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 194 void ReadData(EntryImpl* entry, |
179 int buf_len, const net::CompletionCallback& callback); | 195 int index, |
180 void WriteData( | 196 int offset, |
181 EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 197 net::IOBuffer* buf, |
182 int buf_len, bool truncate, const net::CompletionCallback& callback); | 198 int buf_len, |
183 void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 199 const net::CompletionCallback& callback); |
184 int buf_len, const net::CompletionCallback& callback); | 200 void WriteData(EntryImpl* entry, |
185 void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 201 int index, |
186 int buf_len, const net::CompletionCallback& callback); | 202 int offset, |
187 void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start, | 203 net::IOBuffer* buf, |
| 204 int buf_len, |
| 205 bool truncate, |
| 206 const net::CompletionCallback& callback); |
| 207 void ReadSparseData(EntryImpl* entry, |
| 208 int64 offset, |
| 209 net::IOBuffer* buf, |
| 210 int buf_len, |
| 211 const net::CompletionCallback& callback); |
| 212 void WriteSparseData(EntryImpl* entry, |
| 213 int64 offset, |
| 214 net::IOBuffer* buf, |
| 215 int buf_len, |
| 216 const net::CompletionCallback& callback); |
| 217 void GetAvailableRange(EntryImpl* entry, |
| 218 int64 offset, |
| 219 int len, |
| 220 int64* start, |
188 const net::CompletionCallback& callback); | 221 const net::CompletionCallback& callback); |
189 void CancelSparseIO(EntryImpl* entry); | 222 void CancelSparseIO(EntryImpl* entry); |
190 void ReadyForSparseIO(EntryImpl* entry, | 223 void ReadyForSparseIO(EntryImpl* entry, |
191 const net::CompletionCallback& callback); | 224 const net::CompletionCallback& callback); |
192 | 225 |
193 // Blocks until all operations are cancelled or completed. | 226 // Blocks until all operations are cancelled or completed. |
194 void WaitForPendingIO(); | 227 void WaitForPendingIO(); |
195 | 228 |
196 scoped_refptr<base::MessageLoopProxy> background_thread() { | 229 scoped_refptr<base::MessageLoopProxy> background_thread() { |
197 return background_thread_; | 230 return background_thread_; |
(...skipping 16 matching lines...) Expand all Loading... |
214 BackendImpl* backend_; | 247 BackendImpl* backend_; |
215 scoped_refptr<base::MessageLoopProxy> background_thread_; | 248 scoped_refptr<base::MessageLoopProxy> background_thread_; |
216 base::WeakPtrFactory<InFlightBackendIO> ptr_factory_; | 249 base::WeakPtrFactory<InFlightBackendIO> ptr_factory_; |
217 | 250 |
218 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); | 251 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); |
219 }; | 252 }; |
220 | 253 |
221 } // namespace disk_cache | 254 } // namespace disk_cache |
222 | 255 |
223 #endif // NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ | 256 #endif // NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ |
OLD | NEW |