Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: net/disk_cache/simple/simple_entry_impl.h

Issue 23983005: SimpleCache: merge the first and second stream in one file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched to GrowableIOBuffer Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "net/base/cache_type.h" 16 #include "net/base/cache_type.h"
17 #include "net/base/net_log.h" 17 #include "net/base/net_log.h"
18 #include "net/disk_cache/disk_cache.h" 18 #include "net/disk_cache/disk_cache.h"
19 #include "net/disk_cache/simple/simple_entry_format.h" 19 #include "net/disk_cache/simple/simple_entry_format.h"
20 #include "net/disk_cache/simple/simple_entry_operation.h" 20 #include "net/disk_cache/simple/simple_entry_operation.h"
21 21
22 namespace base { 22 namespace base {
23 class TaskRunner; 23 class TaskRunner;
24 } 24 }
25 25
26 namespace net { 26 namespace net {
27 class GrowableIOBuffer;
27 class IOBuffer; 28 class IOBuffer;
28 } 29 }
29 30
30 namespace disk_cache { 31 namespace disk_cache {
31 32
32 class SimpleBackendImpl; 33 class SimpleBackendImpl;
33 class SimpleSynchronousEntry; 34 class SimpleSynchronousEntry;
34 struct SimpleEntryStat; 35 struct SimpleEntryStat;
35 struct SimpleEntryCreationResults; 36 struct SimpleEntryCreationResults;
36 37
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 void EntryOperationComplete(int stream_index, 203 void EntryOperationComplete(int stream_index,
203 const CompletionCallback& completion_callback, 204 const CompletionCallback& completion_callback,
204 const SimpleEntryStat& entry_stat, 205 const SimpleEntryStat& entry_stat,
205 scoped_ptr<int> result); 206 scoped_ptr<int> result);
206 207
207 // Called after an asynchronous read. Updates |crc32s_| if possible. 208 // Called after an asynchronous read. Updates |crc32s_| if possible.
208 void ReadOperationComplete(int stream_index, 209 void ReadOperationComplete(int stream_index,
209 int offset, 210 int offset,
210 const CompletionCallback& completion_callback, 211 const CompletionCallback& completion_callback,
211 scoped_ptr<uint32> read_crc32, 212 scoped_ptr<uint32> read_crc32,
212 scoped_ptr<base::Time> last_used, 213 scoped_ptr<SimpleEntryStat> entry_stat,
213 scoped_ptr<int> result); 214 scoped_ptr<int> result);
214 215
215 // Called after an asynchronous write completes. 216 // Called after an asynchronous write completes.
216 void WriteOperationComplete(int stream_index, 217 void WriteOperationComplete(int stream_index,
217 const CompletionCallback& completion_callback, 218 const CompletionCallback& completion_callback,
218 scoped_ptr<SimpleEntryStat> entry_stat, 219 scoped_ptr<SimpleEntryStat> entry_stat,
219 scoped_ptr<int> result); 220 scoped_ptr<int> result);
220 221
221 // Called after an asynchronous doom completes. 222 // Called after an asynchronous doom completes.
222 void DoomOperationComplete(const CompletionCallback& callback, 223 void DoomOperationComplete(const CompletionCallback& callback,
(...skipping 13 matching lines...) Expand all
236 // the entry in |entry_stat|. Updates the metadata in the entry and in the 237 // the entry in |entry_stat|. Updates the metadata in the entry and in the
237 // index to make them available on next IO operations. 238 // index to make them available on next IO operations.
238 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); 239 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat);
239 240
240 int64 GetDiskUsage() const; 241 int64 GetDiskUsage() const;
241 242
242 // Used to report histograms. 243 // Used to report histograms.
243 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; 244 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const;
244 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; 245 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const;
245 246
247 // Reads from the stream 0 data kept in memory.
248 int ReadStream0Data(net::IOBuffer* buf, int offset, int buf_len);
249
250 // Copies stream 0 data to the buffer kept in memory.
251 int CopyStream0Data(net::IOBuffer* buf,
252 int offset, int buf_len,
253 bool truncate);
254
246 // All nonstatic SimpleEntryImpl methods should always be called on the IO 255 // All nonstatic SimpleEntryImpl methods should always be called on the IO
247 // thread, in all cases. |io_thread_checker_| documents and enforces this. 256 // thread, in all cases. |io_thread_checker_| documents and enforces this.
248 base::ThreadChecker io_thread_checker_; 257 base::ThreadChecker io_thread_checker_;
249 258
250 base::WeakPtr<SimpleBackendImpl> backend_; 259 base::WeakPtr<SimpleBackendImpl> backend_;
251 const net::CacheType cache_type_; 260 const net::CacheType cache_type_;
252 const scoped_refptr<base::TaskRunner> worker_pool_; 261 const scoped_refptr<base::TaskRunner> worker_pool_;
253 const base::FilePath path_; 262 const base::FilePath path_;
254 const uint64 entry_hash_; 263 const uint64 entry_hash_;
255 const bool use_optimistic_operations_; 264 const bool use_optimistic_operations_;
256 std::string key_; 265 std::string key_;
257 266
258 // |last_used_|, |last_modified_| and |data_size_| are copied from the 267 // |last_used_|, |last_modified_| and |data_size_| are copied from the
259 // synchronous entry at the completion of each item of asynchronous IO. 268 // synchronous entry at the completion of each item of asynchronous IO.
260 // TODO(clamy): Unify last_used_ with data in the index. 269 // TODO(clamy): Unify last_used_ with data in the index.
261 base::Time last_used_; 270 base::Time last_used_;
262 base::Time last_modified_; 271 base::Time last_modified_;
263 int32 data_size_[kSimpleEntryFileCount]; 272 int32 data_size_[kSimpleEntryStreamCount];
264 273
265 // Number of times this object has been returned from Backend::OpenEntry() and 274 // Number of times this object has been returned from Backend::OpenEntry() and
266 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to 275 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to
267 // notify the backend when this entry not used by any callers. 276 // notify the backend when this entry not used by any callers.
268 int open_count_; 277 int open_count_;
269 278
270 State state_; 279 State state_;
271 280
272 // When possible, we compute a crc32, for the data in each entry as we read or 281 // When possible, we compute a crc32, for the data in each entry as we read or
273 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from 282 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from
274 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the 283 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the
275 // value of |crc32s_[index]| is undefined. 284 // value of |crc32s_[index]| is undefined.
276 int32 crc32s_end_offset_[kSimpleEntryFileCount]; 285 int32 crc32s_end_offset_[kSimpleEntryStreamCount];
277 uint32 crc32s_[kSimpleEntryFileCount]; 286 uint32 crc32s_[kSimpleEntryStreamCount];
278 287
279 // If |have_written_[index]| is true, we have written to the stream |index|. 288 // If |have_written_[index]| is true, we have written to the stream |index|.
280 bool have_written_[kSimpleEntryFileCount]; 289 bool have_written_[kSimpleEntryStreamCount];
281 290
282 // Reflects how much CRC checking has been done with the entry. This state is 291 // Reflects how much CRC checking has been done with the entry. This state is
283 // reported on closing each entry stream. 292 // reported on closing each entry stream.
284 CheckCrcResult crc_check_state_[kSimpleEntryFileCount]; 293 CheckCrcResult crc_check_state_[kSimpleEntryStreamCount];
285 294
286 // The |synchronous_entry_| is the worker thread object that performs IO on 295 // The |synchronous_entry_| is the worker thread object that performs IO on
287 // entries. It's owned by this SimpleEntryImpl whenever |executing_operation_| 296 // entries. It's owned by this SimpleEntryImpl whenever |executing_operation_|
288 // is false (i.e. when an operation is not pending on the worker pool). When 297 // is false (i.e. when an operation is not pending on the worker pool). When
289 // an operation is being executed no one owns the synchronous entry. Therefore 298 // an operation is being executed no one owns the synchronous entry. Therefore
290 // SimpleEntryImpl should not be deleted while an operation is running as that 299 // SimpleEntryImpl should not be deleted while an operation is running as that
291 // would leak the SimpleSynchronousEntry. 300 // would leak the SimpleSynchronousEntry.
292 SimpleSynchronousEntry* synchronous_entry_; 301 SimpleSynchronousEntry* synchronous_entry_;
293 302
294 std::queue<SimpleEntryOperation> pending_operations_; 303 std::queue<SimpleEntryOperation> pending_operations_;
295 304
296 net::BoundNetLog net_log_; 305 net::BoundNetLog net_log_;
297 306
298 scoped_ptr<SimpleEntryOperation> executing_operation_; 307 scoped_ptr<SimpleEntryOperation> executing_operation_;
308
309 // Unlike other streams, stream 0 data is read from the disk when the entry is
310 // opened, and then kept in memory. All read/write operations on stream 0
311 // affect the |stream_0_data_| buffer. When the entry is closed,
312 // |stream_0_data_| is written to the disk.
313 // Stream 0 is kept in memory because it is stored in the same file than
314 // stream 1 on disk (to save diskspace). This strategy allows stream 1 to
gavinp 2013/09/10 22:20:49 Stream 1 probably never needs to change size, thou
clamy 2013/09/11 12:46:21 Probably not, but the unit tests test it.
315 // change size easily. Since stream 0 is only used to write HTTP headers, the
316 // memory consumption of keeping it in memory is acceptable.
317 scoped_refptr<net::GrowableIOBuffer> stream_0_data_;
299 }; 318 };
300 319
301 } // namespace disk_cache 320 } // namespace disk_cache
302 321
303 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 322 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698