Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: net/disk_cache/simple/simple_entry_impl.cc

Issue 1815363002: Add RetainedRef uses where needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cert/nss_cert_database.cc ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 } else { 782 } else {
783 crc32s_to_write->push_back(CRCRecord(i, false, 0)); 783 crc32s_to_write->push_back(CRCRecord(i, false, 0));
784 } 784 }
785 } 785 }
786 } 786 }
787 } else { 787 } else {
788 DCHECK(STATE_UNINITIALIZED == state_ || STATE_FAILURE == state_); 788 DCHECK(STATE_UNINITIALIZED == state_ || STATE_FAILURE == state_);
789 } 789 }
790 790
791 if (synchronous_entry_) { 791 if (synchronous_entry_) {
792 Closure task = 792 Closure task = base::Bind(
793 base::Bind(&SimpleSynchronousEntry::Close, 793 &SimpleSynchronousEntry::Close, base::Unretained(synchronous_entry_),
794 base::Unretained(synchronous_entry_), 794 SimpleEntryStat(last_used_, last_modified_, data_size_,
795 SimpleEntryStat(last_used_, last_modified_, data_size_, 795 sparse_data_size_),
796 sparse_data_size_), 796 base::Passed(&crc32s_to_write), base::RetainedRef(stream_0_data_));
797 base::Passed(&crc32s_to_write),
798 stream_0_data_);
799 Closure reply = base::Bind(&SimpleEntryImpl::CloseOperationComplete, this); 797 Closure reply = base::Bind(&SimpleEntryImpl::CloseOperationComplete, this);
800 synchronous_entry_ = NULL; 798 synchronous_entry_ = NULL;
801 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 799 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
802 800
803 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 801 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
804 if (!have_written_[i]) { 802 if (!have_written_[i]) {
805 SIMPLE_CACHE_UMA(ENUMERATION, 803 SIMPLE_CACHE_UMA(ENUMERATION,
806 "CheckCRCResult", cache_type_, 804 "CheckCRCResult", cache_type_,
807 crc_check_state_[i], CRC_CHECK_MAX); 805 crc_check_state_[i], CRC_CHECK_MAX);
808 } 806 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 state_ = STATE_IO_PENDING; 867 state_ = STATE_IO_PENDING;
870 if (!doomed_ && backend_.get()) 868 if (!doomed_ && backend_.get())
871 backend_->index()->UseIfExists(entry_hash_); 869 backend_->index()->UseIfExists(entry_hash_);
872 870
873 scoped_ptr<uint32_t> read_crc32(new uint32_t()); 871 scoped_ptr<uint32_t> read_crc32(new uint32_t());
874 scoped_ptr<int> result(new int()); 872 scoped_ptr<int> result(new int());
875 scoped_ptr<SimpleEntryStat> entry_stat( 873 scoped_ptr<SimpleEntryStat> entry_stat(
876 new SimpleEntryStat(last_used_, last_modified_, data_size_, 874 new SimpleEntryStat(last_used_, last_modified_, data_size_,
877 sparse_data_size_)); 875 sparse_data_size_));
878 Closure task = base::Bind( 876 Closure task = base::Bind(
879 &SimpleSynchronousEntry::ReadData, 877 &SimpleSynchronousEntry::ReadData, base::Unretained(synchronous_entry_),
880 base::Unretained(synchronous_entry_),
881 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len), 878 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len),
882 make_scoped_refptr(buf), 879 base::RetainedRef(buf), read_crc32.get(), entry_stat.get(), result.get());
883 read_crc32.get(),
884 entry_stat.get(),
885 result.get());
886 Closure reply = base::Bind(&SimpleEntryImpl::ReadOperationComplete, 880 Closure reply = base::Bind(&SimpleEntryImpl::ReadOperationComplete,
887 this, 881 this,
888 stream_index, 882 stream_index,
889 offset, 883 offset,
890 callback, 884 callback,
891 base::Passed(&read_crc32), 885 base::Passed(&read_crc32),
892 base::Passed(&entry_stat), 886 base::Passed(&entry_stat),
893 base::Passed(&result)); 887 base::Passed(&result));
894 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 888 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
895 } 889 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // |last_modified_| yet, we make this approximation. 964 // |last_modified_| yet, we make this approximation.
971 last_used_ = last_modified_ = base::Time::Now(); 965 last_used_ = last_modified_ = base::Time::Now();
972 966
973 have_written_[stream_index] = true; 967 have_written_[stream_index] = true;
974 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF 968 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF
975 // record will have to be rewritten. 969 // record will have to be rewritten.
976 if (stream_index == 1) 970 if (stream_index == 1)
977 have_written_[0] = true; 971 have_written_[0] = true;
978 972
979 scoped_ptr<int> result(new int()); 973 scoped_ptr<int> result(new int());
980 Closure task = base::Bind(&SimpleSynchronousEntry::WriteData, 974 Closure task = base::Bind(
981 base::Unretained(synchronous_entry_), 975 &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_),
982 SimpleSynchronousEntry::EntryOperationData( 976 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len,
983 stream_index, offset, buf_len, truncate, 977 truncate, doomed_),
984 doomed_), 978 base::RetainedRef(buf), entry_stat.get(), result.get());
985 make_scoped_refptr(buf),
986 entry_stat.get(),
987 result.get());
988 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, 979 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete,
989 this, 980 this,
990 stream_index, 981 stream_index,
991 callback, 982 callback,
992 base::Passed(&entry_stat), 983 base::Passed(&entry_stat),
993 base::Passed(&result)); 984 base::Passed(&result));
994 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 985 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
995 } 986 }
996 987
997 void SimpleEntryImpl::ReadSparseDataInternal( 988 void SimpleEntryImpl::ReadSparseDataInternal(
998 int64_t sparse_offset, 989 int64_t sparse_offset,
999 net::IOBuffer* buf, 990 net::IOBuffer* buf,
1000 int buf_len, 991 int buf_len,
1001 const CompletionCallback& callback) { 992 const CompletionCallback& callback) {
1002 DCHECK(io_thread_checker_.CalledOnValidThread()); 993 DCHECK(io_thread_checker_.CalledOnValidThread());
1003 ScopedOperationRunner operation_runner(this); 994 ScopedOperationRunner operation_runner(this);
1004 995
1005 if (net_log_.IsCapturing()) { 996 if (net_log_.IsCapturing()) {
1006 net_log_.AddEvent( 997 net_log_.AddEvent(
1007 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN, 998 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN,
1008 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); 999 CreateNetLogSparseOperationCallback(sparse_offset, buf_len));
1009 } 1000 }
1010 1001
1011 DCHECK_EQ(STATE_READY, state_); 1002 DCHECK_EQ(STATE_READY, state_);
1012 state_ = STATE_IO_PENDING; 1003 state_ = STATE_IO_PENDING;
1013 1004
1014 scoped_ptr<int> result(new int()); 1005 scoped_ptr<int> result(new int());
1015 scoped_ptr<base::Time> last_used(new base::Time()); 1006 scoped_ptr<base::Time> last_used(new base::Time());
1016 Closure task = base::Bind(&SimpleSynchronousEntry::ReadSparseData, 1007 Closure task = base::Bind(
1017 base::Unretained(synchronous_entry_), 1008 &SimpleSynchronousEntry::ReadSparseData,
1018 SimpleSynchronousEntry::EntryOperationData( 1009 base::Unretained(synchronous_entry_),
1019 sparse_offset, buf_len), 1010 SimpleSynchronousEntry::EntryOperationData(sparse_offset, buf_len),
1020 make_scoped_refptr(buf), 1011 base::RetainedRef(buf), last_used.get(), result.get());
1021 last_used.get(),
1022 result.get());
1023 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete, 1012 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete,
1024 this, 1013 this,
1025 callback, 1014 callback,
1026 base::Passed(&last_used), 1015 base::Passed(&last_used),
1027 base::Passed(&result)); 1016 base::Passed(&result));
1028 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 1017 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
1029 } 1018 }
1030 1019
1031 void SimpleEntryImpl::WriteSparseDataInternal( 1020 void SimpleEntryImpl::WriteSparseDataInternal(
1032 int64_t sparse_offset, 1021 int64_t sparse_offset,
(...skipping 18 matching lines...) Expand all
1051 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; 1040 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor;
1052 } 1041 }
1053 1042
1054 scoped_ptr<SimpleEntryStat> entry_stat( 1043 scoped_ptr<SimpleEntryStat> entry_stat(
1055 new SimpleEntryStat(last_used_, last_modified_, data_size_, 1044 new SimpleEntryStat(last_used_, last_modified_, data_size_,
1056 sparse_data_size_)); 1045 sparse_data_size_));
1057 1046
1058 last_used_ = last_modified_ = base::Time::Now(); 1047 last_used_ = last_modified_ = base::Time::Now();
1059 1048
1060 scoped_ptr<int> result(new int()); 1049 scoped_ptr<int> result(new int());
1061 Closure task = base::Bind(&SimpleSynchronousEntry::WriteSparseData, 1050 Closure task = base::Bind(
1062 base::Unretained(synchronous_entry_), 1051 &SimpleSynchronousEntry::WriteSparseData,
1063 SimpleSynchronousEntry::EntryOperationData( 1052 base::Unretained(synchronous_entry_),
1064 sparse_offset, buf_len), 1053 SimpleSynchronousEntry::EntryOperationData(sparse_offset, buf_len),
1065 make_scoped_refptr(buf), 1054 base::RetainedRef(buf), max_sparse_data_size, entry_stat.get(),
1066 max_sparse_data_size, 1055 result.get());
1067 entry_stat.get(),
1068 result.get());
1069 Closure reply = base::Bind(&SimpleEntryImpl::WriteSparseOperationComplete, 1056 Closure reply = base::Bind(&SimpleEntryImpl::WriteSparseOperationComplete,
1070 this, 1057 this,
1071 callback, 1058 callback,
1072 base::Passed(&entry_stat), 1059 base::Passed(&entry_stat),
1073 base::Passed(&result)); 1060 base::Passed(&result));
1074 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 1061 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
1075 } 1062 }
1076 1063
1077 void SimpleEntryImpl::GetAvailableRangeInternal( 1064 void SimpleEntryImpl::GetAvailableRangeInternal(
1078 int64_t sparse_offset, 1065 int64_t sparse_offset,
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 } 1538 }
1552 crc32s_end_offset_[stream_index] = offset + length; 1539 crc32s_end_offset_[stream_index] = offset + length;
1553 } else if (offset < crc32s_end_offset_[stream_index]) { 1540 } else if (offset < crc32s_end_offset_[stream_index]) {
1554 // If a range for which the crc32 was already computed is rewritten, the 1541 // If a range for which the crc32 was already computed is rewritten, the
1555 // computation of the crc32 need to start from 0 again. 1542 // computation of the crc32 need to start from 0 again.
1556 crc32s_end_offset_[stream_index] = 0; 1543 crc32s_end_offset_[stream_index] = 0;
1557 } 1544 }
1558 } 1545 }
1559 1546
1560 } // namespace disk_cache 1547 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/cert/nss_cert_database.cc ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698