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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 return; | 689 return; |
690 } | 690 } |
691 | 691 |
692 DCHECK_EQ(STATE_UNINITIALIZED, state_); | 692 DCHECK_EQ(STATE_UNINITIALIZED, state_); |
693 DCHECK(!synchronous_entry_); | 693 DCHECK(!synchronous_entry_); |
694 state_ = STATE_IO_PENDING; | 694 state_ = STATE_IO_PENDING; |
695 const base::TimeTicks start_time = base::TimeTicks::Now(); | 695 const base::TimeTicks start_time = base::TimeTicks::Now(); |
696 std::unique_ptr<SimpleEntryCreationResults> results( | 696 std::unique_ptr<SimpleEntryCreationResults> results( |
697 new SimpleEntryCreationResults(SimpleEntryStat( | 697 new SimpleEntryCreationResults(SimpleEntryStat( |
698 last_used_, last_modified_, data_size_, sparse_data_size_))); | 698 last_used_, last_modified_, data_size_, sparse_data_size_))); |
699 Closure task = base::Bind(&SimpleSynchronousEntry::OpenEntry, | 699 Closure task = |
700 cache_type_, | 700 base::Bind(&SimpleSynchronousEntry::OpenEntry, cache_type_, path_, key_, |
701 path_, | 701 entry_hash_, have_index, results.get()); |
702 entry_hash_, | 702 Closure reply = |
703 have_index, | 703 base::Bind(&SimpleEntryImpl::CreationOperationComplete, this, callback, |
704 results.get()); | 704 start_time, base::Passed(&results), out_entry, |
705 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, | 705 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END); |
706 this, | |
707 callback, | |
708 start_time, | |
709 base::Passed(&results), | |
710 out_entry, | |
711 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END); | |
712 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); | 706 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); |
713 } | 707 } |
714 | 708 |
715 void SimpleEntryImpl::CreateEntryInternal(bool have_index, | 709 void SimpleEntryImpl::CreateEntryInternal(bool have_index, |
716 const CompletionCallback& callback, | 710 const CompletionCallback& callback, |
717 Entry** out_entry) { | 711 Entry** out_entry) { |
718 ScopedOperationRunner operation_runner(this); | 712 ScopedOperationRunner operation_runner(this); |
719 | 713 |
720 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_BEGIN); | 714 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_BEGIN); |
721 | 715 |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1140 | 1134 |
1141 state_ = STATE_READY; | 1135 state_ = STATE_READY; |
1142 synchronous_entry_ = in_results->sync_entry; | 1136 synchronous_entry_ = in_results->sync_entry; |
1143 if (in_results->stream_0_data.get()) { | 1137 if (in_results->stream_0_data.get()) { |
1144 stream_0_data_ = in_results->stream_0_data; | 1138 stream_0_data_ = in_results->stream_0_data; |
1145 // The crc was read in SimpleSynchronousEntry. | 1139 // The crc was read in SimpleSynchronousEntry. |
1146 crc_check_state_[0] = CRC_CHECK_DONE; | 1140 crc_check_state_[0] = CRC_CHECK_DONE; |
1147 crc32s_[0] = in_results->stream_0_crc32; | 1141 crc32s_[0] = in_results->stream_0_crc32; |
1148 crc32s_end_offset_[0] = in_results->entry_stat.data_size(0); | 1142 crc32s_end_offset_[0] = in_results->entry_stat.data_size(0); |
1149 } | 1143 } |
1150 if (key_.empty()) { | 1144 if (key_.empty()) |
Randy Smith (Not in Mondays)
2016/05/17 20:04:07
It's not really part of this CL, but I'd value hav
gavinp
2016/05/18 15:46:00
Done.
| |
1151 SetKey(synchronous_entry_->key()); | 1145 SetKey(synchronous_entry_->key()); |
1152 } else { | |
1153 // This should only be triggered when creating an entry. The key check in | |
1154 // the open case is handled in SimpleBackendImpl. | |
1155 DCHECK_EQ(key_, synchronous_entry_->key()); | |
1156 } | |
1157 UpdateDataFromEntryStat(in_results->entry_stat); | 1146 UpdateDataFromEntryStat(in_results->entry_stat); |
1158 SIMPLE_CACHE_UMA(TIMES, | 1147 SIMPLE_CACHE_UMA(TIMES, |
1159 "EntryCreationTime", cache_type_, | 1148 "EntryCreationTime", cache_type_, |
1160 (base::TimeTicks::Now() - start_time)); | 1149 (base::TimeTicks::Now() - start_time)); |
1161 AdjustOpenEntryCountBy(cache_type_, 1); | 1150 AdjustOpenEntryCountBy(cache_type_, 1); |
1162 | 1151 |
1163 net_log_.AddEvent(end_event_type); | 1152 net_log_.AddEvent(end_event_type); |
1164 PostClientCallback(completion_callback, net::OK); | 1153 PostClientCallback(completion_callback, net::OK); |
1165 } | 1154 } |
1166 | 1155 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1396 } | 1385 } |
1397 sparse_data_size_ = entry_stat.sparse_data_size(); | 1386 sparse_data_size_ = entry_stat.sparse_data_size(); |
1398 if (!doomed_ && backend_.get()) | 1387 if (!doomed_ && backend_.get()) |
1399 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage()); | 1388 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage()); |
1400 } | 1389 } |
1401 | 1390 |
1402 int64_t SimpleEntryImpl::GetDiskUsage() const { | 1391 int64_t SimpleEntryImpl::GetDiskUsage() const { |
1403 int64_t file_size = 0; | 1392 int64_t file_size = 0; |
1404 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { | 1393 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { |
1405 file_size += | 1394 file_size += |
1406 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]); | 1395 simple_util::GetFileSizeFromDataSize(key_.size(), data_size_[i]); |
1407 } | 1396 } |
1408 file_size += sparse_data_size_; | 1397 file_size += sparse_data_size_; |
1409 return file_size; | 1398 return file_size; |
1410 } | 1399 } |
1411 | 1400 |
1412 void SimpleEntryImpl::RecordReadIsParallelizable( | 1401 void SimpleEntryImpl::RecordReadIsParallelizable( |
1413 const SimpleEntryOperation& operation) const { | 1402 const SimpleEntryOperation& operation) const { |
1414 if (!executing_operation_) | 1403 if (!executing_operation_) |
1415 return; | 1404 return; |
1416 // Used in histograms, please only add entries at the end. | 1405 // Used in histograms, please only add entries at the end. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1552 } | 1541 } |
1553 crc32s_end_offset_[stream_index] = offset + length; | 1542 crc32s_end_offset_[stream_index] = offset + length; |
1554 } else if (offset < crc32s_end_offset_[stream_index]) { | 1543 } else if (offset < crc32s_end_offset_[stream_index]) { |
1555 // If a range for which the crc32 was already computed is rewritten, the | 1544 // If a range for which the crc32 was already computed is rewritten, the |
1556 // computation of the crc32 need to start from 0 again. | 1545 // computation of the crc32 need to start from 0 again. |
1557 crc32s_end_offset_[stream_index] = 0; | 1546 crc32s_end_offset_[stream_index] = 0; |
1558 } | 1547 } |
1559 } | 1548 } |
1560 | 1549 |
1561 } // namespace disk_cache | 1550 } // namespace disk_cache |
OLD | NEW |