| 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 #include "net/disk_cache/simple/simple_entry_impl.h" | 5 #include "net/disk_cache/simple/simple_entry_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 last_used_(Time::Now()), | 189 last_used_(Time::Now()), |
| 190 last_modified_(last_used_), | 190 last_modified_(last_used_), |
| 191 sparse_data_size_(0), | 191 sparse_data_size_(0), |
| 192 open_count_(0), | 192 open_count_(0), |
| 193 doomed_(false), | 193 doomed_(false), |
| 194 state_(STATE_UNINITIALIZED), | 194 state_(STATE_UNINITIALIZED), |
| 195 synchronous_entry_(NULL), | 195 synchronous_entry_(NULL), |
| 196 net_log_( | 196 net_log_( |
| 197 net::NetLogWithSource::Make(net_log, | 197 net::NetLogWithSource::Make(net_log, |
| 198 net::NetLogSourceType::DISK_CACHE_ENTRY)), | 198 net::NetLogSourceType::DISK_CACHE_ENTRY)), |
| 199 stream_0_data_(new net::GrowableIOBuffer()) { | 199 stream_0_data_(new net::GrowableIOBuffer()), |
| 200 stream_1_prefetch_data_(new net::GrowableIOBuffer()) { |
| 200 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_), | 201 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_), |
| 201 "arrays should be the same size"); | 202 "arrays should be the same size"); |
| 202 static_assert(arraysize(data_size_) == arraysize(crc32s_), | 203 static_assert(arraysize(data_size_) == arraysize(crc32s_), |
| 203 "arrays should be the same size"); | 204 "arrays should be the same size"); |
| 204 static_assert(arraysize(data_size_) == arraysize(have_written_), | 205 static_assert(arraysize(data_size_) == arraysize(have_written_), |
| 205 "arrays should be the same size"); | 206 "arrays should be the same size"); |
| 206 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), | 207 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), |
| 207 "arrays should be the same size"); | 208 "arrays should be the same size"); |
| 208 MakeUninitialized(); | 209 MakeUninitialized(); |
| 209 net_log_.BeginEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY, | 210 net_log_.BeginEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. | 551 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. |
| 551 return net::OK; | 552 return net::OK; |
| 552 } | 553 } |
| 553 | 554 |
| 554 size_t SimpleEntryImpl::EstimateMemoryUsage() const { | 555 size_t SimpleEntryImpl::EstimateMemoryUsage() const { |
| 555 // TODO(xunjieli): crbug.com/669108. It'd be nice to have the rest of |entry| | 556 // TODO(xunjieli): crbug.com/669108. It'd be nice to have the rest of |entry| |
| 556 // measured, but the ownership of SimpleSynchronousEntry isn't straightforward | 557 // measured, but the ownership of SimpleSynchronousEntry isn't straightforward |
| 557 return sizeof(SimpleSynchronousEntry) + | 558 return sizeof(SimpleSynchronousEntry) + |
| 558 base::trace_event::EstimateMemoryUsage(pending_operations_) + | 559 base::trace_event::EstimateMemoryUsage(pending_operations_) + |
| 559 base::trace_event::EstimateMemoryUsage(executing_operation_) + | 560 base::trace_event::EstimateMemoryUsage(executing_operation_) + |
| 560 (stream_0_data_ ? stream_0_data_->capacity() : 0); | 561 (stream_0_data_ ? stream_0_data_->capacity() : 0) + |
| 562 (stream_1_prefetch_data_ ? stream_1_prefetch_data_->capacity() : 0); |
| 561 } | 563 } |
| 562 | 564 |
| 563 SimpleEntryImpl::~SimpleEntryImpl() { | 565 SimpleEntryImpl::~SimpleEntryImpl() { |
| 564 DCHECK(io_thread_checker_.CalledOnValidThread()); | 566 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 565 DCHECK_EQ(0U, pending_operations_.size()); | 567 DCHECK_EQ(0U, pending_operations_.size()); |
| 566 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); | 568 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); |
| 567 DCHECK(!synchronous_entry_); | 569 DCHECK(!synchronous_entry_); |
| 568 net_log_.EndEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY); | 570 net_log_.EndEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY); |
| 569 } | 571 } |
| 570 | 572 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 // Since stream 0 data is kept in memory, it is read immediately. | 861 // Since stream 0 data is kept in memory, it is read immediately. |
| 860 if (stream_index == 0) { | 862 if (stream_index == 0) { |
| 861 int ret_value = ReadStream0Data(buf, offset, buf_len); | 863 int ret_value = ReadStream0Data(buf, offset, buf_len); |
| 862 if (!callback.is_null()) { | 864 if (!callback.is_null()) { |
| 863 base::ThreadTaskRunnerHandle::Get()->PostTask( | 865 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 864 FROM_HERE, base::Bind(callback, ret_value)); | 866 FROM_HERE, base::Bind(callback, ret_value)); |
| 865 } | 867 } |
| 866 return; | 868 return; |
| 867 } | 869 } |
| 868 | 870 |
| 871 // XXX(jkarlin): See if we can use the prefetch data for stream 1. |
| 872 |
| 869 state_ = STATE_IO_PENDING; | 873 state_ = STATE_IO_PENDING; |
| 870 if (!doomed_ && backend_.get()) | 874 if (!doomed_ && backend_.get()) |
| 871 backend_->index()->UseIfExists(entry_hash_); | 875 backend_->index()->UseIfExists(entry_hash_); |
| 872 | 876 |
| 873 // Figure out if we should be computing the checksum for this read, | 877 // Figure out if we should be computing the checksum for this read, |
| 874 // and whether we should be verifying it, too. | 878 // and whether we should be verifying it, too. |
| 875 std::unique_ptr<SimpleSynchronousEntry::CRCRequest> crc_request; | 879 std::unique_ptr<SimpleSynchronousEntry::CRCRequest> crc_request; |
| 876 if (crc32s_end_offset_[stream_index] == offset) { | 880 if (crc32s_end_offset_[stream_index] == offset) { |
| 877 crc_request.reset(new SimpleSynchronousEntry::CRCRequest()); | 881 crc_request.reset(new SimpleSynchronousEntry::CRCRequest()); |
| 878 | 882 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 | 1158 |
| 1155 state_ = STATE_READY; | 1159 state_ = STATE_READY; |
| 1156 synchronous_entry_ = in_results->sync_entry; | 1160 synchronous_entry_ = in_results->sync_entry; |
| 1157 if (in_results->stream_0_data.get()) { | 1161 if (in_results->stream_0_data.get()) { |
| 1158 stream_0_data_ = in_results->stream_0_data; | 1162 stream_0_data_ = in_results->stream_0_data; |
| 1159 // The crc was read in SimpleSynchronousEntry. | 1163 // The crc was read in SimpleSynchronousEntry. |
| 1160 crc_check_state_[0] = CRC_CHECK_DONE; | 1164 crc_check_state_[0] = CRC_CHECK_DONE; |
| 1161 crc32s_[0] = in_results->stream_0_crc32; | 1165 crc32s_[0] = in_results->stream_0_crc32; |
| 1162 crc32s_end_offset_[0] = in_results->entry_stat.data_size(0); | 1166 crc32s_end_offset_[0] = in_results->entry_stat.data_size(0); |
| 1163 } | 1167 } |
| 1168 if (in_results->stream_1_prefetch_data.get()) { |
| 1169 stream_1_prefetch_data_ = in_results->stream_1_prefetch_data; |
| 1170 } |
| 1171 |
| 1164 // If this entry was opened by hash, key_ could still be empty. If so, update | 1172 // If this entry was opened by hash, key_ could still be empty. If so, update |
| 1165 // it with the key read from the synchronous entry. | 1173 // it with the key read from the synchronous entry. |
| 1166 if (key_.empty()) { | 1174 if (key_.empty()) { |
| 1167 SetKey(synchronous_entry_->key()); | 1175 SetKey(synchronous_entry_->key()); |
| 1168 } else { | 1176 } else { |
| 1169 // This should only be triggered when creating an entry. In the open case | 1177 // This should only be triggered when creating an entry. In the open case |
| 1170 // the key is either copied from the arguments to open, or checked | 1178 // the key is either copied from the arguments to open, or checked |
| 1171 // in the synchronous entry. | 1179 // in the synchronous entry. |
| 1172 DCHECK_EQ(key_, synchronous_entry_->key()); | 1180 DCHECK_EQ(key_, synchronous_entry_->key()); |
| 1173 } | 1181 } |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 } | 1536 } |
| 1529 crc32s_end_offset_[stream_index] = offset + length; | 1537 crc32s_end_offset_[stream_index] = offset + length; |
| 1530 } else if (offset < crc32s_end_offset_[stream_index]) { | 1538 } else if (offset < crc32s_end_offset_[stream_index]) { |
| 1531 // If a range for which the crc32 was already computed is rewritten, the | 1539 // If a range for which the crc32 was already computed is rewritten, the |
| 1532 // computation of the crc32 need to start from 0 again. | 1540 // computation of the crc32 need to start from 0 again. |
| 1533 crc32s_end_offset_[stream_index] = 0; | 1541 crc32s_end_offset_[stream_index] = 0; |
| 1534 } | 1542 } |
| 1535 } | 1543 } |
| 1536 | 1544 |
| 1537 } // namespace disk_cache | 1545 } // namespace disk_cache |
| OLD | NEW |