| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 ~ScopedOperationRunner() { | 156 ~ScopedOperationRunner() { |
| 157 entry_->RunNextOperationIfNeeded(); | 157 entry_->RunNextOperationIfNeeded(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 private: | 160 private: |
| 161 SimpleEntryImpl* const entry_; | 161 SimpleEntryImpl* const entry_; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 SimpleEntryImpl::ActiveEntryProxy::~ActiveEntryProxy() {} |
| 165 |
| 164 SimpleEntryImpl::SimpleEntryImpl(net::CacheType cache_type, | 166 SimpleEntryImpl::SimpleEntryImpl(net::CacheType cache_type, |
| 165 const FilePath& path, | 167 const FilePath& path, |
| 166 const uint64 entry_hash, | 168 const uint64 entry_hash, |
| 167 OperationsMode operations_mode, | 169 OperationsMode operations_mode, |
| 168 SimpleBackendImpl* backend, | 170 SimpleBackendImpl* backend, |
| 169 net::NetLog* net_log) | 171 net::NetLog* net_log) |
| 170 : backend_(backend->AsWeakPtr()), | 172 : backend_(backend->AsWeakPtr()), |
| 171 cache_type_(cache_type), | 173 cache_type_(cache_type), |
| 172 worker_pool_(backend->worker_pool()), | 174 worker_pool_(backend->worker_pool()), |
| 173 path_(path), | 175 path_(path), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 189 arrays_should_be_same_size); | 191 arrays_should_be_same_size); |
| 190 COMPILE_ASSERT(arraysize(data_size_) == arraysize(have_written_), | 192 COMPILE_ASSERT(arraysize(data_size_) == arraysize(have_written_), |
| 191 arrays_should_be_same_size); | 193 arrays_should_be_same_size); |
| 192 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc_check_state_), | 194 COMPILE_ASSERT(arraysize(data_size_) == arraysize(crc_check_state_), |
| 193 arrays_should_be_same_size); | 195 arrays_should_be_same_size); |
| 194 MakeUninitialized(); | 196 MakeUninitialized(); |
| 195 net_log_.BeginEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY, | 197 net_log_.BeginEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY, |
| 196 CreateNetLogSimpleEntryConstructionCallback(this)); | 198 CreateNetLogSimpleEntryConstructionCallback(this)); |
| 197 } | 199 } |
| 198 | 200 |
| 201 void SimpleEntryImpl::SetActiveEntryProxy( |
| 202 scoped_ptr<ActiveEntryProxy> active_entry_proxy) { |
| 203 DCHECK(!active_entry_proxy_); |
| 204 active_entry_proxy_.reset(active_entry_proxy.release()); |
| 205 } |
| 206 |
| 199 int SimpleEntryImpl::OpenEntry(Entry** out_entry, | 207 int SimpleEntryImpl::OpenEntry(Entry** out_entry, |
| 200 const CompletionCallback& callback) { | 208 const CompletionCallback& callback) { |
| 201 DCHECK(backend_.get()); | 209 DCHECK(backend_.get()); |
| 202 | 210 |
| 203 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_CALL); | 211 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_CALL); |
| 204 | 212 |
| 205 bool have_index = backend_->index()->initialized(); | 213 bool have_index = backend_->index()->initialized(); |
| 206 // This enumeration is used in histograms, add entries only at end. | 214 // This enumeration is used in histograms, add entries only at end. |
| 207 enum OpenEntryIndexEnum { | 215 enum OpenEntryIndexEnum { |
| 208 INDEX_NOEXIST = 0, | 216 INDEX_NOEXIST = 0, |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 // entry, so there's no need to coordinate which object is performing sparse | 527 // entry, so there's no need to coordinate which object is performing sparse |
| 520 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. | 528 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. |
| 521 return net::OK; | 529 return net::OK; |
| 522 } | 530 } |
| 523 | 531 |
| 524 SimpleEntryImpl::~SimpleEntryImpl() { | 532 SimpleEntryImpl::~SimpleEntryImpl() { |
| 525 DCHECK(io_thread_checker_.CalledOnValidThread()); | 533 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 526 DCHECK_EQ(0U, pending_operations_.size()); | 534 DCHECK_EQ(0U, pending_operations_.size()); |
| 527 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); | 535 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); |
| 528 DCHECK(!synchronous_entry_); | 536 DCHECK(!synchronous_entry_); |
| 529 RemoveSelfFromBackend(); | |
| 530 net_log_.EndEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY); | 537 net_log_.EndEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY); |
| 531 } | 538 } |
| 532 | 539 |
| 533 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback, | 540 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback, |
| 534 int result) { | 541 int result) { |
| 535 if (callback.is_null()) | 542 if (callback.is_null()) |
| 536 return; | 543 return; |
| 537 // Note that the callback is posted rather than directly invoked to avoid | 544 // Note that the callback is posted rather than directly invoked to avoid |
| 538 // reentrancy issues. | 545 // reentrancy issues. |
| 539 base::ThreadTaskRunnerHandle::Get()->PostTask( | 546 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 561 // If the backend no longer exists, the callback won't be invoked, and so we | 568 // If the backend no longer exists, the callback won't be invoked, and so we |
| 562 // must close ourselves to avoid leaking. As well, there's no guarantee the | 569 // must close ourselves to avoid leaking. As well, there's no guarantee the |
| 563 // client-provided pointer (|out_entry|) hasn't been freed, and no point | 570 // client-provided pointer (|out_entry|) hasn't been freed, and no point |
| 564 // dereferencing it, either. | 571 // dereferencing it, either. |
| 565 Close(); | 572 Close(); |
| 566 return; | 573 return; |
| 567 } | 574 } |
| 568 *out_entry = this; | 575 *out_entry = this; |
| 569 } | 576 } |
| 570 | 577 |
| 571 void SimpleEntryImpl::RemoveSelfFromBackend() { | |
| 572 if (!backend_.get()) | |
| 573 return; | |
| 574 backend_->OnDeactivated(this); | |
| 575 } | |
| 576 | |
| 577 void SimpleEntryImpl::MarkAsDoomed() { | 578 void SimpleEntryImpl::MarkAsDoomed() { |
| 578 doomed_ = true; | 579 doomed_ = true; |
| 579 if (!backend_.get()) | 580 if (!backend_.get()) |
| 580 return; | 581 return; |
| 581 backend_->index()->Remove(entry_hash_); | 582 backend_->index()->Remove(entry_hash_); |
| 582 RemoveSelfFromBackend(); | 583 active_entry_proxy_.reset(); |
| 583 } | 584 } |
| 584 | 585 |
| 585 void SimpleEntryImpl::RunNextOperationIfNeeded() { | 586 void SimpleEntryImpl::RunNextOperationIfNeeded() { |
| 586 DCHECK(io_thread_checker_.CalledOnValidThread()); | 587 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 587 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, | 588 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, |
| 588 "EntryOperationsPending", cache_type_, | 589 "EntryOperationsPending", cache_type_, |
| 589 pending_operations_.size(), 0, 100, 20); | 590 pending_operations_.size(), 0, 100, 20); |
| 590 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) { | 591 if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) { |
| 591 scoped_ptr<SimpleEntryOperation> operation( | 592 scoped_ptr<SimpleEntryOperation> operation( |
| 592 new SimpleEntryOperation(pending_operations_.front())); | 593 new SimpleEntryOperation(pending_operations_.front())); |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 } | 1523 } |
| 1523 crc32s_end_offset_[stream_index] = offset + length; | 1524 crc32s_end_offset_[stream_index] = offset + length; |
| 1524 } else if (offset < crc32s_end_offset_[stream_index]) { | 1525 } else if (offset < crc32s_end_offset_[stream_index]) { |
| 1525 // If a range for which the crc32 was already computed is rewritten, the | 1526 // If a range for which the crc32 was already computed is rewritten, the |
| 1526 // computation of the crc32 need to start from 0 again. | 1527 // computation of the crc32 need to start from 0 again. |
| 1527 crc32s_end_offset_[stream_index] = 0; | 1528 crc32s_end_offset_[stream_index] = 0; |
| 1528 } | 1529 } |
| 1529 } | 1530 } |
| 1530 | 1531 |
| 1531 } // namespace disk_cache | 1532 } // namespace disk_cache |
| OLD | NEW |