| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 static_assert(arraysize(data_size_) == arraysize(have_written_), | 193 static_assert(arraysize(data_size_) == arraysize(have_written_), |
| 194 "arrays should be the same size"); | 194 "arrays should be the same size"); |
| 195 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), | 195 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), |
| 196 "arrays should be the same size"); | 196 "arrays should be the same size"); |
| 197 MakeUninitialized(); | 197 MakeUninitialized(); |
| 198 net_log_.BeginEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY, | 198 net_log_.BeginEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY, |
| 199 CreateNetLogSimpleEntryConstructionCallback(this)); | 199 CreateNetLogSimpleEntryConstructionCallback(this)); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void SimpleEntryImpl::SetActiveEntryProxy( | 202 void SimpleEntryImpl::SetActiveEntryProxy( |
| 203 scoped_ptr<ActiveEntryProxy> active_entry_proxy) { | 203 std::unique_ptr<ActiveEntryProxy> active_entry_proxy) { |
| 204 DCHECK(!active_entry_proxy_); | 204 DCHECK(!active_entry_proxy_); |
| 205 active_entry_proxy_.reset(active_entry_proxy.release()); | 205 active_entry_proxy_.reset(active_entry_proxy.release()); |
| 206 } | 206 } |
| 207 | 207 |
| 208 int SimpleEntryImpl::OpenEntry(Entry** out_entry, | 208 int SimpleEntryImpl::OpenEntry(Entry** out_entry, |
| 209 const CompletionCallback& callback) { | 209 const CompletionCallback& callback) { |
| 210 DCHECK(backend_.get()); | 210 DCHECK(backend_.get()); |
| 211 | 211 |
| 212 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_CALL); | 212 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_CALL); |
| 213 | 213 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 backend_->index()->Remove(entry_hash_); | 593 backend_->index()->Remove(entry_hash_); |
| 594 active_entry_proxy_.reset(); | 594 active_entry_proxy_.reset(); |
| 595 } | 595 } |
| 596 | 596 |
| 597 void SimpleEntryImpl::RunNextOperationIfNeeded() { | 597 void SimpleEntryImpl::RunNextOperationIfNeeded() { |
| 598 DCHECK(io_thread_checker_.CalledOnValidThread()); | 598 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 599 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, | 599 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, |
| 600 "EntryOperationsPending", cache_type_, | 600 "EntryOperationsPending", cache_type_, |
| 601 pending_operations_.size(), 0, 100, 20); | 601 pending_operations_.size(), 0, 100, 20); |
| 602 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) { | 602 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) { |
| 603 scoped_ptr<SimpleEntryOperation> operation( | 603 std::unique_ptr<SimpleEntryOperation> operation( |
| 604 new SimpleEntryOperation(pending_operations_.front())); | 604 new SimpleEntryOperation(pending_operations_.front())); |
| 605 pending_operations_.pop(); | 605 pending_operations_.pop(); |
| 606 switch (operation->type()) { | 606 switch (operation->type()) { |
| 607 case SimpleEntryOperation::TYPE_OPEN: | 607 case SimpleEntryOperation::TYPE_OPEN: |
| 608 OpenEntryInternal(operation->have_index(), | 608 OpenEntryInternal(operation->have_index(), |
| 609 operation->callback(), | 609 operation->callback(), |
| 610 operation->out_entry()); | 610 operation->out_entry()); |
| 611 break; | 611 break; |
| 612 case SimpleEntryOperation::TYPE_CREATE: | 612 case SimpleEntryOperation::TYPE_CREATE: |
| 613 CreateEntryInternal(operation->have_index(), | 613 CreateEntryInternal(operation->have_index(), |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 net_log_.AddEvent( | 686 net_log_.AddEvent( |
| 687 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, | 687 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, |
| 688 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); | 688 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); |
| 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 scoped_ptr<SimpleEntryCreationResults> results( | 696 std::unique_ptr<SimpleEntryCreationResults> results( |
| 697 new SimpleEntryCreationResults( | 697 new SimpleEntryCreationResults(SimpleEntryStat( |
| 698 SimpleEntryStat(last_used_, last_modified_, data_size_, | 698 last_used_, last_modified_, data_size_, sparse_data_size_))); |
| 699 sparse_data_size_))); | |
| 700 Closure task = base::Bind(&SimpleSynchronousEntry::OpenEntry, | 699 Closure task = base::Bind(&SimpleSynchronousEntry::OpenEntry, |
| 701 cache_type_, | 700 cache_type_, |
| 702 path_, | 701 path_, |
| 703 entry_hash_, | 702 entry_hash_, |
| 704 have_index, | 703 have_index, |
| 705 results.get()); | 704 results.get()); |
| 706 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, | 705 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, |
| 707 this, | 706 this, |
| 708 callback, | 707 callback, |
| 709 start_time, | 708 start_time, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 735 | 734 |
| 736 // Since we don't know the correct values for |last_used_| and | 735 // Since we don't know the correct values for |last_used_| and |
| 737 // |last_modified_| yet, we make this approximation. | 736 // |last_modified_| yet, we make this approximation. |
| 738 last_used_ = last_modified_ = base::Time::Now(); | 737 last_used_ = last_modified_ = base::Time::Now(); |
| 739 | 738 |
| 740 // If creation succeeds, we should mark all streams to be saved on close. | 739 // If creation succeeds, we should mark all streams to be saved on close. |
| 741 for (int i = 0; i < kSimpleEntryStreamCount; ++i) | 740 for (int i = 0; i < kSimpleEntryStreamCount; ++i) |
| 742 have_written_[i] = true; | 741 have_written_[i] = true; |
| 743 | 742 |
| 744 const base::TimeTicks start_time = base::TimeTicks::Now(); | 743 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 745 scoped_ptr<SimpleEntryCreationResults> results( | 744 std::unique_ptr<SimpleEntryCreationResults> results( |
| 746 new SimpleEntryCreationResults( | 745 new SimpleEntryCreationResults(SimpleEntryStat( |
| 747 SimpleEntryStat(last_used_, last_modified_, data_size_, | 746 last_used_, last_modified_, data_size_, sparse_data_size_))); |
| 748 sparse_data_size_))); | |
| 749 Closure task = base::Bind(&SimpleSynchronousEntry::CreateEntry, | 747 Closure task = base::Bind(&SimpleSynchronousEntry::CreateEntry, |
| 750 cache_type_, | 748 cache_type_, |
| 751 path_, | 749 path_, |
| 752 key_, | 750 key_, |
| 753 entry_hash_, | 751 entry_hash_, |
| 754 have_index, | 752 have_index, |
| 755 results.get()); | 753 results.get()); |
| 756 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, | 754 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, |
| 757 this, | 755 this, |
| 758 callback, | 756 callback, |
| 759 start_time, | 757 start_time, |
| 760 base::Passed(&results), | 758 base::Passed(&results), |
| 761 out_entry, | 759 out_entry, |
| 762 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_END); | 760 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_END); |
| 763 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); | 761 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); |
| 764 } | 762 } |
| 765 | 763 |
| 766 void SimpleEntryImpl::CloseInternal() { | 764 void SimpleEntryImpl::CloseInternal() { |
| 767 DCHECK(io_thread_checker_.CalledOnValidThread()); | 765 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 768 typedef SimpleSynchronousEntry::CRCRecord CRCRecord; | 766 typedef SimpleSynchronousEntry::CRCRecord CRCRecord; |
| 769 scoped_ptr<std::vector<CRCRecord> > | 767 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write( |
| 770 crc32s_to_write(new std::vector<CRCRecord>()); | 768 new std::vector<CRCRecord>()); |
| 771 | 769 |
| 772 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_BEGIN); | 770 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_BEGIN); |
| 773 | 771 |
| 774 if (state_ == STATE_READY) { | 772 if (state_ == STATE_READY) { |
| 775 DCHECK(synchronous_entry_); | 773 DCHECK(synchronous_entry_); |
| 776 state_ = STATE_IO_PENDING; | 774 state_ = STATE_IO_PENDING; |
| 777 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { | 775 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { |
| 778 if (have_written_[i]) { | 776 if (have_written_[i]) { |
| 779 if (GetDataSize(i) == crc32s_end_offset_[i]) { | 777 if (GetDataSize(i) == crc32s_end_offset_[i]) { |
| 780 int32_t crc = GetDataSize(i) == 0 ? crc32(0, Z_NULL, 0) : crc32s_[i]; | 778 int32_t crc = GetDataSize(i) == 0 ? crc32(0, Z_NULL, 0) : crc32s_[i]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 base::ThreadTaskRunnerHandle::Get()->PostTask( | 859 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 862 FROM_HERE, base::Bind(callback, ret_value)); | 860 FROM_HERE, base::Bind(callback, ret_value)); |
| 863 } | 861 } |
| 864 return; | 862 return; |
| 865 } | 863 } |
| 866 | 864 |
| 867 state_ = STATE_IO_PENDING; | 865 state_ = STATE_IO_PENDING; |
| 868 if (!doomed_ && backend_.get()) | 866 if (!doomed_ && backend_.get()) |
| 869 backend_->index()->UseIfExists(entry_hash_); | 867 backend_->index()->UseIfExists(entry_hash_); |
| 870 | 868 |
| 871 scoped_ptr<uint32_t> read_crc32(new uint32_t()); | 869 std::unique_ptr<uint32_t> read_crc32(new uint32_t()); |
| 872 scoped_ptr<int> result(new int()); | 870 std::unique_ptr<int> result(new int()); |
| 873 scoped_ptr<SimpleEntryStat> entry_stat( | 871 std::unique_ptr<SimpleEntryStat> entry_stat(new SimpleEntryStat( |
| 874 new SimpleEntryStat(last_used_, last_modified_, data_size_, | 872 last_used_, last_modified_, data_size_, sparse_data_size_)); |
| 875 sparse_data_size_)); | |
| 876 Closure task = base::Bind( | 873 Closure task = base::Bind( |
| 877 &SimpleSynchronousEntry::ReadData, base::Unretained(synchronous_entry_), | 874 &SimpleSynchronousEntry::ReadData, base::Unretained(synchronous_entry_), |
| 878 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len), | 875 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len), |
| 879 base::RetainedRef(buf), read_crc32.get(), entry_stat.get(), result.get()); | 876 base::RetainedRef(buf), read_crc32.get(), entry_stat.get(), result.get()); |
| 880 Closure reply = base::Bind(&SimpleEntryImpl::ReadOperationComplete, | 877 Closure reply = base::Bind(&SimpleEntryImpl::ReadOperationComplete, |
| 881 this, | 878 this, |
| 882 stream_index, | 879 stream_index, |
| 883 offset, | 880 offset, |
| 884 callback, | 881 callback, |
| 885 base::Passed(&read_crc32), | 882 base::Passed(&read_crc32), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 return; | 940 return; |
| 944 } | 941 } |
| 945 } | 942 } |
| 946 state_ = STATE_IO_PENDING; | 943 state_ = STATE_IO_PENDING; |
| 947 if (!doomed_ && backend_.get()) | 944 if (!doomed_ && backend_.get()) |
| 948 backend_->index()->UseIfExists(entry_hash_); | 945 backend_->index()->UseIfExists(entry_hash_); |
| 949 | 946 |
| 950 AdvanceCrc(buf, offset, buf_len, stream_index); | 947 AdvanceCrc(buf, offset, buf_len, stream_index); |
| 951 | 948 |
| 952 // |entry_stat| needs to be initialized before modifying |data_size_|. | 949 // |entry_stat| needs to be initialized before modifying |data_size_|. |
| 953 scoped_ptr<SimpleEntryStat> entry_stat( | 950 std::unique_ptr<SimpleEntryStat> entry_stat(new SimpleEntryStat( |
| 954 new SimpleEntryStat(last_used_, last_modified_, data_size_, | 951 last_used_, last_modified_, data_size_, sparse_data_size_)); |
| 955 sparse_data_size_)); | |
| 956 if (truncate) { | 952 if (truncate) { |
| 957 data_size_[stream_index] = offset + buf_len; | 953 data_size_[stream_index] = offset + buf_len; |
| 958 } else { | 954 } else { |
| 959 data_size_[stream_index] = std::max(offset + buf_len, | 955 data_size_[stream_index] = std::max(offset + buf_len, |
| 960 GetDataSize(stream_index)); | 956 GetDataSize(stream_index)); |
| 961 } | 957 } |
| 962 | 958 |
| 963 // Since we don't know the correct values for |last_used_| and | 959 // Since we don't know the correct values for |last_used_| and |
| 964 // |last_modified_| yet, we make this approximation. | 960 // |last_modified_| yet, we make this approximation. |
| 965 last_used_ = last_modified_ = base::Time::Now(); | 961 last_used_ = last_modified_ = base::Time::Now(); |
| 966 | 962 |
| 967 have_written_[stream_index] = true; | 963 have_written_[stream_index] = true; |
| 968 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF | 964 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF |
| 969 // record will have to be rewritten. | 965 // record will have to be rewritten. |
| 970 if (stream_index == 1) | 966 if (stream_index == 1) |
| 971 have_written_[0] = true; | 967 have_written_[0] = true; |
| 972 | 968 |
| 973 scoped_ptr<int> result(new int()); | 969 std::unique_ptr<int> result(new int()); |
| 974 Closure task = base::Bind( | 970 Closure task = base::Bind( |
| 975 &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_), | 971 &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_), |
| 976 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len, | 972 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len, |
| 977 truncate, doomed_), | 973 truncate, doomed_), |
| 978 base::RetainedRef(buf), entry_stat.get(), result.get()); | 974 base::RetainedRef(buf), entry_stat.get(), result.get()); |
| 979 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, | 975 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, |
| 980 this, | 976 this, |
| 981 stream_index, | 977 stream_index, |
| 982 callback, | 978 callback, |
| 983 base::Passed(&entry_stat), | 979 base::Passed(&entry_stat), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 995 | 991 |
| 996 if (net_log_.IsCapturing()) { | 992 if (net_log_.IsCapturing()) { |
| 997 net_log_.AddEvent( | 993 net_log_.AddEvent( |
| 998 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN, | 994 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN, |
| 999 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); | 995 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); |
| 1000 } | 996 } |
| 1001 | 997 |
| 1002 DCHECK_EQ(STATE_READY, state_); | 998 DCHECK_EQ(STATE_READY, state_); |
| 1003 state_ = STATE_IO_PENDING; | 999 state_ = STATE_IO_PENDING; |
| 1004 | 1000 |
| 1005 scoped_ptr<int> result(new int()); | 1001 std::unique_ptr<int> result(new int()); |
| 1006 scoped_ptr<base::Time> last_used(new base::Time()); | 1002 std::unique_ptr<base::Time> last_used(new base::Time()); |
| 1007 Closure task = base::Bind( | 1003 Closure task = base::Bind( |
| 1008 &SimpleSynchronousEntry::ReadSparseData, | 1004 &SimpleSynchronousEntry::ReadSparseData, |
| 1009 base::Unretained(synchronous_entry_), | 1005 base::Unretained(synchronous_entry_), |
| 1010 SimpleSynchronousEntry::EntryOperationData(sparse_offset, buf_len), | 1006 SimpleSynchronousEntry::EntryOperationData(sparse_offset, buf_len), |
| 1011 base::RetainedRef(buf), last_used.get(), result.get()); | 1007 base::RetainedRef(buf), last_used.get(), result.get()); |
| 1012 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete, | 1008 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete, |
| 1013 this, | 1009 this, |
| 1014 callback, | 1010 callback, |
| 1015 base::Passed(&last_used), | 1011 base::Passed(&last_used), |
| 1016 base::Passed(&result)); | 1012 base::Passed(&result)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1033 | 1029 |
| 1034 DCHECK_EQ(STATE_READY, state_); | 1030 DCHECK_EQ(STATE_READY, state_); |
| 1035 state_ = STATE_IO_PENDING; | 1031 state_ = STATE_IO_PENDING; |
| 1036 | 1032 |
| 1037 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max(); | 1033 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max(); |
| 1038 if (backend_.get()) { | 1034 if (backend_.get()) { |
| 1039 uint64_t max_cache_size = backend_->index()->max_size(); | 1035 uint64_t max_cache_size = backend_->index()->max_size(); |
| 1040 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; | 1036 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; |
| 1041 } | 1037 } |
| 1042 | 1038 |
| 1043 scoped_ptr<SimpleEntryStat> entry_stat( | 1039 std::unique_ptr<SimpleEntryStat> entry_stat(new SimpleEntryStat( |
| 1044 new SimpleEntryStat(last_used_, last_modified_, data_size_, | 1040 last_used_, last_modified_, data_size_, sparse_data_size_)); |
| 1045 sparse_data_size_)); | |
| 1046 | 1041 |
| 1047 last_used_ = last_modified_ = base::Time::Now(); | 1042 last_used_ = last_modified_ = base::Time::Now(); |
| 1048 | 1043 |
| 1049 scoped_ptr<int> result(new int()); | 1044 std::unique_ptr<int> result(new int()); |
| 1050 Closure task = base::Bind( | 1045 Closure task = base::Bind( |
| 1051 &SimpleSynchronousEntry::WriteSparseData, | 1046 &SimpleSynchronousEntry::WriteSparseData, |
| 1052 base::Unretained(synchronous_entry_), | 1047 base::Unretained(synchronous_entry_), |
| 1053 SimpleSynchronousEntry::EntryOperationData(sparse_offset, buf_len), | 1048 SimpleSynchronousEntry::EntryOperationData(sparse_offset, buf_len), |
| 1054 base::RetainedRef(buf), max_sparse_data_size, entry_stat.get(), | 1049 base::RetainedRef(buf), max_sparse_data_size, entry_stat.get(), |
| 1055 result.get()); | 1050 result.get()); |
| 1056 Closure reply = base::Bind(&SimpleEntryImpl::WriteSparseOperationComplete, | 1051 Closure reply = base::Bind(&SimpleEntryImpl::WriteSparseOperationComplete, |
| 1057 this, | 1052 this, |
| 1058 callback, | 1053 callback, |
| 1059 base::Passed(&entry_stat), | 1054 base::Passed(&entry_stat), |
| 1060 base::Passed(&result)); | 1055 base::Passed(&result)); |
| 1061 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); | 1056 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); |
| 1062 } | 1057 } |
| 1063 | 1058 |
| 1064 void SimpleEntryImpl::GetAvailableRangeInternal( | 1059 void SimpleEntryImpl::GetAvailableRangeInternal( |
| 1065 int64_t sparse_offset, | 1060 int64_t sparse_offset, |
| 1066 int len, | 1061 int len, |
| 1067 int64_t* out_start, | 1062 int64_t* out_start, |
| 1068 const CompletionCallback& callback) { | 1063 const CompletionCallback& callback) { |
| 1069 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1064 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1070 ScopedOperationRunner operation_runner(this); | 1065 ScopedOperationRunner operation_runner(this); |
| 1071 | 1066 |
| 1072 DCHECK_EQ(STATE_READY, state_); | 1067 DCHECK_EQ(STATE_READY, state_); |
| 1073 state_ = STATE_IO_PENDING; | 1068 state_ = STATE_IO_PENDING; |
| 1074 | 1069 |
| 1075 scoped_ptr<int> result(new int()); | 1070 std::unique_ptr<int> result(new int()); |
| 1076 Closure task = base::Bind(&SimpleSynchronousEntry::GetAvailableRange, | 1071 Closure task = base::Bind(&SimpleSynchronousEntry::GetAvailableRange, |
| 1077 base::Unretained(synchronous_entry_), | 1072 base::Unretained(synchronous_entry_), |
| 1078 SimpleSynchronousEntry::EntryOperationData( | 1073 SimpleSynchronousEntry::EntryOperationData( |
| 1079 sparse_offset, len), | 1074 sparse_offset, len), |
| 1080 out_start, | 1075 out_start, |
| 1081 result.get()); | 1076 result.get()); |
| 1082 Closure reply = base::Bind( | 1077 Closure reply = base::Bind( |
| 1083 &SimpleEntryImpl::GetAvailableRangeOperationComplete, | 1078 &SimpleEntryImpl::GetAvailableRangeOperationComplete, |
| 1084 this, | 1079 this, |
| 1085 callback, | 1080 callback, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1112 FROM_HERE, | 1107 FROM_HERE, |
| 1113 base::Bind(&SimpleSynchronousEntry::DoomEntry, path_, entry_hash_), | 1108 base::Bind(&SimpleSynchronousEntry::DoomEntry, path_, entry_hash_), |
| 1114 base::Bind( | 1109 base::Bind( |
| 1115 &SimpleEntryImpl::DoomOperationComplete, this, callback, state_)); | 1110 &SimpleEntryImpl::DoomOperationComplete, this, callback, state_)); |
| 1116 state_ = STATE_IO_PENDING; | 1111 state_ = STATE_IO_PENDING; |
| 1117 } | 1112 } |
| 1118 | 1113 |
| 1119 void SimpleEntryImpl::CreationOperationComplete( | 1114 void SimpleEntryImpl::CreationOperationComplete( |
| 1120 const CompletionCallback& completion_callback, | 1115 const CompletionCallback& completion_callback, |
| 1121 const base::TimeTicks& start_time, | 1116 const base::TimeTicks& start_time, |
| 1122 scoped_ptr<SimpleEntryCreationResults> in_results, | 1117 std::unique_ptr<SimpleEntryCreationResults> in_results, |
| 1123 Entry** out_entry, | 1118 Entry** out_entry, |
| 1124 net::NetLog::EventType end_event_type) { | 1119 net::NetLog::EventType end_event_type) { |
| 1125 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1120 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1126 DCHECK_EQ(state_, STATE_IO_PENDING); | 1121 DCHECK_EQ(state_, STATE_IO_PENDING); |
| 1127 DCHECK(in_results); | 1122 DCHECK(in_results); |
| 1128 ScopedOperationRunner operation_runner(this); | 1123 ScopedOperationRunner operation_runner(this); |
| 1129 SIMPLE_CACHE_UMA(BOOLEAN, | 1124 SIMPLE_CACHE_UMA(BOOLEAN, |
| 1130 "EntryCreationResult", cache_type_, | 1125 "EntryCreationResult", cache_type_, |
| 1131 in_results->result == net::OK); | 1126 in_results->result == net::OK); |
| 1132 if (in_results->result != net::OK) { | 1127 if (in_results->result != net::OK) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 (base::TimeTicks::Now() - start_time)); | 1160 (base::TimeTicks::Now() - start_time)); |
| 1166 AdjustOpenEntryCountBy(cache_type_, 1); | 1161 AdjustOpenEntryCountBy(cache_type_, 1); |
| 1167 | 1162 |
| 1168 net_log_.AddEvent(end_event_type); | 1163 net_log_.AddEvent(end_event_type); |
| 1169 PostClientCallback(completion_callback, net::OK); | 1164 PostClientCallback(completion_callback, net::OK); |
| 1170 } | 1165 } |
| 1171 | 1166 |
| 1172 void SimpleEntryImpl::EntryOperationComplete( | 1167 void SimpleEntryImpl::EntryOperationComplete( |
| 1173 const CompletionCallback& completion_callback, | 1168 const CompletionCallback& completion_callback, |
| 1174 const SimpleEntryStat& entry_stat, | 1169 const SimpleEntryStat& entry_stat, |
| 1175 scoped_ptr<int> result) { | 1170 std::unique_ptr<int> result) { |
| 1176 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1171 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1177 DCHECK(synchronous_entry_); | 1172 DCHECK(synchronous_entry_); |
| 1178 DCHECK_EQ(STATE_IO_PENDING, state_); | 1173 DCHECK_EQ(STATE_IO_PENDING, state_); |
| 1179 DCHECK(result); | 1174 DCHECK(result); |
| 1180 if (*result < 0) { | 1175 if (*result < 0) { |
| 1181 state_ = STATE_FAILURE; | 1176 state_ = STATE_FAILURE; |
| 1182 MarkAsDoomed(); | 1177 MarkAsDoomed(); |
| 1183 } else { | 1178 } else { |
| 1184 state_ = STATE_READY; | 1179 state_ = STATE_READY; |
| 1185 UpdateDataFromEntryStat(entry_stat); | 1180 UpdateDataFromEntryStat(entry_stat); |
| 1186 } | 1181 } |
| 1187 | 1182 |
| 1188 if (!completion_callback.is_null()) { | 1183 if (!completion_callback.is_null()) { |
| 1189 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1184 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1190 FROM_HERE, base::Bind(completion_callback, *result)); | 1185 FROM_HERE, base::Bind(completion_callback, *result)); |
| 1191 } | 1186 } |
| 1192 RunNextOperationIfNeeded(); | 1187 RunNextOperationIfNeeded(); |
| 1193 } | 1188 } |
| 1194 | 1189 |
| 1195 void SimpleEntryImpl::ReadOperationComplete( | 1190 void SimpleEntryImpl::ReadOperationComplete( |
| 1196 int stream_index, | 1191 int stream_index, |
| 1197 int offset, | 1192 int offset, |
| 1198 const CompletionCallback& completion_callback, | 1193 const CompletionCallback& completion_callback, |
| 1199 scoped_ptr<uint32_t> read_crc32, | 1194 std::unique_ptr<uint32_t> read_crc32, |
| 1200 scoped_ptr<SimpleEntryStat> entry_stat, | 1195 std::unique_ptr<SimpleEntryStat> entry_stat, |
| 1201 scoped_ptr<int> result) { | 1196 std::unique_ptr<int> result) { |
| 1202 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1197 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1203 DCHECK(synchronous_entry_); | 1198 DCHECK(synchronous_entry_); |
| 1204 DCHECK_EQ(STATE_IO_PENDING, state_); | 1199 DCHECK_EQ(STATE_IO_PENDING, state_); |
| 1205 DCHECK(read_crc32); | 1200 DCHECK(read_crc32); |
| 1206 DCHECK(result); | 1201 DCHECK(result); |
| 1207 | 1202 |
| 1208 if (*result > 0 && | 1203 if (*result > 0 && |
| 1209 crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_AT_ALL) { | 1204 crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_AT_ALL) { |
| 1210 crc_check_state_[stream_index] = CRC_CHECK_NEVER_READ_TO_END; | 1205 crc_check_state_[stream_index] = CRC_CHECK_NEVER_READ_TO_END; |
| 1211 } | 1206 } |
| 1212 | 1207 |
| 1213 if (*result > 0 && crc32s_end_offset_[stream_index] == offset) { | 1208 if (*result > 0 && crc32s_end_offset_[stream_index] == offset) { |
| 1214 uint32_t current_crc = | 1209 uint32_t current_crc = |
| 1215 offset == 0 ? crc32(0, Z_NULL, 0) : crc32s_[stream_index]; | 1210 offset == 0 ? crc32(0, Z_NULL, 0) : crc32s_[stream_index]; |
| 1216 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result); | 1211 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result); |
| 1217 crc32s_end_offset_[stream_index] += *result; | 1212 crc32s_end_offset_[stream_index] += *result; |
| 1218 if (!have_written_[stream_index] && | 1213 if (!have_written_[stream_index] && |
| 1219 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) { | 1214 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) { |
| 1220 // We have just read a file from start to finish, and so we have | 1215 // We have just read a file from start to finish, and so we have |
| 1221 // computed a crc of the entire file. We can check it now. If a cache | 1216 // computed a crc of the entire file. We can check it now. If a cache |
| 1222 // entry has a single reader, the normal pattern is to read from start | 1217 // entry has a single reader, the normal pattern is to read from start |
| 1223 // to finish. | 1218 // to finish. |
| 1224 | 1219 |
| 1225 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN); | 1220 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN); |
| 1226 | 1221 |
| 1227 scoped_ptr<int> new_result(new int()); | 1222 std::unique_ptr<int> new_result(new int()); |
| 1228 Closure task = base::Bind(&SimpleSynchronousEntry::CheckEOFRecord, | 1223 Closure task = base::Bind(&SimpleSynchronousEntry::CheckEOFRecord, |
| 1229 base::Unretained(synchronous_entry_), | 1224 base::Unretained(synchronous_entry_), |
| 1230 stream_index, | 1225 stream_index, |
| 1231 *entry_stat, | 1226 *entry_stat, |
| 1232 crc32s_[stream_index], | 1227 crc32s_[stream_index], |
| 1233 new_result.get()); | 1228 new_result.get()); |
| 1234 Closure reply = base::Bind(&SimpleEntryImpl::ChecksumOperationComplete, | 1229 Closure reply = base::Bind(&SimpleEntryImpl::ChecksumOperationComplete, |
| 1235 this, *result, stream_index, | 1230 this, *result, stream_index, |
| 1236 completion_callback, | 1231 completion_callback, |
| 1237 base::Passed(&new_result)); | 1232 base::Passed(&new_result)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1259 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, | 1254 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, |
| 1260 CreateNetLogReadWriteCompleteCallback(*result)); | 1255 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1261 } | 1256 } |
| 1262 | 1257 |
| 1263 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1258 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1264 } | 1259 } |
| 1265 | 1260 |
| 1266 void SimpleEntryImpl::WriteOperationComplete( | 1261 void SimpleEntryImpl::WriteOperationComplete( |
| 1267 int stream_index, | 1262 int stream_index, |
| 1268 const CompletionCallback& completion_callback, | 1263 const CompletionCallback& completion_callback, |
| 1269 scoped_ptr<SimpleEntryStat> entry_stat, | 1264 std::unique_ptr<SimpleEntryStat> entry_stat, |
| 1270 scoped_ptr<int> result) { | 1265 std::unique_ptr<int> result) { |
| 1271 if (*result >= 0) | 1266 if (*result >= 0) |
| 1272 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); | 1267 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); |
| 1273 else | 1268 else |
| 1274 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); | 1269 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); |
| 1275 if (net_log_.IsCapturing()) { | 1270 if (net_log_.IsCapturing()) { |
| 1276 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, | 1271 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, |
| 1277 CreateNetLogReadWriteCompleteCallback(*result)); | 1272 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1278 } | 1273 } |
| 1279 | 1274 |
| 1280 if (*result < 0) { | 1275 if (*result < 0) { |
| 1281 crc32s_end_offset_[stream_index] = 0; | 1276 crc32s_end_offset_[stream_index] = 0; |
| 1282 } | 1277 } |
| 1283 | 1278 |
| 1284 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1279 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1285 } | 1280 } |
| 1286 | 1281 |
| 1287 void SimpleEntryImpl::ReadSparseOperationComplete( | 1282 void SimpleEntryImpl::ReadSparseOperationComplete( |
| 1288 const CompletionCallback& completion_callback, | 1283 const CompletionCallback& completion_callback, |
| 1289 scoped_ptr<base::Time> last_used, | 1284 std::unique_ptr<base::Time> last_used, |
| 1290 scoped_ptr<int> result) { | 1285 std::unique_ptr<int> result) { |
| 1291 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1286 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1292 DCHECK(synchronous_entry_); | 1287 DCHECK(synchronous_entry_); |
| 1293 DCHECK(result); | 1288 DCHECK(result); |
| 1294 | 1289 |
| 1295 if (net_log_.IsCapturing()) { | 1290 if (net_log_.IsCapturing()) { |
| 1296 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_END, | 1291 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_END, |
| 1297 CreateNetLogReadWriteCompleteCallback(*result)); | 1292 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1298 } | 1293 } |
| 1299 | 1294 |
| 1300 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_, | 1295 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_, |
| 1301 sparse_data_size_); | 1296 sparse_data_size_); |
| 1302 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); | 1297 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); |
| 1303 } | 1298 } |
| 1304 | 1299 |
| 1305 void SimpleEntryImpl::WriteSparseOperationComplete( | 1300 void SimpleEntryImpl::WriteSparseOperationComplete( |
| 1306 const CompletionCallback& completion_callback, | 1301 const CompletionCallback& completion_callback, |
| 1307 scoped_ptr<SimpleEntryStat> entry_stat, | 1302 std::unique_ptr<SimpleEntryStat> entry_stat, |
| 1308 scoped_ptr<int> result) { | 1303 std::unique_ptr<int> result) { |
| 1309 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1304 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1310 DCHECK(synchronous_entry_); | 1305 DCHECK(synchronous_entry_); |
| 1311 DCHECK(result); | 1306 DCHECK(result); |
| 1312 | 1307 |
| 1313 if (net_log_.IsCapturing()) { | 1308 if (net_log_.IsCapturing()) { |
| 1314 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_END, | 1309 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_END, |
| 1315 CreateNetLogReadWriteCompleteCallback(*result)); | 1310 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1316 } | 1311 } |
| 1317 | 1312 |
| 1318 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1313 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1319 } | 1314 } |
| 1320 | 1315 |
| 1321 void SimpleEntryImpl::GetAvailableRangeOperationComplete( | 1316 void SimpleEntryImpl::GetAvailableRangeOperationComplete( |
| 1322 const CompletionCallback& completion_callback, | 1317 const CompletionCallback& completion_callback, |
| 1323 scoped_ptr<int> result) { | 1318 std::unique_ptr<int> result) { |
| 1324 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1319 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1325 DCHECK(synchronous_entry_); | 1320 DCHECK(synchronous_entry_); |
| 1326 DCHECK(result); | 1321 DCHECK(result); |
| 1327 | 1322 |
| 1328 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, | 1323 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, |
| 1329 sparse_data_size_); | 1324 sparse_data_size_); |
| 1330 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); | 1325 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); |
| 1331 } | 1326 } |
| 1332 | 1327 |
| 1333 void SimpleEntryImpl::DoomOperationComplete( | 1328 void SimpleEntryImpl::DoomOperationComplete( |
| 1334 const CompletionCallback& callback, | 1329 const CompletionCallback& callback, |
| 1335 State state_to_restore, | 1330 State state_to_restore, |
| 1336 int result) { | 1331 int result) { |
| 1337 state_ = state_to_restore; | 1332 state_ = state_to_restore; |
| 1338 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_END); | 1333 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_END); |
| 1339 PostClientCallback(callback, result); | 1334 PostClientCallback(callback, result); |
| 1340 RunNextOperationIfNeeded(); | 1335 RunNextOperationIfNeeded(); |
| 1341 if (backend_) | 1336 if (backend_) |
| 1342 backend_->OnDoomComplete(entry_hash_); | 1337 backend_->OnDoomComplete(entry_hash_); |
| 1343 } | 1338 } |
| 1344 | 1339 |
| 1345 void SimpleEntryImpl::ChecksumOperationComplete( | 1340 void SimpleEntryImpl::ChecksumOperationComplete( |
| 1346 int orig_result, | 1341 int orig_result, |
| 1347 int stream_index, | 1342 int stream_index, |
| 1348 const CompletionCallback& completion_callback, | 1343 const CompletionCallback& completion_callback, |
| 1349 scoped_ptr<int> result) { | 1344 std::unique_ptr<int> result) { |
| 1350 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1345 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1351 DCHECK(synchronous_entry_); | 1346 DCHECK(synchronous_entry_); |
| 1352 DCHECK_EQ(STATE_IO_PENDING, state_); | 1347 DCHECK_EQ(STATE_IO_PENDING, state_); |
| 1353 DCHECK(result); | 1348 DCHECK(result); |
| 1354 | 1349 |
| 1355 if (net_log_.IsCapturing()) { | 1350 if (net_log_.IsCapturing()) { |
| 1356 net_log_.AddEventWithNetErrorCode( | 1351 net_log_.AddEventWithNetErrorCode( |
| 1357 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_END, | 1352 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_END, |
| 1358 *result); | 1353 *result); |
| 1359 } | 1354 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 } | 1552 } |
| 1558 crc32s_end_offset_[stream_index] = offset + length; | 1553 crc32s_end_offset_[stream_index] = offset + length; |
| 1559 } else if (offset < crc32s_end_offset_[stream_index]) { | 1554 } else if (offset < crc32s_end_offset_[stream_index]) { |
| 1560 // If a range for which the crc32 was already computed is rewritten, the | 1555 // If a range for which the crc32 was already computed is rewritten, the |
| 1561 // computation of the crc32 need to start from 0 again. | 1556 // computation of the crc32 need to start from 0 again. |
| 1562 crc32s_end_offset_[stream_index] = 0; | 1557 crc32s_end_offset_[stream_index] = 0; |
| 1563 } | 1558 } |
| 1564 } | 1559 } |
| 1565 | 1560 |
| 1566 } // namespace disk_cache | 1561 } // namespace disk_cache |
| OLD | NEW |