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 <stdint.h> |
| 9 |
8 #include <list> | 10 #include <list> |
9 #include <string> | 11 #include <string> |
10 | 12 |
| 13 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
12 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
13 #include "base/time/time.h" | 16 #include "base/time/time.h" |
14 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
15 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
16 #include "net/disk_cache/blockfile/in_flight_io.h" | 19 #include "net/disk_cache/blockfile/in_flight_io.h" |
17 #include "net/disk_cache/blockfile/rankings.h" | 20 #include "net/disk_cache/blockfile/rankings.h" |
18 | 21 |
19 namespace disk_cache { | 22 namespace disk_cache { |
20 | 23 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 void EndEnumeration(scoped_ptr<Rankings::Iterator> iterator); | 64 void EndEnumeration(scoped_ptr<Rankings::Iterator> iterator); |
62 void OnExternalCacheHit(const std::string& key); | 65 void OnExternalCacheHit(const std::string& key); |
63 void CloseEntryImpl(EntryImpl* entry); | 66 void CloseEntryImpl(EntryImpl* entry); |
64 void DoomEntryImpl(EntryImpl* entry); | 67 void DoomEntryImpl(EntryImpl* entry); |
65 void FlushQueue(); // Dummy operation. | 68 void FlushQueue(); // Dummy operation. |
66 void RunTask(const base::Closure& task); | 69 void RunTask(const base::Closure& task); |
67 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 70 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, |
68 int buf_len); | 71 int buf_len); |
69 void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 72 void WriteData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, |
70 int buf_len, bool truncate); | 73 int buf_len, bool truncate); |
71 void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 74 void ReadSparseData(EntryImpl* entry, |
| 75 int64_t offset, |
| 76 net::IOBuffer* buf, |
72 int buf_len); | 77 int buf_len); |
73 void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 78 void WriteSparseData(EntryImpl* entry, |
| 79 int64_t offset, |
| 80 net::IOBuffer* buf, |
74 int buf_len); | 81 int buf_len); |
75 void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start); | 82 void GetAvailableRange(EntryImpl* entry, |
| 83 int64_t offset, |
| 84 int len, |
| 85 int64_t* start); |
76 void CancelSparseIO(EntryImpl* entry); | 86 void CancelSparseIO(EntryImpl* entry); |
77 void ReadyForSparseIO(EntryImpl* entry); | 87 void ReadyForSparseIO(EntryImpl* entry); |
78 | 88 |
79 private: | 89 private: |
80 // 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 |
81 // executed sequentially (queued by the message loop). On the other hand, | 91 // executed sequentially (queued by the message loop). On the other hand, |
82 // 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 |
83 // 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 |
84 // are subject to throttling, so we keep an explicit queue. | 94 // are subject to throttling, so we keep an explicit queue. |
85 enum Operation { | 95 enum Operation { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 base::Time initial_time_; | 140 base::Time initial_time_; |
131 base::Time end_time_; | 141 base::Time end_time_; |
132 Rankings::Iterator* iterator_; | 142 Rankings::Iterator* iterator_; |
133 scoped_ptr<Rankings::Iterator> scoped_iterator_; | 143 scoped_ptr<Rankings::Iterator> scoped_iterator_; |
134 EntryImpl* entry_; | 144 EntryImpl* entry_; |
135 int index_; | 145 int index_; |
136 int offset_; | 146 int offset_; |
137 scoped_refptr<net::IOBuffer> buf_; | 147 scoped_refptr<net::IOBuffer> buf_; |
138 int buf_len_; | 148 int buf_len_; |
139 bool truncate_; | 149 bool truncate_; |
140 int64 offset64_; | 150 int64_t offset64_; |
141 int64* start_; | 151 int64_t* start_; |
142 base::TimeTicks start_time_; | 152 base::TimeTicks start_time_; |
143 base::Closure task_; | 153 base::Closure task_; |
144 | 154 |
145 DISALLOW_COPY_AND_ASSIGN(BackendIO); | 155 DISALLOW_COPY_AND_ASSIGN(BackendIO); |
146 }; | 156 }; |
147 | 157 |
148 // The specialized controller that keeps track of current operations. | 158 // The specialized controller that keeps track of current operations. |
149 class InFlightBackendIO : public InFlightIO { | 159 class InFlightBackendIO : public InFlightIO { |
150 public: | 160 public: |
151 InFlightBackendIO( | 161 InFlightBackendIO( |
(...skipping 23 matching lines...) Expand all Loading... |
175 void CloseEntryImpl(EntryImpl* entry); | 185 void CloseEntryImpl(EntryImpl* entry); |
176 void DoomEntryImpl(EntryImpl* entry); | 186 void DoomEntryImpl(EntryImpl* entry); |
177 void FlushQueue(const net::CompletionCallback& callback); | 187 void FlushQueue(const net::CompletionCallback& callback); |
178 void RunTask(const base::Closure& task, | 188 void RunTask(const base::Closure& task, |
179 const net::CompletionCallback& callback); | 189 const net::CompletionCallback& callback); |
180 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 190 void ReadData(EntryImpl* entry, int index, int offset, net::IOBuffer* buf, |
181 int buf_len, const net::CompletionCallback& callback); | 191 int buf_len, const net::CompletionCallback& callback); |
182 void WriteData( | 192 void WriteData( |
183 EntryImpl* entry, int index, int offset, net::IOBuffer* buf, | 193 EntryImpl* entry, int index, int offset, net::IOBuffer* buf, |
184 int buf_len, bool truncate, const net::CompletionCallback& callback); | 194 int buf_len, bool truncate, const net::CompletionCallback& callback); |
185 void ReadSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 195 void ReadSparseData(EntryImpl* entry, |
186 int buf_len, const net::CompletionCallback& callback); | 196 int64_t offset, |
187 void WriteSparseData(EntryImpl* entry, int64 offset, net::IOBuffer* buf, | 197 net::IOBuffer* buf, |
188 int buf_len, const net::CompletionCallback& callback); | 198 int buf_len, |
189 void GetAvailableRange(EntryImpl* entry, int64 offset, int len, int64* start, | 199 const net::CompletionCallback& callback); |
| 200 void WriteSparseData(EntryImpl* entry, |
| 201 int64_t offset, |
| 202 net::IOBuffer* buf, |
| 203 int buf_len, |
| 204 const net::CompletionCallback& callback); |
| 205 void GetAvailableRange(EntryImpl* entry, |
| 206 int64_t offset, |
| 207 int len, |
| 208 int64_t* start, |
190 const net::CompletionCallback& callback); | 209 const net::CompletionCallback& callback); |
191 void CancelSparseIO(EntryImpl* entry); | 210 void CancelSparseIO(EntryImpl* entry); |
192 void ReadyForSparseIO(EntryImpl* entry, | 211 void ReadyForSparseIO(EntryImpl* entry, |
193 const net::CompletionCallback& callback); | 212 const net::CompletionCallback& callback); |
194 | 213 |
195 // Blocks until all operations are cancelled or completed. | 214 // Blocks until all operations are cancelled or completed. |
196 void WaitForPendingIO(); | 215 void WaitForPendingIO(); |
197 | 216 |
198 scoped_refptr<base::SingleThreadTaskRunner> background_thread() { | 217 scoped_refptr<base::SingleThreadTaskRunner> background_thread() { |
199 return background_thread_; | 218 return background_thread_; |
(...skipping 15 matching lines...) Expand all Loading... |
215 BackendImpl* backend_; | 234 BackendImpl* backend_; |
216 scoped_refptr<base::SingleThreadTaskRunner> background_thread_; | 235 scoped_refptr<base::SingleThreadTaskRunner> background_thread_; |
217 base::WeakPtrFactory<InFlightBackendIO> ptr_factory_; | 236 base::WeakPtrFactory<InFlightBackendIO> ptr_factory_; |
218 | 237 |
219 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); | 238 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); |
220 }; | 239 }; |
221 | 240 |
222 } // namespace disk_cache | 241 } // namespace disk_cache |
223 | 242 |
224 #endif // NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ | 243 #endif // NET_DISK_CACHE_BLOCKFILE_IN_FLIGHT_BACKEND_IO_H_ |
OLD | NEW |