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

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: rebase only 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
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 net::NetLog* net_log) 163 net::NetLog* net_log)
164 : backend_(backend->AsWeakPtr()), 164 : backend_(backend->AsWeakPtr()),
165 cache_type_(cache_type), 165 cache_type_(cache_type),
166 worker_pool_(backend->worker_pool()), 166 worker_pool_(backend->worker_pool()),
167 path_(path), 167 path_(path),
168 entry_hash_(entry_hash), 168 entry_hash_(entry_hash),
169 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS), 169 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS),
170 last_used_(Time::Now()), 170 last_used_(Time::Now()),
171 last_modified_(last_used_), 171 last_modified_(last_used_),
172 open_count_(0), 172 open_count_(0),
173 doomed_(false),
173 state_(STATE_UNINITIALIZED), 174 state_(STATE_UNINITIALIZED),
174 synchronous_entry_(NULL), 175 synchronous_entry_(NULL),
175 net_log_(net::BoundNetLog::Make( 176 net_log_(net::BoundNetLog::Make(
176 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY)) { 177 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY)) {
177 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_end_offset_), 178 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_end_offset_),
178 arrays_should_be_same_size); 179 arrays_should_be_same_size);
179 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_), 180 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc32s_),
180 arrays_should_be_same_size); 181 arrays_should_be_same_size);
181 COMPILE_ASSERT(arraysize(data_size_) == arraysize(have_written_), 182 COMPILE_ASSERT(arraysize(data_size_) == arraysize(have_written_),
182 arrays_should_be_same_size); 183 arrays_should_be_same_size);
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 DCHECK(out_entry); 528 DCHECK(out_entry);
528 ++open_count_; 529 ++open_count_;
529 AddRef(); // Balanced in Close() 530 AddRef(); // Balanced in Close()
530 *out_entry = this; 531 *out_entry = this;
531 } 532 }
532 533
533 void SimpleEntryImpl::RemoveSelfFromBackend() { 534 void SimpleEntryImpl::RemoveSelfFromBackend() {
534 if (!backend_.get()) 535 if (!backend_.get())
535 return; 536 return;
536 backend_->OnDeactivated(this); 537 backend_->OnDeactivated(this);
537 backend_.reset();
538 } 538 }
539 539
540 void SimpleEntryImpl::MarkAsDoomed() { 540 void SimpleEntryImpl::MarkAsDoomed() {
541 if (!backend_.get()) 541 if (!backend_.get())
542 return; 542 return;
543 doomed_ = true;
543 backend_->index()->Remove(entry_hash_); 544 backend_->index()->Remove(entry_hash_);
544 RemoveSelfFromBackend(); 545 RemoveSelfFromBackend();
545 } 546 }
546 547
547 void SimpleEntryImpl::RunNextOperationIfNeeded() { 548 void SimpleEntryImpl::RunNextOperationIfNeeded() {
548 DCHECK(io_thread_checker_.CalledOnValidThread()); 549 DCHECK(io_thread_checker_.CalledOnValidThread());
549 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, 550 SIMPLE_CACHE_UMA(CUSTOM_COUNTS,
550 "EntryOperationsPending", cache_type_, 551 "EntryOperationsPending", cache_type_,
551 pending_operations_.size(), 0, 100, 20); 552 pending_operations_.size(), 0, 100, 20);
552 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) { 553 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 // STATE_IO_PENDING. 784 // STATE_IO_PENDING.
784 if (!callback.is_null()) 785 if (!callback.is_null())
785 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind( 786 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind(
786 callback, 0)); 787 callback, 0));
787 return; 788 return;
788 } 789 }
789 790
790 buf_len = std::min(buf_len, GetDataSize(stream_index) - offset); 791 buf_len = std::min(buf_len, GetDataSize(stream_index) - offset);
791 792
792 state_ = STATE_IO_PENDING; 793 state_ = STATE_IO_PENDING;
793 if (backend_.get()) 794 if (!doomed_ && backend_.get())
794 backend_->index()->UseIfExists(entry_hash_); 795 backend_->index()->UseIfExists(entry_hash_);
795 796
796 scoped_ptr<uint32> read_crc32(new uint32()); 797 scoped_ptr<uint32> read_crc32(new uint32());
797 scoped_ptr<int> result(new int()); 798 scoped_ptr<int> result(new int());
798 scoped_ptr<base::Time> last_used(new base::Time()); 799 scoped_ptr<base::Time> last_used(new base::Time());
799 Closure task = base::Bind( 800 Closure task = base::Bind(
800 &SimpleSynchronousEntry::ReadData, 801 &SimpleSynchronousEntry::ReadData,
801 base::Unretained(synchronous_entry_), 802 base::Unretained(synchronous_entry_),
802 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len), 803 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len),
803 make_scoped_refptr(buf), 804 make_scoped_refptr(buf),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 // callback directly. 844 // callback directly.
844 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind( 845 MessageLoopProxy::current()->PostTask(FROM_HERE, base::Bind(
845 callback, net::ERR_FAILED)); 846 callback, net::ERR_FAILED));
846 } 847 }
847 // |this| may be destroyed after return here. 848 // |this| may be destroyed after return here.
848 return; 849 return;
849 } 850 }
850 851
851 DCHECK_EQ(STATE_READY, state_); 852 DCHECK_EQ(STATE_READY, state_);
852 state_ = STATE_IO_PENDING; 853 state_ = STATE_IO_PENDING;
853 if (backend_.get()) 854 if (!doomed_ && backend_.get())
854 backend_->index()->UseIfExists(entry_hash_); 855 backend_->index()->UseIfExists(entry_hash_);
855 // It is easy to incrementally compute the CRC from [0 .. |offset + buf_len|) 856 // It is easy to incrementally compute the CRC from [0 .. |offset + buf_len|)
856 // if |offset == 0| or we have already computed the CRC for [0 .. offset). 857 // if |offset == 0| or we have already computed the CRC for [0 .. offset).
857 // We rely on most write operations being sequential, start to end to compute 858 // We rely on most write operations being sequential, start to end to compute
858 // the crc of the data. When we write to an entry and close without having 859 // the crc of the data. When we write to an entry and close without having
859 // done a sequential write, we don't check the CRC on read. 860 // done a sequential write, we don't check the CRC on read.
860 if (offset == 0 || crc32s_end_offset_[stream_index] == offset) { 861 if (offset == 0 || crc32s_end_offset_[stream_index] == offset) {
861 uint32 initial_crc = (offset != 0) ? crc32s_[stream_index] 862 uint32 initial_crc = (offset != 0) ? crc32s_[stream_index]
862 : crc32(0, Z_NULL, 0); 863 : crc32(0, Z_NULL, 0);
863 if (buf_len > 0) { 864 if (buf_len > 0) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, 896 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete,
896 this, 897 this,
897 stream_index, 898 stream_index,
898 callback, 899 callback,
899 base::Passed(&entry_stat), 900 base::Passed(&entry_stat),
900 base::Passed(&result)); 901 base::Passed(&result));
901 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 902 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
902 } 903 }
903 904
904 void SimpleEntryImpl::DoomEntryInternal(const CompletionCallback& callback) { 905 void SimpleEntryImpl::DoomEntryInternal(const CompletionCallback& callback) {
906 if (backend_)
907 backend_->OnDoomStart(entry_hash_);
905 PostTaskAndReplyWithResult( 908 PostTaskAndReplyWithResult(
906 worker_pool_, FROM_HERE, 909 worker_pool_, FROM_HERE,
907 base::Bind(&SimpleSynchronousEntry::DoomEntry, path_, key_, entry_hash_), 910 base::Bind(&SimpleSynchronousEntry::DoomEntry, path_, key_, entry_hash_),
908 base::Bind(&SimpleEntryImpl::DoomOperationComplete, this, callback, 911 base::Bind(&SimpleEntryImpl::DoomOperationComplete, this, callback,
909 state_)); 912 state_));
910 state_ = STATE_IO_PENDING; 913 state_ = STATE_IO_PENDING;
911 } 914 }
912 915
913 void SimpleEntryImpl::CreationOperationComplete( 916 void SimpleEntryImpl::CreationOperationComplete(
914 const CompletionCallback& completion_callback, 917 const CompletionCallback& completion_callback,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); 1078 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE);
1076 if (net_log_.IsLoggingAllEvents()) { 1079 if (net_log_.IsLoggingAllEvents()) {
1077 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, 1080 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END,
1078 CreateNetLogReadWriteCompleteCallback(*result)); 1081 CreateNetLogReadWriteCompleteCallback(*result));
1079 } 1082 }
1080 1083
1081 EntryOperationComplete( 1084 EntryOperationComplete(
1082 stream_index, completion_callback, *entry_stat, result.Pass()); 1085 stream_index, completion_callback, *entry_stat, result.Pass());
1083 } 1086 }
1084 1087
1085 void SimpleEntryImpl::DoomOperationComplete(const CompletionCallback& callback, 1088 void SimpleEntryImpl::DoomOperationComplete(
1086 State state_to_restore, 1089 const CompletionCallback& callback,
1087 int result) { 1090 State state_to_restore,
1091 int result) {
1088 state_ = state_to_restore; 1092 state_ = state_to_restore;
1089 if (!callback.is_null()) 1093 if (!callback.is_null())
1090 callback.Run(result); 1094 callback.Run(result);
1091 RunNextOperationIfNeeded(); 1095 RunNextOperationIfNeeded();
1096 if (backend_)
1097 backend_->OnDoomComplete(entry_hash_);
1092 } 1098 }
1093 1099
1094 void SimpleEntryImpl::ChecksumOperationComplete( 1100 void SimpleEntryImpl::ChecksumOperationComplete(
1095 int orig_result, 1101 int orig_result,
1096 int stream_index, 1102 int stream_index,
1097 const CompletionCallback& completion_callback, 1103 const CompletionCallback& completion_callback,
1098 scoped_ptr<int> result) { 1104 scoped_ptr<int> result) {
1099 DCHECK(io_thread_checker_.CalledOnValidThread()); 1105 DCHECK(io_thread_checker_.CalledOnValidThread());
1100 DCHECK(synchronous_entry_); 1106 DCHECK(synchronous_entry_);
1101 DCHECK_EQ(STATE_IO_PENDING, state_); 1107 DCHECK_EQ(STATE_IO_PENDING, state_);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 const SimpleEntryStat& entry_stat) { 1149 const SimpleEntryStat& entry_stat) {
1144 DCHECK(io_thread_checker_.CalledOnValidThread()); 1150 DCHECK(io_thread_checker_.CalledOnValidThread());
1145 DCHECK(synchronous_entry_); 1151 DCHECK(synchronous_entry_);
1146 DCHECK_EQ(STATE_READY, state_); 1152 DCHECK_EQ(STATE_READY, state_);
1147 1153
1148 last_used_ = entry_stat.last_used; 1154 last_used_ = entry_stat.last_used;
1149 last_modified_ = entry_stat.last_modified; 1155 last_modified_ = entry_stat.last_modified;
1150 for (int i = 0; i < kSimpleEntryFileCount; ++i) { 1156 for (int i = 0; i < kSimpleEntryFileCount; ++i) {
1151 data_size_[i] = entry_stat.data_size[i]; 1157 data_size_[i] = entry_stat.data_size[i];
1152 } 1158 }
1153 if (backend_.get()) 1159 if (!doomed_ && backend_.get())
1154 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage()); 1160 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage());
1155 } 1161 }
1156 1162
1157 int64 SimpleEntryImpl::GetDiskUsage() const { 1163 int64 SimpleEntryImpl::GetDiskUsage() const {
1158 int64 file_size = 0; 1164 int64 file_size = 0;
1159 for (int i = 0; i < kSimpleEntryFileCount; ++i) { 1165 for (int i = 0; i < kSimpleEntryFileCount; ++i) {
1160 file_size += 1166 file_size +=
1161 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]); 1167 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]);
1162 } 1168 }
1163 return file_size; 1169 return file_size;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 type = conflicting ? WRITE_FOLLOWS_CONFLICTING_WRITE 1234 type = conflicting ? WRITE_FOLLOWS_CONFLICTING_WRITE
1229 : WRITE_FOLLOWS_NON_CONFLICTING_WRITE; 1235 : WRITE_FOLLOWS_NON_CONFLICTING_WRITE;
1230 } 1236 }
1231 } 1237 }
1232 SIMPLE_CACHE_UMA(ENUMERATION, 1238 SIMPLE_CACHE_UMA(ENUMERATION,
1233 "WriteDependencyType", cache_type_, 1239 "WriteDependencyType", cache_type_,
1234 type, WRITE_DEPENDENCY_TYPE_MAX); 1240 type, WRITE_DEPENDENCY_TYPE_MAX);
1235 } 1241 }
1236 1242
1237 } // namespace disk_cache 1243 } // namespace disk_cache
OLDNEW
« net/disk_cache/simple/simple_entry_impl.h ('K') | « 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