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

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: Stream 0 size in footer 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_export.h" 17 #include "net/base/net_export.h"
18 #include "net/base/net_log.h" 18 #include "net/base/net_log.h"
19 #include "net/disk_cache/disk_cache.h" 19 #include "net/disk_cache/disk_cache.h"
20 #include "net/disk_cache/simple/simple_entry_format.h" 20 #include "net/disk_cache/simple/simple_entry_format.h"
21 #include "net/disk_cache/simple/simple_entry_operation.h" 21 #include "net/disk_cache/simple/simple_entry_operation.h"
22 22
23 namespace base { 23 namespace base {
24 class TaskRunner; 24 class TaskRunner;
25 } 25 }
26 26
27 namespace net { 27 namespace net {
28 class GrowableIOBuffer;
28 class IOBuffer; 29 class IOBuffer;
29 } 30 }
30 31
31 namespace disk_cache { 32 namespace disk_cache {
32 33
33 class SimpleBackendImpl; 34 class SimpleBackendImpl;
34 class SimpleSynchronousEntry; 35 class SimpleSynchronousEntry;
35 struct SimpleEntryStat; 36 struct SimpleEntryStat;
36 struct SimpleEntryCreationResults; 37 struct SimpleEntryCreationResults;
37 38
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 void EntryOperationComplete(int stream_index, 211 void EntryOperationComplete(int stream_index,
211 const CompletionCallback& completion_callback, 212 const CompletionCallback& completion_callback,
212 const SimpleEntryStat& entry_stat, 213 const SimpleEntryStat& entry_stat,
213 scoped_ptr<int> result); 214 scoped_ptr<int> result);
214 215
215 // Called after an asynchronous read. Updates |crc32s_| if possible. 216 // Called after an asynchronous read. Updates |crc32s_| if possible.
216 void ReadOperationComplete(int stream_index, 217 void ReadOperationComplete(int stream_index,
217 int offset, 218 int offset,
218 const CompletionCallback& completion_callback, 219 const CompletionCallback& completion_callback,
219 scoped_ptr<uint32> read_crc32, 220 scoped_ptr<uint32> read_crc32,
220 scoped_ptr<base::Time> last_used, 221 scoped_ptr<SimpleEntryStat> entry_stat,
221 scoped_ptr<int> result); 222 scoped_ptr<int> result);
222 223
223 // Called after an asynchronous write completes. 224 // Called after an asynchronous write completes.
224 void WriteOperationComplete(int stream_index, 225 void WriteOperationComplete(int stream_index,
225 const CompletionCallback& completion_callback, 226 const CompletionCallback& completion_callback,
226 scoped_ptr<SimpleEntryStat> entry_stat, 227 scoped_ptr<SimpleEntryStat> entry_stat,
227 scoped_ptr<int> result); 228 scoped_ptr<int> result);
228 229
229 // Called after an asynchronous doom completes. 230 // Called after an asynchronous doom completes.
230 void DoomOperationComplete(const CompletionCallback& callback, 231 void DoomOperationComplete(const CompletionCallback& callback,
(...skipping 13 matching lines...) Expand all
244 // the entry in |entry_stat|. Updates the metadata in the entry and in the 245 // the entry in |entry_stat|. Updates the metadata in the entry and in the
245 // index to make them available on next IO operations. 246 // index to make them available on next IO operations.
246 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); 247 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat);
247 248
248 int64 GetDiskUsage() const; 249 int64 GetDiskUsage() const;
249 250
250 // Used to report histograms. 251 // Used to report histograms.
251 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; 252 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const;
252 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; 253 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const;
253 254
255 // Reads from the stream 0 data kept in memory.
256 int ReadStream0Data(net::IOBuffer* buf, int offset, int buf_len);
257
258 // Copies stream 0 data to the buffer kept in memory.
259 int CopyStream0Data(net::IOBuffer* buf,
260 int offset, int buf_len,
261 bool truncate);
pasko 2013/09/17 14:17:36 since this function does not change the state of |
clamy 2013/09/18 16:17:14 net::IOBuffer::data() is not const, and used in th
262
254 // All nonstatic SimpleEntryImpl methods should always be called on the IO 263 // All nonstatic SimpleEntryImpl methods should always be called on the IO
255 // thread, in all cases. |io_thread_checker_| documents and enforces this. 264 // thread, in all cases. |io_thread_checker_| documents and enforces this.
256 base::ThreadChecker io_thread_checker_; 265 base::ThreadChecker io_thread_checker_;
257 266
258 const base::WeakPtr<SimpleBackendImpl> backend_; 267 const base::WeakPtr<SimpleBackendImpl> backend_;
259 const net::CacheType cache_type_; 268 const net::CacheType cache_type_;
260 const scoped_refptr<base::TaskRunner> worker_pool_; 269 const scoped_refptr<base::TaskRunner> worker_pool_;
261 const base::FilePath path_; 270 const base::FilePath path_;
262 const uint64 entry_hash_; 271 const uint64 entry_hash_;
263 const bool use_optimistic_operations_; 272 const bool use_optimistic_operations_;
264 std::string key_; 273 std::string key_;
265 274
266 // |last_used_|, |last_modified_| and |data_size_| are copied from the 275 // |last_used_|, |last_modified_| and |data_size_| are copied from the
267 // synchronous entry at the completion of each item of asynchronous IO. 276 // synchronous entry at the completion of each item of asynchronous IO.
268 // TODO(clamy): Unify last_used_ with data in the index. 277 // TODO(clamy): Unify last_used_ with data in the index.
269 base::Time last_used_; 278 base::Time last_used_;
270 base::Time last_modified_; 279 base::Time last_modified_;
271 int32 data_size_[kSimpleEntryFileCount]; 280 int32 data_size_[kSimpleEntryStreamCount];
272 281
273 // Number of times this object has been returned from Backend::OpenEntry() and 282 // Number of times this object has been returned from Backend::OpenEntry() and
274 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to 283 // Backend::CreateEntry() without subsequent Entry::Close() calls. Used to
275 // notify the backend when this entry not used by any callers. 284 // notify the backend when this entry not used by any callers.
276 int open_count_; 285 int open_count_;
277 286
278 bool doomed_; 287 bool doomed_;
279 288
280 State state_; 289 State state_;
281 290
282 // When possible, we compute a crc32, for the data in each entry as we read or 291 // When possible, we compute a crc32, for the data in each entry as we read or
283 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from 292 // write. For each stream, |crc32s_[index]| is the crc32 of that stream from
284 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the 293 // [0 .. |crc32s_end_offset_|). If |crc32s_end_offset_[index] == 0| then the
285 // value of |crc32s_[index]| is undefined. 294 // value of |crc32s_[index]| is undefined.
286 int32 crc32s_end_offset_[kSimpleEntryFileCount]; 295 int32 crc32s_end_offset_[kSimpleEntryStreamCount];
287 uint32 crc32s_[kSimpleEntryFileCount]; 296 uint32 crc32s_[kSimpleEntryStreamCount];
288 297
289 // If |have_written_[index]| is true, we have written to the stream |index|. 298 // If |have_written_[index]| is true, we have written to the stream |index|.
Deprecated (see juliatuttle) 2013/09/16 20:01:52 This comment is no longer strictly true; we set ha
clamy 2013/09/17 13:59:42 Done.
290 bool have_written_[kSimpleEntryFileCount]; 299 bool have_written_[kSimpleEntryStreamCount];
291 300
292 // Reflects how much CRC checking has been done with the entry. This state is 301 // Reflects how much CRC checking has been done with the entry. This state is
293 // reported on closing each entry stream. 302 // reported on closing each entry stream.
294 CheckCrcResult crc_check_state_[kSimpleEntryFileCount]; 303 CheckCrcResult crc_check_state_[kSimpleEntryStreamCount];
295 304
296 // The |synchronous_entry_| is the worker thread object that performs IO on 305 // The |synchronous_entry_| is the worker thread object that performs IO on
297 // entries. It's owned by this SimpleEntryImpl whenever |executing_operation_| 306 // entries. It's owned by this SimpleEntryImpl whenever |executing_operation_|
298 // is false (i.e. when an operation is not pending on the worker pool). When 307 // is false (i.e. when an operation is not pending on the worker pool). When
299 // an operation is being executed no one owns the synchronous entry. Therefore 308 // an operation is being executed no one owns the synchronous entry. Therefore
300 // SimpleEntryImpl should not be deleted while an operation is running as that 309 // SimpleEntryImpl should not be deleted while an operation is running as that
301 // would leak the SimpleSynchronousEntry. 310 // would leak the SimpleSynchronousEntry.
302 SimpleSynchronousEntry* synchronous_entry_; 311 SimpleSynchronousEntry* synchronous_entry_;
303 312
304 std::queue<SimpleEntryOperation> pending_operations_; 313 std::queue<SimpleEntryOperation> pending_operations_;
305 314
306 net::BoundNetLog net_log_; 315 net::BoundNetLog net_log_;
307 316
308 scoped_ptr<SimpleEntryOperation> executing_operation_; 317 scoped_ptr<SimpleEntryOperation> executing_operation_;
318
319 // Unlike other streams, stream 0 data is read from the disk when the entry is
320 // opened, and then kept in memory. All read/write operations on stream 0
321 // affect the |stream_0_data_| buffer. When the entry is closed,
322 // |stream_0_data_| is written to the disk.
323 // Stream 0 is kept in memory because it is stored in the same file than
pasko 2013/09/17 14:17:36 s/than/as/ s/(to save diskspace)// <-- since we a
clamy 2013/09/18 16:17:14 Done.
324 // stream 1 on disk (to save diskspace). This strategy allows stream 1 to
325 // change size easily. Since stream 0 is only used to write HTTP headers, the
326 // memory consumption of keeping it in memory is acceptable.
327 scoped_refptr<net::GrowableIOBuffer> stream_0_data_;
309 }; 328 };
310 329
311 } // namespace disk_cache 330 } // namespace disk_cache
312 331
313 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 332 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698