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