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

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

Issue 23486006: Track entries pending Doom in SimpleCache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add TODO Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | no next file » | 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 <vector> 9 #include <vector>
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 net::NetLog* net_log) 154 net::NetLog* net_log)
155 : backend_(backend->AsWeakPtr()), 155 : backend_(backend->AsWeakPtr()),
156 cache_type_(cache_type), 156 cache_type_(cache_type),
157 worker_pool_(backend->worker_pool()), 157 worker_pool_(backend->worker_pool()),
158 path_(path), 158 path_(path),
159 entry_hash_(entry_hash), 159 entry_hash_(entry_hash),
160 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS), 160 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS),
161 last_used_(Time::Now()), 161 last_used_(Time::Now()),
162 last_modified_(last_used_), 162 last_modified_(last_used_),
163 open_count_(0), 163 open_count_(0),
164 doomed_(false),
164 state_(STATE_UNINITIALIZED), 165 state_(STATE_UNINITIALIZED),
165 synchronous_entry_(NULL), 166 synchronous_entry_(NULL),
166 net_log_(net::BoundNetLog::Make( 167 net_log_(net::BoundNetLog::Make(
167 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY)) { 168 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY)) {
168 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_end_offset_), 169 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_end_offset_),
169 arrays_should_be_same_size); 170 arrays_should_be_same_size);
170 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_), 171 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_),
171 arrays_should_be_same_size); 172 arrays_should_be_same_size);
172 COMPILE_ASSERT(arraysize(data_size_) == arraysize(have_written_), 173 COMPILE_ASSERT(arraysize(data_size_) == arraysize(have_written_),
173 arrays_should_be_same_size); 174 arrays_should_be_same_size);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 DCHECK(out_entry); 519 DCHECK(out_entry);
519 ++open_count_; 520 ++open_count_;
520 AddRef(); // Balanced in Close() 521 AddRef(); // Balanced in Close()
521 *out_entry = this; 522 *out_entry = this;
522 } 523 }
523 524
524 void SimpleEntryImpl::RemoveSelfFromBackend() { 525 void SimpleEntryImpl::RemoveSelfFromBackend() {
525 if (!backend_.get()) 526 if (!backend_.get())
526 return; 527 return;
527 backend_->OnDeactivated(this); 528 backend_->OnDeactivated(this);
528 backend_.reset();
529 } 529 }
530 530
531 void SimpleEntryImpl::MarkAsDoomed() { 531 void SimpleEntryImpl::MarkAsDoomed() {
532 if (!backend_.get()) 532 if (!backend_.get())
533 return; 533 return;
534 doomed_ = true;
534 backend_->index()->Remove(entry_hash_); 535 backend_->index()->Remove(entry_hash_);
535 RemoveSelfFromBackend(); 536 RemoveSelfFromBackend();
536 } 537 }
537 538
538 void SimpleEntryImpl::RunNextOperationIfNeeded() { 539 void SimpleEntryImpl::RunNextOperationIfNeeded() {
539 DCHECK(io_thread_checker_.CalledOnValidThread()); 540 DCHECK(io_thread_checker_.CalledOnValidThread());
540 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, 541 SIMPLE_CACHE_UMA(CUSTOM_COUNTS,
541 "EntryOperationsPending", cache_type_, 542 "EntryOperationsPending", cache_type_,
542 pending_operations_.size(), 0, 100, 20); 543 pending_operations_.size(), 0, 100, 20);
543 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) { 544 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 // STATE_IO_PENDING. 775 // STATE_IO_PENDING.
775 if (!callback.is_null()) 776 if (!callback.is_null())
776 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind( 777 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind(
777 callback, 0)); 778 callback, 0));
778 return; 779 return;
779 } 780 }
780 781
781 buf_len = std::min(buf_len, GetDataSize(stream_index) - offset); 782 buf_len = std::min(buf_len, GetDataSize(stream_index) - offset);
782 783
783 state_ = STATE_IO_PENDING; 784 state_ = STATE_IO_PENDING;
784 if (backend_.get()) 785 if (!doomed_ && backend_.get())
785 backend_->index()->UseIfExists(entry_hash_); 786 backend_->index()->UseIfExists(entry_hash_);
786 787
787 scoped_ptr<uint32> read_crc32(new uint32()); 788 scoped_ptr<uint32> read_crc32(new uint32());
788 scoped_ptr<int> result(new int()); 789 scoped_ptr<int> result(new int());
789 scoped_ptr<base::Time> last_used(new base::Time()); 790 scoped_ptr<base::Time> last_used(new base::Time());
790 Closure task = base::Bind( 791 Closure task = base::Bind(
791 &SimpleSynchronousEntry::ReadData, 792 &SimpleSynchronousEntry::ReadData,
792 base::Unretained(synchronous_entry_), 793 base::Unretained(synchronous_entry_),
793 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len), 794 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len),
794 make_scoped_refptr(buf), 795 make_scoped_refptr(buf),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 // callback directly. 835 // callback directly.
835 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind( 836 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind(
836 callback, net::ERR_FAILED)); 837 callback, net::ERR_FAILED));
837 } 838 }
838 // |this| may be destroyed after return here. 839 // |this| may be destroyed after return here.
839 return; 840 return;
840 } 841 }
841 842
842 DCHECK_EQ(STATE_READY, state_); 843 DCHECK_EQ(STATE_READY, state_);
843 state_ = STATE_IO_PENDING; 844 state_ = STATE_IO_PENDING;
844 if (backend_.get()) 845 if (!doomed_ && backend_.get())
845 backend_->index()->UseIfExists(entry_hash_); 846 backend_->index()->UseIfExists(entry_hash_);
846 // It is easy to incrementally compute the CRC from [0 .. |offset + buf_len|) 847 // It is easy to incrementally compute the CRC from [0 .. |offset + buf_len|)
847 // if |offset == 0| or we have already computed the CRC for [0 .. offset). 848 // if |offset == 0| or we have already computed the CRC for [0 .. offset).
848 // We rely on most write operations being sequential, start to end to compute 849 // We rely on most write operations being sequential, start to end to compute
849 // the crc of the data. When we write to an entry and close without having 850 // the crc of the data. When we write to an entry and close without having
850 // done a sequential write, we don't check the CRC on read. 851 // done a sequential write, we don't check the CRC on read.
851 if (offset == 0 || crc32s_end_offset_[stream_index] == offset) { 852 if (offset == 0 || crc32s_end_offset_[stream_index] == offset) {
852 uint32 initial_crc = (offset != 0) ? crc32s_[stream_index] 853 uint32 initial_crc = (offset != 0) ? crc32s_[stream_index]
853 : crc32(0, Z_NULL, 0); 854 : crc32(0, Z_NULL, 0);
854 if (buf_len > 0) { 855 if (buf_len > 0) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, 887 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete,
887 this, 888 this,
888 stream_index, 889 stream_index,
889 callback, 890 callback,
890 base::Passed(&entry_stat), 891 base::Passed(&entry_stat),
891 base::Passed(&result)); 892 base::Passed(&result));
892 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 893 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
893 } 894 }
894 895
895 void SimpleEntryImpl::DoomEntryInternal(const CompletionCallback& callback) { 896 void SimpleEntryImpl::DoomEntryInternal(const CompletionCallback& callback) {
897 if (backend_)
898 backend_->OnDoomStart(entry_hash_);
896 PostTaskAndReplyWithResult( 899 PostTaskAndReplyWithResult(
897 worker_pool_, FROM_HERE, 900 worker_pool_, FROM_HERE,
898 base::Bind(&SimpleSynchronousEntry::DoomEntry, path_, key_, entry_hash_), 901 base::Bind(&SimpleSynchronousEntry::DoomEntry, path_, key_, entry_hash_),
899 base::Bind(&SimpleEntryImpl::DoomOperationComplete, this, callback, 902 base::Bind(&SimpleEntryImpl::DoomOperationComplete, this, callback,
900 state_)); 903 state_));
901 state_ = STATE_IO_PENDING; 904 state_ = STATE_IO_PENDING;
902 } 905 }
903 906
904 void SimpleEntryImpl::CreationOperationComplete( 907 void SimpleEntryImpl::CreationOperationComplete(
905 const CompletionCallback& completion_callback, 908 const CompletionCallback& completion_callback,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); 1069 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE);
1067 if (net_log_.IsLoggingAllEvents()) { 1070 if (net_log_.IsLoggingAllEvents()) {
1068 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, 1071 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END,
1069 CreateNetLogReadWriteCompleteCallback(*result)); 1072 CreateNetLogReadWriteCompleteCallback(*result));
1070 } 1073 }
1071 1074
1072 EntryOperationComplete( 1075 EntryOperationComplete(
1073 stream_index, completion_callback, *entry_stat, result.Pass()); 1076 stream_index, completion_callback, *entry_stat, result.Pass());
1074 } 1077 }
1075 1078
1076 void SimpleEntryImpl::DoomOperationComplete(const CompletionCallback& callback, 1079 void SimpleEntryImpl::DoomOperationComplete(
1077 State state_to_restore, 1080 const CompletionCallback& callback,
1078 int result) { 1081 State state_to_restore,
1082 int result) {
1079 state_ = state_to_restore; 1083 state_ = state_to_restore;
1080 if (!callback.is_null()) 1084 if (!callback.is_null())
1081 callback.Run(result); 1085 callback.Run(result);
1082 RunNextOperationIfNeeded(); 1086 RunNextOperationIfNeeded();
1087 if (backend_)
1088 backend_->OnDoomComplete(entry_hash_);
1083 } 1089 }
1084 1090
1085 void SimpleEntryImpl::ChecksumOperationComplete( 1091 void SimpleEntryImpl::ChecksumOperationComplete(
1086 int orig_result, 1092 int orig_result,
1087 int stream_index, 1093 int stream_index,
1088 const CompletionCallback& completion_callback, 1094 const CompletionCallback& completion_callback,
1089 scoped_ptr<int> result) { 1095 scoped_ptr<int> result) {
1090 DCHECK(io_thread_checker_.CalledOnValidThread()); 1096 DCHECK(io_thread_checker_.CalledOnValidThread());
1091 DCHECK(synchronous_entry_); 1097 DCHECK(synchronous_entry_);
1092 DCHECK_EQ(STATE_IO_PENDING, state_); 1098 DCHECK_EQ(STATE_IO_PENDING, state_);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 const SimpleEntryStat& entry_stat) { 1140 const SimpleEntryStat& entry_stat) {
1135 DCHECK(io_thread_checker_.CalledOnValidThread()); 1141 DCHECK(io_thread_checker_.CalledOnValidThread());
1136 DCHECK(synchronous_entry_); 1142 DCHECK(synchronous_entry_);
1137 DCHECK_EQ(STATE_READY, state_); 1143 DCHECK_EQ(STATE_READY, state_);
1138 1144
1139 last_used_ = entry_stat.last_used; 1145 last_used_ = entry_stat.last_used;
1140 last_modified_ = entry_stat.last_modified; 1146 last_modified_ = entry_stat.last_modified;
1141 for (int i = 0; i < kSimpleEntryFileCount; ++i) { 1147 for (int i = 0; i < kSimpleEntryFileCount; ++i) {
1142 data_size_[i] = entry_stat.data_size[i]; 1148 data_size_[i] = entry_stat.data_size[i];
1143 } 1149 }
1144 if (backend_.get()) 1150 if (!doomed_ && backend_.get())
1145 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage()); 1151 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage());
1146 } 1152 }
1147 1153
1148 int64 SimpleEntryImpl::GetDiskUsage() const { 1154 int64 SimpleEntryImpl::GetDiskUsage() const {
1149 int64 file_size = 0; 1155 int64 file_size = 0;
1150 for (int i = 0; i < kSimpleEntryFileCount; ++i) { 1156 for (int i = 0; i < kSimpleEntryFileCount; ++i) {
1151 file_size += 1157 file_size +=
1152 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]); 1158 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]);
1153 } 1159 }
1154 return file_size; 1160 return file_size;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 type = conflicting ? WRITE_FOLLOWS_CONFLICTING_WRITE 1225 type = conflicting ? WRITE_FOLLOWS_CONFLICTING_WRITE
1220 : WRITE_FOLLOWS_NON_CONFLICTING_WRITE; 1226 : WRITE_FOLLOWS_NON_CONFLICTING_WRITE;
1221 } 1227 }
1222 } 1228 }
1223 SIMPLE_CACHE_UMA(ENUMERATION, 1229 SIMPLE_CACHE_UMA(ENUMERATION,
1224 "WriteDependencyType", cache_type_, 1230 "WriteDependencyType", cache_type_,
1225 type, WRITE_DEPENDENCY_TYPE_MAX); 1231 type, WRITE_DEPENDENCY_TYPE_MAX);
1226 } 1232 }
1227 1233
1228 } // namespace disk_cache 1234 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698