OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BACKEND_IO_H_ | 5 #ifndef NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ |
6 #define NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ | 6 #define NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/disk_cache/in_flight_io.h" | 16 #include "net/disk_cache/in_flight_io.h" |
17 | 17 |
18 namespace disk_cache { | 18 namespace disk_cache { |
19 | 19 |
20 class BackendImpl; | 20 class BackendImpl; |
21 class Entry; | 21 class Entry; |
22 class EntryImpl; | 22 class EntryImpl; |
23 | 23 |
24 // This class represents a single asynchronous disk cache IO operation while it | 24 // This class represents a single asynchronous disk cache IO operation while it |
25 // is being bounced between threads. | 25 // is being bounced between threads. |
26 class BackendIO : public BackgroundIO { | 26 class BackendIO : public BackgroundIO { |
27 public: | 27 public: |
28 BackendIO(InFlightIO* controller, BackendImpl* backend, | 28 BackendIO(InFlightIO* controller, BackendImpl* backend, |
29 net::OldCompletionCallback* callback); | 29 net::OldCompletionCallback* callback); |
| 30 BackendIO(InFlightIO* controller, BackendImpl* backend, |
| 31 const net::CompletionCallback& callback); |
30 | 32 |
31 // Runs the actual operation on the background thread. | 33 // Runs the actual operation on the background thread. |
32 void ExecuteOperation(); | 34 void ExecuteOperation(); |
33 | 35 |
34 // Callback implementation. | 36 // Callback implementation. |
35 void OnIOComplete(int result); | 37 void OnIOComplete(int result); |
36 | 38 |
37 // Returns true if this operation is directed to an entry (vs. the backend). | 39 // Returns true if this operation is directed to an entry (vs. the backend). |
38 bool IsEntryOperation(); | 40 bool IsEntryOperation(); |
39 | 41 |
40 net::OldCompletionCallback* callback() { return callback_; } | 42 net::OldCompletionCallback* old_callback() const { return old_callback_; } |
| 43 net::CompletionCallback callback() const { return callback_; } |
41 | 44 |
42 // Grabs an extra reference of entry_. | 45 // Grabs an extra reference of entry_. |
43 void ReferenceEntry(); | 46 void ReferenceEntry(); |
44 | 47 |
45 // Returns the time that has passed since the operation was created. | 48 // Returns the time that has passed since the operation was created. |
46 base::TimeDelta ElapsedTime() const; | 49 base::TimeDelta ElapsedTime() const; |
47 | 50 |
48 // The operations we proxy: | 51 // The operations we proxy: |
49 void Init(); | 52 void Init(); |
50 void OpenEntry(const std::string& key, Entry** entry); | 53 void OpenEntry(const std::string& key, Entry** entry); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 OP_CANCEL_IO, | 109 OP_CANCEL_IO, |
107 OP_IS_READY | 110 OP_IS_READY |
108 }; | 111 }; |
109 | 112 |
110 virtual ~BackendIO(); | 113 virtual ~BackendIO(); |
111 | 114 |
112 void ExecuteBackendOperation(); | 115 void ExecuteBackendOperation(); |
113 void ExecuteEntryOperation(); | 116 void ExecuteEntryOperation(); |
114 | 117 |
115 BackendImpl* backend_; | 118 BackendImpl* backend_; |
116 net::OldCompletionCallback* callback_; | 119 net::OldCompletionCallback* old_callback_; |
| 120 net::CompletionCallback callback_; |
117 Operation operation_; | 121 Operation operation_; |
118 net::OldCompletionCallbackImpl<BackendIO> my_callback_; | 122 net::OldCompletionCallbackImpl<BackendIO> my_callback_; |
119 | 123 |
120 // The arguments of all the operations we proxy: | 124 // The arguments of all the operations we proxy: |
121 std::string key_; | 125 std::string key_; |
122 Entry** entry_ptr_; | 126 Entry** entry_ptr_; |
123 base::Time initial_time_; | 127 base::Time initial_time_; |
124 base::Time end_time_; | 128 base::Time end_time_; |
125 void** iter_ptr_; | 129 void** iter_ptr_; |
126 void* iter_; | 130 void* iter_; |
(...skipping 15 matching lines...) Expand all Loading... |
142 class InFlightBackendIO : public InFlightIO { | 146 class InFlightBackendIO : public InFlightIO { |
143 public: | 147 public: |
144 InFlightBackendIO(BackendImpl* backend, | 148 InFlightBackendIO(BackendImpl* backend, |
145 base::MessageLoopProxy* background_thread); | 149 base::MessageLoopProxy* background_thread); |
146 virtual ~InFlightBackendIO(); | 150 virtual ~InFlightBackendIO(); |
147 | 151 |
148 // The operations we proxy: | 152 // The operations we proxy: |
149 void Init(net::OldCompletionCallback* callback); | 153 void Init(net::OldCompletionCallback* callback); |
150 void OpenEntry(const std::string& key, Entry** entry, | 154 void OpenEntry(const std::string& key, Entry** entry, |
151 net::OldCompletionCallback* callback); | 155 net::OldCompletionCallback* callback); |
| 156 void OpenEntry(const std::string& key, Entry** entry, |
| 157 const net::CompletionCallback& callback); |
152 void CreateEntry(const std::string& key, Entry** entry, | 158 void CreateEntry(const std::string& key, Entry** entry, |
153 net::OldCompletionCallback* callback); | 159 net::OldCompletionCallback* callback); |
| 160 void CreateEntry(const std::string& key, Entry** entry, |
| 161 const net::CompletionCallback& callback); |
154 void DoomEntry(const std::string& key, net::OldCompletionCallback* callback); | 162 void DoomEntry(const std::string& key, net::OldCompletionCallback* callback); |
155 void DoomAllEntries(net::OldCompletionCallback* callback); | 163 void DoomAllEntries(net::OldCompletionCallback* callback); |
156 void DoomEntriesBetween(const base::Time initial_time, | 164 void DoomEntriesBetween(const base::Time initial_time, |
157 const base::Time end_time, | 165 const base::Time end_time, |
158 net::OldCompletionCallback* callback); | 166 net::OldCompletionCallback* callback); |
159 void DoomEntriesSince(const base::Time initial_time, | 167 void DoomEntriesSince(const base::Time initial_time, |
160 net::OldCompletionCallback* callback); | 168 net::OldCompletionCallback* callback); |
161 void OpenNextEntry(void** iter, Entry** next_entry, | 169 void OpenNextEntry(void** iter, Entry** next_entry, |
162 net::OldCompletionCallback* callback); | 170 net::OldCompletionCallback* callback); |
163 void OpenPrevEntry(void** iter, Entry** prev_entry, | 171 void OpenPrevEntry(void** iter, Entry** prev_entry, |
164 net::OldCompletionCallback* callback); | 172 net::OldCompletionCallback* callback); |
165 void EndEnumeration(void* iterator); | 173 void EndEnumeration(void* iterator); |
166 void OnExternalCacheHit(const std::string& key); | 174 void OnExternalCacheHit(const std::string& key); |
167 void CloseEntryImpl(EntryImpl* entry); | 175 void CloseEntryImpl(EntryImpl* entry); |
168 void DoomEntryImpl(EntryImpl* entry); | 176 void DoomEntryImpl(EntryImpl* entry); |
169 void FlushQueue(net::OldCompletionCallback* callback); | 177 void FlushQueue(net::OldCompletionCallback* callback); |
170 void RunTask(Task* task, net::OldCompletionCallback* callback); | 178 void RunTask(Task* task, net::OldCompletionCallback* callback); |
171 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 179 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, |
172 int buf_len, net::OldCompletionCallback* callback); | 180 int buf_len, net::OldCompletionCallback* callback); |
173 void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 181 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, |
174 int buf_len, bool truncate, net::OldCompletionCallback* callbac
k); | 182 int buf_len, const net::CompletionCallback& callback); |
| 183 void WriteData(EntryImpl* entry, int index, int offset, |
| 184 net::IOBuffer* buf, int buf_len, bool truncate, |
| 185 net::OldCompletionCallback* callback); |
| 186 void WriteData(EntryImpl* entry, int index, int offset, |
| 187 net::IOBuffer* buf, int buf_len, bool truncate, |
| 188 const net::CompletionCallback& callback); |
175 void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 189 void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, |
176 int buf_len, net::OldCompletionCallback* callback); | 190 int buf_len, net::OldCompletionCallback* callback); |
177 void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 191 void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, |
178 int buf_len, net::OldCompletionCallback* callback); | 192 int buf_len, net::OldCompletionCallback* callback); |
179 void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start, | 193 void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start, |
180 net::OldCompletionCallback* callback); | 194 net::OldCompletionCallback* callback); |
181 void CancelSparseIO(EntryImpl* entry); | 195 void CancelSparseIO(EntryImpl* entry); |
182 void ReadyForSparseIO(EntryImpl* entry, net::OldCompletionCallback* callback); | 196 void ReadyForSparseIO(EntryImpl* entry, net::OldCompletionCallback* callback); |
183 | 197 |
184 // Blocks until all operations are cancelled or completed. | 198 // Blocks until all operations are cancelled or completed. |
(...skipping 17 matching lines...) Expand all Loading... |
202 | 216 |
203 BackendImpl* backend_; | 217 BackendImpl* backend_; |
204 scoped_refptr<base::MessageLoopProxy> background_thread_; | 218 scoped_refptr<base::MessageLoopProxy> background_thread_; |
205 | 219 |
206 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); | 220 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); |
207 }; | 221 }; |
208 | 222 |
209 } // namespace disk_cache | 223 } // namespace disk_cache |
210 | 224 |
211 #endif // NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ | 225 #endif // NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ |
OLD | NEW |