OLD | NEW |
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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 void DoomOperationComplete(const CompletionCallback& callback, | 284 void DoomOperationComplete(const CompletionCallback& callback, |
285 State state_to_restore, | 285 State state_to_restore, |
286 int result); | 286 int result); |
287 | 287 |
288 // Reports reads result potentially refining status based on |crc_result|. | 288 // Reports reads result potentially refining status based on |crc_result|. |
289 // |crc_result| is permitted to be null. | 289 // |crc_result| is permitted to be null. |
290 void RecordReadResultConsideringChecksum( | 290 void RecordReadResultConsideringChecksum( |
291 int result, | 291 int result, |
292 std::unique_ptr<SimpleSynchronousEntry::CRCRequest> crc_result) const; | 292 std::unique_ptr<SimpleSynchronousEntry::CRCRequest> crc_result) const; |
293 | 293 |
294 // Called after completion of asynchronous IO and receiving file metadata for | 294 // Called after completion of an operation, to either incoproprate file info |
295 // the entry in |entry_stat|. Updates the metadata in the entry and in the | 295 // received from I/O done on the worker pool, or to simply bump the |
296 // index to make them available on next IO operations. | 296 // timestamps. Updates the metadata both in |this| and in the index. |
| 297 // Stream size information in particular may be important for following |
| 298 // operations. |
297 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); | 299 void UpdateDataFromEntryStat(const SimpleEntryStat& entry_stat); |
298 | 300 |
299 int64_t GetDiskUsage() const; | 301 int64_t GetDiskUsage() const; |
300 | 302 |
301 // Used to report histograms. | 303 // Used to report histograms. |
302 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; | 304 void RecordReadIsParallelizable(const SimpleEntryOperation& operation) const; |
303 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; | 305 void RecordWriteDependencyType(const SimpleEntryOperation& operation) const; |
304 | 306 |
305 // Reads from the stream 0 data kept in memory. | 307 // Completes a read from the stream data kept in memory, logging metrics |
306 int ReadStream0Data(net::IOBuffer* buf, int offset, int buf_len); | 308 // and updating metadata. If |callback| is non-null, it will be posted to the |
| 309 // current task runner with the return code. |
| 310 void ReadFromBufferAndPostReply(net::GrowableIOBuffer* in_buf, |
| 311 int offset, |
| 312 int buf_len, |
| 313 net::IOBuffer* out_buf, |
| 314 const CompletionCallback& callback); |
307 | 315 |
308 // Copies data from |buf| to the internal in-memory buffer for stream 0. If | 316 // Copies data from |buf| to the internal in-memory buffer for stream 0. If |
309 // |truncate| is set to true, the target buffer will be truncated at |offset| | 317 // |truncate| is set to true, the target buffer will be truncated at |offset| |
310 // + |buf_len| before being written. | 318 // + |buf_len| before being written. |
311 int SetStream0Data(net::IOBuffer* buf, | 319 int SetStream0Data(net::IOBuffer* buf, |
312 int offset, int buf_len, | 320 int offset, int buf_len, |
313 bool truncate); | 321 bool truncate); |
314 | 322 |
315 // Updates |crc32s_| and |crc32s_end_offset_| for a write of the data in | 323 // Updates |crc32s_| and |crc32s_end_offset_| for a write of the data in |
316 // |buffer| on |stream_index|, starting at |offset| and of length |length|. | 324 // |buffer| on |stream_index|, starting at |offset| and of length |length|. |
(...skipping 10 matching lines...) Expand all Loading... |
327 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 335 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
328 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 336 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
329 base::ThreadChecker io_thread_checker_; | 337 base::ThreadChecker io_thread_checker_; |
330 | 338 |
331 const base::WeakPtr<SimpleBackendImpl> backend_; | 339 const base::WeakPtr<SimpleBackendImpl> backend_; |
332 const net::CacheType cache_type_; | 340 const net::CacheType cache_type_; |
333 const scoped_refptr<base::TaskRunner> worker_pool_; | 341 const scoped_refptr<base::TaskRunner> worker_pool_; |
334 const base::FilePath path_; | 342 const base::FilePath path_; |
335 const uint64_t entry_hash_; | 343 const uint64_t entry_hash_; |
336 const bool use_optimistic_operations_; | 344 const bool use_optimistic_operations_; |
| 345 bool is_initial_stream1_read_; // used for metrics only. |
337 std::string key_; | 346 std::string key_; |
338 | 347 |
339 // |last_used_|, |last_modified_| and |data_size_| are copied from the | 348 // |last_used_|, |last_modified_| and |data_size_| are copied from the |
340 // synchronous entry at the completion of each item of asynchronous IO. | 349 // synchronous entry at the completion of each item of asynchronous IO. |
341 // TODO(clamy): Unify last_used_ with data in the index. | 350 // TODO(clamy): Unify last_used_ with data in the index. |
342 base::Time last_used_; | 351 base::Time last_used_; |
343 base::Time last_modified_; | 352 base::Time last_modified_; |
344 int32_t data_size_[kSimpleEntryStreamCount]; | 353 int32_t data_size_[kSimpleEntryStreamCount]; |
345 int32_t sparse_data_size_; | 354 int32_t sparse_data_size_; |
346 | 355 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Unlike other streams, stream 0 data is read from the disk when the entry is | 398 // Unlike other streams, stream 0 data is read from the disk when the entry is |
390 // opened, and then kept in memory. All read/write operations on stream 0 | 399 // opened, and then kept in memory. All read/write operations on stream 0 |
391 // affect the |stream_0_data_| buffer. When the entry is closed, | 400 // affect the |stream_0_data_| buffer. When the entry is closed, |
392 // |stream_0_data_| is written to the disk. | 401 // |stream_0_data_| is written to the disk. |
393 // Stream 0 is kept in memory because it is stored in the same file as stream | 402 // Stream 0 is kept in memory because it is stored in the same file as stream |
394 // 1 on disk, to reduce the number of file descriptors and save disk space. | 403 // 1 on disk, to reduce the number of file descriptors and save disk space. |
395 // This strategy allows stream 1 to change size easily. Since stream 0 is only | 404 // This strategy allows stream 1 to change size easily. Since stream 0 is only |
396 // used to write HTTP headers, the memory consumption of keeping it in memory | 405 // used to write HTTP headers, the memory consumption of keeping it in memory |
397 // is acceptable. | 406 // is acceptable. |
398 scoped_refptr<net::GrowableIOBuffer> stream_0_data_; | 407 scoped_refptr<net::GrowableIOBuffer> stream_0_data_; |
| 408 |
| 409 // Sometimes stream 1 data is prefetched when stream 0 is first read. |
| 410 // If a write to the stream occurs on the entry the prefetch buffer is |
| 411 // discarded. It may also be null if it wasn't prefetched in the first place. |
| 412 scoped_refptr<net::GrowableIOBuffer> stream_1_prefetch_data_; |
399 }; | 413 }; |
400 | 414 |
401 } // namespace disk_cache | 415 } // namespace disk_cache |
402 | 416 |
403 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ | 417 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ |
OLD | NEW |