Commit 3c173072 authored by Ben Kelly's avatar Ben Kelly Committed by Commit Bot

SimpleCache: Support access from sequences.

Historically the simple disk_cache backend has assumed all accesses
occurred on the browser IO thread.  In order to support running
cache_storage on a separate sequence this CL removes the IO thread
assumptions from simple disk_cache.

Bug: 960012
Change-Id: Idde0f6049aad403318d32b65a160515ee5d67fa6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1643234Reviewed-by: default avatarMaks Orlovich <morlovich@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665990}
parent e7ba15aa
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/thread_pool/thread_pool.h" #include "base/task/thread_pool/thread_pool.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h"
...@@ -286,7 +286,7 @@ net::Error SimpleBackendImpl::Init(CompletionOnceCallback completion_callback) { ...@@ -286,7 +286,7 @@ net::Error SimpleBackendImpl::Init(CompletionOnceCallback completion_callback) {
base::MakeRefCounted<net::PrioritizedTaskRunner>(worker_pool); base::MakeRefCounted<net::PrioritizedTaskRunner>(worker_pool);
index_ = std::make_unique<SimpleIndex>( index_ = std::make_unique<SimpleIndex>(
base::ThreadTaskRunnerHandle::Get(), cleanup_tracker_.get(), this, base::SequencedTaskRunnerHandle::Get(), cleanup_tracker_.get(), this,
GetCacheType(), GetCacheType(),
std::make_unique<SimpleIndexFile>(cache_runner_, worker_pool.get(), std::make_unique<SimpleIndexFile>(cache_runner_, worker_pool.get(),
GetCacheType(), path_)); GetCacheType(), path_));
......
...@@ -41,15 +41,17 @@ namespace disk_cache { ...@@ -41,15 +41,17 @@ namespace disk_cache {
// SimpleBackendImpl is a new cache backend that stores entries in individual // SimpleBackendImpl is a new cache backend that stores entries in individual
// files. // files.
// See http://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend // See
// http://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend
// //
// The SimpleBackendImpl provides safe iteration; mutating entries during // The SimpleBackendImpl provides safe iteration; mutating entries during
// iteration cannot cause a crash. It is undefined whether entries created or // iteration cannot cause a crash. It is undefined whether entries created or
// destroyed during the iteration will be included in any pre-existing // destroyed during the iteration will be included in any pre-existing
// iterations. // iterations.
// //
// The non-static functions below must be called on the IO thread unless // The non-static functions below must be called on the source creation sequence
// otherwise stated. // unless otherwise stated. Historically the source creation sequence has been
// the IO thread, but the simple backend may now be used from other sequences.
class BackendCleanupTracker; class BackendCleanupTracker;
class SimpleEntryImpl; class SimpleEntryImpl;
...@@ -204,8 +206,8 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, ...@@ -204,8 +206,8 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
Int64CompletionOnceCallback callback, Int64CompletionOnceCallback callback,
int result); int result);
// Try to create the directory if it doesn't exist. This must run on the IO // Try to create the directory if it doesn't exist. This must run on the
// thread. // source creation sequence.
static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path, static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path,
uint64_t suggested_max_size, uint64_t suggested_max_size,
net::CacheType cache_type); net::CacheType cache_type);
......
...@@ -15,11 +15,10 @@ ...@@ -15,11 +15,10 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/task_runner.h" #include "base/task_runner.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/memory_usage_estimator.h" #include "base/trace_event/memory_usage_estimator.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
...@@ -125,7 +124,7 @@ int PostToCallbackIfNeeded(bool sync_possible, ...@@ -125,7 +124,7 @@ int PostToCallbackIfNeeded(bool sync_possible,
net::CompletionOnceCallback callback, net::CompletionOnceCallback callback,
int rv) { int rv) {
if (!sync_possible && !callback.is_null()) { if (!sync_possible && !callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), rv)); FROM_HERE, base::BindOnce(std::move(callback), rv));
return net::ERR_IO_PENDING; return net::ERR_IO_PENDING;
} else { } else {
...@@ -383,7 +382,7 @@ void SimpleEntryImpl::Doom() { ...@@ -383,7 +382,7 @@ void SimpleEntryImpl::Doom() {
} }
void SimpleEntryImpl::Close() { void SimpleEntryImpl::Close() {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_LT(0, open_count_); DCHECK_LT(0, open_count_);
net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_CALL); net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_CALL);
...@@ -401,23 +400,23 @@ void SimpleEntryImpl::Close() { ...@@ -401,23 +400,23 @@ void SimpleEntryImpl::Close() {
} }
std::string SimpleEntryImpl::GetKey() const { std::string SimpleEntryImpl::GetKey() const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return key_; return key_;
} }
Time SimpleEntryImpl::GetLastUsed() const { Time SimpleEntryImpl::GetLastUsed() const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(cache_type_ != net::APP_CACHE); DCHECK(cache_type_ != net::APP_CACHE);
return last_used_; return last_used_;
} }
Time SimpleEntryImpl::GetLastModified() const { Time SimpleEntryImpl::GetLastModified() const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return last_modified_; return last_modified_;
} }
int32_t SimpleEntryImpl::GetDataSize(int stream_index) const { int32_t SimpleEntryImpl::GetDataSize(int stream_index) const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_LE(0, data_size_[stream_index]); DCHECK_LE(0, data_size_[stream_index]);
return data_size_[stream_index]; return data_size_[stream_index];
} }
...@@ -427,7 +426,7 @@ int SimpleEntryImpl::ReadData(int stream_index, ...@@ -427,7 +426,7 @@ int SimpleEntryImpl::ReadData(int stream_index,
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
CompletionOnceCallback callback) { CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_CALL, net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_CALL,
...@@ -471,7 +470,7 @@ int SimpleEntryImpl::WriteData(int stream_index, ...@@ -471,7 +470,7 @@ int SimpleEntryImpl::WriteData(int stream_index,
int buf_len, int buf_len,
CompletionOnceCallback callback, CompletionOnceCallback callback,
bool truncate) { bool truncate) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_CALL, net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_CALL,
...@@ -551,7 +550,7 @@ int SimpleEntryImpl::ReadSparseData(int64_t offset, ...@@ -551,7 +550,7 @@ int SimpleEntryImpl::ReadSparseData(int64_t offset,
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
CompletionOnceCallback callback) { CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_CALL, net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_CALL,
...@@ -577,7 +576,7 @@ int SimpleEntryImpl::WriteSparseData(int64_t offset, ...@@ -577,7 +576,7 @@ int SimpleEntryImpl::WriteSparseData(int64_t offset,
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
CompletionOnceCallback callback) { CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
net_log_.AddEvent( net_log_.AddEvent(
...@@ -604,7 +603,7 @@ int SimpleEntryImpl::GetAvailableRange(int64_t offset, ...@@ -604,7 +603,7 @@ int SimpleEntryImpl::GetAvailableRange(int64_t offset,
int len, int len,
int64_t* start, int64_t* start,
CompletionOnceCallback callback) { CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (offset < 0 || len < 0) if (offset < 0 || len < 0)
return net::ERR_INVALID_ARGUMENT; return net::ERR_INVALID_ARGUMENT;
...@@ -615,20 +614,20 @@ int SimpleEntryImpl::GetAvailableRange(int64_t offset, ...@@ -615,20 +614,20 @@ int SimpleEntryImpl::GetAvailableRange(int64_t offset,
} }
bool SimpleEntryImpl::CouldBeSparse() const { bool SimpleEntryImpl::CouldBeSparse() const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(morlovich): Actually check. // TODO(morlovich): Actually check.
return true; return true;
} }
void SimpleEntryImpl::CancelSparseIO() { void SimpleEntryImpl::CancelSparseIO() {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// The Simple Cache does not return distinct objects for the same non-doomed // The Simple Cache does not return distinct objects for the same non-doomed
// entry, so there's no need to coordinate which object is performing sparse // entry, so there's no need to coordinate which object is performing sparse
// I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly.
} }
net::Error SimpleEntryImpl::ReadyForSparseIO(CompletionOnceCallback callback) { net::Error SimpleEntryImpl::ReadyForSparseIO(CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// The simple Cache does not return distinct objects for the same non-doomed // The simple Cache does not return distinct objects for the same non-doomed
// entry, so there's no need to coordinate which object is performing sparse // entry, so there's no need to coordinate which object is performing sparse
// I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly.
...@@ -654,7 +653,7 @@ void SimpleEntryImpl::SetPriority(uint32_t entry_priority) { ...@@ -654,7 +653,7 @@ void SimpleEntryImpl::SetPriority(uint32_t entry_priority) {
} }
SimpleEntryImpl::~SimpleEntryImpl() { SimpleEntryImpl::~SimpleEntryImpl() {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(0U, pending_operations_.size()); DCHECK_EQ(0U, pending_operations_.size());
// STATE_IO_PENDING is possible here in one corner case: the entry had // STATE_IO_PENDING is possible here in one corner case: the entry had
...@@ -675,7 +674,7 @@ void SimpleEntryImpl::PostClientCallback(net::CompletionOnceCallback callback, ...@@ -675,7 +674,7 @@ void SimpleEntryImpl::PostClientCallback(net::CompletionOnceCallback callback,
return; return;
// Note that the callback is posted rather than directly invoked to avoid // Note that the callback is posted rather than directly invoked to avoid
// reentrancy issues. // reentrancy issues.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&InvokeCallbackIfBackendIsAlive, backend_, FROM_HERE, base::BindOnce(&InvokeCallbackIfBackendIsAlive, backend_,
std::move(callback), result)); std::move(callback), result));
} }
...@@ -724,7 +723,7 @@ void SimpleEntryImpl::ReturnEntryToCallerAndPostCallback( ...@@ -724,7 +723,7 @@ void SimpleEntryImpl::ReturnEntryToCallerAndPostCallback(
// potentially call ReturnEntryToCaller and then roll it back rather than // potentially call ReturnEntryToCaller and then roll it back rather than
// delay ReturnEntryToCaller: it protects |this| till any potential ownership // delay ReturnEntryToCaller: it protects |this| till any potential ownership
// share transfer is sorted out. // share transfer is sorted out.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&InvokeCallbackIfBackendIsAliveOrCloseEntry, backend_, base::BindOnce(&InvokeCallbackIfBackendIsAliveOrCloseEntry, backend_,
base::Unretained(this), std::move(callback))); base::Unretained(this), std::move(callback)));
...@@ -740,7 +739,7 @@ void SimpleEntryImpl::MarkAsDoomed(DoomState new_state) { ...@@ -740,7 +739,7 @@ void SimpleEntryImpl::MarkAsDoomed(DoomState new_state) {
} }
void SimpleEntryImpl::RunNextOperationIfNeeded() { void SimpleEntryImpl::RunNextOperationIfNeeded() {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) { if (!pending_operations_.empty() && state_ != STATE_IO_PENDING) {
SimpleEntryOperation operation = std::move(pending_operations_.front()); SimpleEntryOperation operation = std::move(pending_operations_.front());
pending_operations_.pop(); pending_operations_.pop();
...@@ -953,7 +952,7 @@ void SimpleEntryImpl::OpenOrCreateEntryInternal( ...@@ -953,7 +952,7 @@ void SimpleEntryImpl::OpenOrCreateEntryInternal(
} }
void SimpleEntryImpl::CloseInternal() { void SimpleEntryImpl::CloseInternal() {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (open_count_ != 0) { if (open_count_ != 0) {
// Entry got resurrected in between Close and CloseInternal, nothing to do // Entry got resurrected in between Close and CloseInternal, nothing to do
...@@ -1017,7 +1016,7 @@ int SimpleEntryImpl::ReadDataInternal(bool sync_possible, ...@@ -1017,7 +1016,7 @@ int SimpleEntryImpl::ReadDataInternal(bool sync_possible,
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ScopedOperationRunner operation_runner(this); ScopedOperationRunner operation_runner(this);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
...@@ -1111,7 +1110,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, ...@@ -1111,7 +1110,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index,
int buf_len, int buf_len,
net::CompletionOnceCallback callback, net::CompletionOnceCallback callback,
bool truncate) { bool truncate) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ScopedOperationRunner operation_runner(this); ScopedOperationRunner operation_runner(this);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
...@@ -1127,7 +1126,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, ...@@ -1127,7 +1126,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index,
CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED));
} }
if (!callback.is_null()) { if (!callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED)); FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED));
} }
// |this| may be destroyed after return here. // |this| may be destroyed after return here.
...@@ -1140,7 +1139,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, ...@@ -1140,7 +1139,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index,
if (stream_index == 0) { if (stream_index == 0) {
int ret_value = SetStream0Data(buf, offset, buf_len, truncate); int ret_value = SetStream0Data(buf, offset, buf_len, truncate);
if (!callback.is_null()) { if (!callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), ret_value)); FROM_HERE, base::BindOnce(std::move(callback), ret_value));
} }
return; return;
...@@ -1153,7 +1152,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, ...@@ -1153,7 +1152,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index,
RecordWriteResult(cache_type_, RecordWriteResult(cache_type_,
SIMPLE_ENTRY_WRITE_RESULT_FAST_EMPTY_RETURN); SIMPLE_ENTRY_WRITE_RESULT_FAST_EMPTY_RETURN);
if (!callback.is_null()) { if (!callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), 0)); FROM_HERE, base::BindOnce(std::move(callback), 0));
} }
return; return;
...@@ -1229,7 +1228,7 @@ void SimpleEntryImpl::ReadSparseDataInternal( ...@@ -1229,7 +1228,7 @@ void SimpleEntryImpl::ReadSparseDataInternal(
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ScopedOperationRunner operation_runner(this); ScopedOperationRunner operation_runner(this);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
...@@ -1245,7 +1244,7 @@ void SimpleEntryImpl::ReadSparseDataInternal( ...@@ -1245,7 +1244,7 @@ void SimpleEntryImpl::ReadSparseDataInternal(
CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED));
} }
if (!callback.is_null()) { if (!callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED)); FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED));
} }
// |this| may be destroyed after return here. // |this| may be destroyed after return here.
...@@ -1274,7 +1273,7 @@ void SimpleEntryImpl::WriteSparseDataInternal( ...@@ -1274,7 +1273,7 @@ void SimpleEntryImpl::WriteSparseDataInternal(
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ScopedOperationRunner operation_runner(this); ScopedOperationRunner operation_runner(this);
if (net_log_.IsCapturing()) { if (net_log_.IsCapturing()) {
...@@ -1290,7 +1289,7 @@ void SimpleEntryImpl::WriteSparseDataInternal( ...@@ -1290,7 +1289,7 @@ void SimpleEntryImpl::WriteSparseDataInternal(
CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED));
} }
if (!callback.is_null()) { if (!callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED)); FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED));
} }
// |this| may be destroyed after return here. // |this| may be destroyed after return here.
...@@ -1330,12 +1329,12 @@ void SimpleEntryImpl::GetAvailableRangeInternal( ...@@ -1330,12 +1329,12 @@ void SimpleEntryImpl::GetAvailableRangeInternal(
int len, int len,
int64_t* out_start, int64_t* out_start,
net::CompletionOnceCallback callback) { net::CompletionOnceCallback callback) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
ScopedOperationRunner operation_runner(this); ScopedOperationRunner operation_runner(this);
if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) {
if (!callback.is_null()) { if (!callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED)); FROM_HERE, base::BindOnce(std::move(callback), net::ERR_FAILED));
} }
// |this| may be destroyed after return here. // |this| may be destroyed after return here.
...@@ -1424,7 +1423,7 @@ void SimpleEntryImpl::CreationOperationComplete( ...@@ -1424,7 +1423,7 @@ void SimpleEntryImpl::CreationOperationComplete(
Entry** out_entry, Entry** out_entry,
bool* out_opened, bool* out_opened,
net::NetLogEventType end_event_type) { net::NetLogEventType end_event_type) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(state_, STATE_IO_PENDING); DCHECK_EQ(state_, STATE_IO_PENDING);
DCHECK(in_results); DCHECK(in_results);
ScopedOperationRunner operation_runner(this); ScopedOperationRunner operation_runner(this);
...@@ -1528,7 +1527,7 @@ void SimpleEntryImpl::EntryOperationComplete( ...@@ -1528,7 +1527,7 @@ void SimpleEntryImpl::EntryOperationComplete(
net::CompletionOnceCallback completion_callback, net::CompletionOnceCallback completion_callback,
const SimpleEntryStat& entry_stat, const SimpleEntryStat& entry_stat,
int result) { int result) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(synchronous_entry_); DCHECK(synchronous_entry_);
DCHECK_EQ(STATE_IO_PENDING, state_); DCHECK_EQ(STATE_IO_PENDING, state_);
if (result < 0) { if (result < 0) {
...@@ -1540,7 +1539,7 @@ void SimpleEntryImpl::EntryOperationComplete( ...@@ -1540,7 +1539,7 @@ void SimpleEntryImpl::EntryOperationComplete(
} }
if (!completion_callback.is_null()) { if (!completion_callback.is_null()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(completion_callback), result)); FROM_HERE, base::BindOnce(std::move(completion_callback), result));
} }
RunNextOperationIfNeeded(); RunNextOperationIfNeeded();
...@@ -1552,7 +1551,7 @@ void SimpleEntryImpl::ReadOperationComplete( ...@@ -1552,7 +1551,7 @@ void SimpleEntryImpl::ReadOperationComplete(
net::CompletionOnceCallback completion_callback, net::CompletionOnceCallback completion_callback,
std::unique_ptr<SimpleEntryStat> entry_stat, std::unique_ptr<SimpleEntryStat> entry_stat,
std::unique_ptr<SimpleSynchronousEntry::ReadResult> read_result) { std::unique_ptr<SimpleSynchronousEntry::ReadResult> read_result) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(synchronous_entry_); DCHECK(synchronous_entry_);
DCHECK_EQ(STATE_IO_PENDING, state_); DCHECK_EQ(STATE_IO_PENDING, state_);
DCHECK(read_result); DCHECK(read_result);
...@@ -1623,7 +1622,7 @@ void SimpleEntryImpl::ReadSparseOperationComplete( ...@@ -1623,7 +1622,7 @@ void SimpleEntryImpl::ReadSparseOperationComplete(
net::CompletionOnceCallback completion_callback, net::CompletionOnceCallback completion_callback,
std::unique_ptr<base::Time> last_used, std::unique_ptr<base::Time> last_used,
std::unique_ptr<int> result) { std::unique_ptr<int> result) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(synchronous_entry_); DCHECK(synchronous_entry_);
DCHECK(result); DCHECK(result);
...@@ -1641,7 +1640,7 @@ void SimpleEntryImpl::WriteSparseOperationComplete( ...@@ -1641,7 +1640,7 @@ void SimpleEntryImpl::WriteSparseOperationComplete(
net::CompletionOnceCallback completion_callback, net::CompletionOnceCallback completion_callback,
std::unique_ptr<SimpleEntryStat> entry_stat, std::unique_ptr<SimpleEntryStat> entry_stat,
std::unique_ptr<int> result) { std::unique_ptr<int> result) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(synchronous_entry_); DCHECK(synchronous_entry_);
DCHECK(result); DCHECK(result);
...@@ -1656,7 +1655,7 @@ void SimpleEntryImpl::WriteSparseOperationComplete( ...@@ -1656,7 +1655,7 @@ void SimpleEntryImpl::WriteSparseOperationComplete(
void SimpleEntryImpl::GetAvailableRangeOperationComplete( void SimpleEntryImpl::GetAvailableRangeOperationComplete(
net::CompletionOnceCallback completion_callback, net::CompletionOnceCallback completion_callback,
std::unique_ptr<int> result) { std::unique_ptr<int> result) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(synchronous_entry_); DCHECK(synchronous_entry_);
DCHECK(result); DCHECK(result);
...@@ -1681,7 +1680,7 @@ void SimpleEntryImpl::DoomOperationComplete( ...@@ -1681,7 +1680,7 @@ void SimpleEntryImpl::DoomOperationComplete(
void SimpleEntryImpl::RecordReadResultConsideringChecksum( void SimpleEntryImpl::RecordReadResultConsideringChecksum(
const std::unique_ptr<SimpleSynchronousEntry::ReadResult>& read_result) const std::unique_ptr<SimpleSynchronousEntry::ReadResult>& read_result)
const { const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(synchronous_entry_); DCHECK(synchronous_entry_);
DCHECK_EQ(STATE_IO_PENDING, state_); DCHECK_EQ(STATE_IO_PENDING, state_);
...@@ -1716,7 +1715,7 @@ void SimpleEntryImpl::CloseOperationComplete( ...@@ -1716,7 +1715,7 @@ void SimpleEntryImpl::CloseOperationComplete(
void SimpleEntryImpl::UpdateDataFromEntryStat( void SimpleEntryImpl::UpdateDataFromEntryStat(
const SimpleEntryStat& entry_stat) { const SimpleEntryStat& entry_stat) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(synchronous_entry_); DCHECK(synchronous_entry_);
DCHECK_EQ(STATE_READY, state_); DCHECK_EQ(STATE_READY, state_);
...@@ -1787,7 +1786,7 @@ int SimpleEntryImpl::SetStream0Data(net::IOBuffer* buf, ...@@ -1787,7 +1786,7 @@ int SimpleEntryImpl::SetStream0Data(net::IOBuffer* buf,
base::Time modification_time = base::Time::Now(); base::Time modification_time = base::Time::Now();
// Reset checksum; SimpleSynchronousEntry::Close will compute it for us, // Reset checksum; SimpleSynchronousEntry::Close will compute it for us,
// and do it off the I/O thread. // and do it off the source creation sequence.
crc32s_end_offset_[0] = 0; crc32s_end_offset_[0] = 0;
UpdateDataFromEntryStat( UpdateDataFromEntryStat(
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/containers/queue.h" #include "base/containers/queue.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h" #include "base/sequence_checker.h"
#include "net/base/cache_type.h" #include "net/base/cache_type.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
#include "net/base/request_priority.h" #include "net/base/request_priority.h"
...@@ -44,9 +44,9 @@ class SimpleFileTracker; ...@@ -44,9 +44,9 @@ class SimpleFileTracker;
class SimpleSynchronousEntry; class SimpleSynchronousEntry;
struct SimpleEntryCreationResults; struct SimpleEntryCreationResults;
// SimpleEntryImpl is the IO thread interface to an entry in the very simple // SimpleEntryImpl is the source task_runner interface to an entry in the very
// disk cache. It proxies for the SimpleSynchronousEntry, which performs IO // simple disk cache. It proxies for the SimpleSynchronousEntry, which performs
// on the worker thread. // IO on the worker thread.
class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry, class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry,
public base::RefCounted<SimpleEntryImpl> { public base::RefCounted<SimpleEntryImpl> {
friend class base::RefCounted<SimpleEntryImpl>; friend class base::RefCounted<SimpleEntryImpl>;
...@@ -307,7 +307,7 @@ class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry, ...@@ -307,7 +307,7 @@ class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry,
// Called after an asynchronous write completes. // Called after an asynchronous write completes.
// |buf| parameter brings back a reference to net::IOBuffer to the original // |buf| parameter brings back a reference to net::IOBuffer to the original
// thread, so that we can reduce cross thread malloc/free pair. // sequence, so that we can reduce cross thread malloc/free pair.
// See http://crbug.com/708644 for details. // See http://crbug.com/708644 for details.
void WriteOperationComplete( void WriteOperationComplete(
int stream_index, int stream_index,
...@@ -367,9 +367,10 @@ class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry, ...@@ -367,9 +367,10 @@ class NET_EXPORT_PRIVATE SimpleEntryImpl : public Entry,
std::unique_ptr<ActiveEntryProxy> active_entry_proxy_; std::unique_ptr<ActiveEntryProxy> active_entry_proxy_;
// All nonstatic SimpleEntryImpl methods should always be called on the IO // All nonstatic SimpleEntryImpl methods should always be called on the
// thread, in all cases. |io_thread_checker_| documents and enforces this. // source creation sequence, in all cases. |sequence_checker_| documents and
base::ThreadChecker io_thread_checker_; // enforces this.
SEQUENCE_CHECKER(sequence_checker_);
const base::WeakPtr<SimpleBackendImpl> backend_; const base::WeakPtr<SimpleBackendImpl> backend_;
SimpleFileTracker* const file_tracker_; SimpleFileTracker* const file_tracker_;
......
...@@ -177,7 +177,7 @@ bool EntryMetadata::Deserialize(net::CacheType cache_type, ...@@ -177,7 +177,7 @@ bool EntryMetadata::Deserialize(net::CacheType cache_type,
} }
SimpleIndex::SimpleIndex( SimpleIndex::SimpleIndex(
const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, const scoped_refptr<base::SequencedTaskRunner>& task_runner,
scoped_refptr<BackendCleanupTracker> cleanup_tracker, scoped_refptr<BackendCleanupTracker> cleanup_tracker,
SimpleIndexDelegate* delegate, SimpleIndexDelegate* delegate,
net::CacheType cache_type, net::CacheType cache_type,
...@@ -186,7 +186,7 @@ SimpleIndex::SimpleIndex( ...@@ -186,7 +186,7 @@ SimpleIndex::SimpleIndex(
delegate_(delegate), delegate_(delegate),
cache_type_(cache_type), cache_type_(cache_type),
index_file_(std::move(index_file)), index_file_(std::move(index_file)),
io_thread_(io_thread), task_runner_(task_runner),
// Creating the callback once so it is reused every time // Creating the callback once so it is reused every time
// write_to_disk_timer_.Start() is called. // write_to_disk_timer_.Start() is called.
write_to_disk_cb_(base::Bind(&SimpleIndex::WriteToDisk, write_to_disk_cb_(base::Bind(&SimpleIndex::WriteToDisk,
...@@ -194,7 +194,7 @@ SimpleIndex::SimpleIndex( ...@@ -194,7 +194,7 @@ SimpleIndex::SimpleIndex(
INDEX_WRITE_REASON_IDLE)) {} INDEX_WRITE_REASON_IDLE)) {}
SimpleIndex::~SimpleIndex() { SimpleIndex::~SimpleIndex() {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Fail all callbacks waiting for the index to come up. // Fail all callbacks waiting for the index to come up.
for (auto it = to_run_when_initialized_.begin(), for (auto it = to_run_when_initialized_.begin(),
...@@ -205,7 +205,7 @@ SimpleIndex::~SimpleIndex() { ...@@ -205,7 +205,7 @@ SimpleIndex::~SimpleIndex() {
} }
void SimpleIndex::Initialize(base::Time cache_mtime) { void SimpleIndex::Initialize(base::Time cache_mtime) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (app_status_listener_) { if (app_status_listener_) {
...@@ -238,9 +238,9 @@ void SimpleIndex::SetMaxSize(uint64_t max_bytes) { ...@@ -238,9 +238,9 @@ void SimpleIndex::SetMaxSize(uint64_t max_bytes) {
} }
net::Error SimpleIndex::ExecuteWhenReady(net::CompletionOnceCallback task) { net::Error SimpleIndex::ExecuteWhenReady(net::CompletionOnceCallback task) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (initialized_) if (initialized_)
io_thread_->PostTask(FROM_HERE, base::BindOnce(std::move(task), net::OK)); task_runner_->PostTask(FROM_HERE, base::BindOnce(std::move(task), net::OK));
else else
to_run_when_initialized_.push_back(std::move(task)); to_run_when_initialized_.push_back(std::move(task));
return net::ERR_IO_PENDING; return net::ERR_IO_PENDING;
...@@ -316,7 +316,7 @@ size_t SimpleIndex::EstimateMemoryUsage() const { ...@@ -316,7 +316,7 @@ size_t SimpleIndex::EstimateMemoryUsage() const {
} }
base::Time SimpleIndex::GetLastUsedTime(uint64_t entry_hash) { base::Time SimpleIndex::GetLastUsedTime(uint64_t entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_NE(cache_type_, net::APP_CACHE); DCHECK_NE(cache_type_, net::APP_CACHE);
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
if (it == entries_set_.end()) if (it == entries_set_.end())
...@@ -336,7 +336,7 @@ bool SimpleIndex::HasPendingWrite() const { ...@@ -336,7 +336,7 @@ bool SimpleIndex::HasPendingWrite() const {
} }
void SimpleIndex::Insert(uint64_t entry_hash) { void SimpleIndex::Insert(uint64_t entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Upon insert we don't know yet the size of the entry. // Upon insert we don't know yet the size of the entry.
// It will be updated later when the SimpleEntryImpl finishes opening or // It will be updated later when the SimpleEntryImpl finishes opening or
// creating the new entry, and then UpdateEntrySize will be called. // creating the new entry, and then UpdateEntrySize will be called.
...@@ -355,7 +355,7 @@ void SimpleIndex::Insert(uint64_t entry_hash) { ...@@ -355,7 +355,7 @@ void SimpleIndex::Insert(uint64_t entry_hash) {
} }
void SimpleIndex::Remove(uint64_t entry_hash) { void SimpleIndex::Remove(uint64_t entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool need_write = false; bool need_write = false;
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
if (it != entries_set_.end()) { if (it != entries_set_.end()) {
...@@ -372,13 +372,13 @@ void SimpleIndex::Remove(uint64_t entry_hash) { ...@@ -372,13 +372,13 @@ void SimpleIndex::Remove(uint64_t entry_hash) {
} }
bool SimpleIndex::Has(uint64_t hash) const { bool SimpleIndex::Has(uint64_t hash) const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// If not initialized, always return true, forcing it to go to the disk. // If not initialized, always return true, forcing it to go to the disk.
return !initialized_ || entries_set_.count(hash) > 0; return !initialized_ || entries_set_.count(hash) > 0;
} }
uint8_t SimpleIndex::GetEntryInMemoryData(uint64_t entry_hash) const { uint8_t SimpleIndex::GetEntryInMemoryData(uint64_t entry_hash) const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
if (it == entries_set_.end()) if (it == entries_set_.end())
return 0; return 0;
...@@ -386,7 +386,7 @@ uint8_t SimpleIndex::GetEntryInMemoryData(uint64_t entry_hash) const { ...@@ -386,7 +386,7 @@ uint8_t SimpleIndex::GetEntryInMemoryData(uint64_t entry_hash) const {
} }
void SimpleIndex::SetEntryInMemoryData(uint64_t entry_hash, uint8_t value) { void SimpleIndex::SetEntryInMemoryData(uint64_t entry_hash, uint8_t value) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
if (it == entries_set_.end()) if (it == entries_set_.end())
return; return;
...@@ -394,7 +394,7 @@ void SimpleIndex::SetEntryInMemoryData(uint64_t entry_hash, uint8_t value) { ...@@ -394,7 +394,7 @@ void SimpleIndex::SetEntryInMemoryData(uint64_t entry_hash, uint8_t value) {
} }
bool SimpleIndex::UseIfExists(uint64_t entry_hash) { bool SimpleIndex::UseIfExists(uint64_t entry_hash) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Always update the last used time, even if it is during initialization. // Always update the last used time, even if it is during initialization.
// It will be merged later. // It will be merged later.
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
...@@ -410,7 +410,7 @@ bool SimpleIndex::UseIfExists(uint64_t entry_hash) { ...@@ -410,7 +410,7 @@ bool SimpleIndex::UseIfExists(uint64_t entry_hash) {
} }
void SimpleIndex::StartEvictionIfNeeded() { void SimpleIndex::StartEvictionIfNeeded() {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (eviction_in_progress_ || cache_size_ <= high_watermark_) if (eviction_in_progress_ || cache_size_ <= high_watermark_)
return; return;
// Take all live key hashes from the index and sort them by time. // Take all live key hashes from the index and sort them by time.
...@@ -467,7 +467,7 @@ void SimpleIndex::StartEvictionIfNeeded() { ...@@ -467,7 +467,7 @@ void SimpleIndex::StartEvictionIfNeeded() {
} }
int32_t SimpleIndex::GetTrailerPrefetchSize(uint64_t entry_hash) const { int32_t SimpleIndex::GetTrailerPrefetchSize(uint64_t entry_hash) const {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(cache_type_, net::APP_CACHE); DCHECK_EQ(cache_type_, net::APP_CACHE);
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
if (it == entries_set_.end()) if (it == entries_set_.end())
...@@ -476,7 +476,7 @@ int32_t SimpleIndex::GetTrailerPrefetchSize(uint64_t entry_hash) const { ...@@ -476,7 +476,7 @@ int32_t SimpleIndex::GetTrailerPrefetchSize(uint64_t entry_hash) const {
} }
void SimpleIndex::SetTrailerPrefetchSize(uint64_t entry_hash, int32_t size) { void SimpleIndex::SetTrailerPrefetchSize(uint64_t entry_hash, int32_t size) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(cache_type_, net::APP_CACHE); DCHECK_EQ(cache_type_, net::APP_CACHE);
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
if (it == entries_set_.end()) if (it == entries_set_.end())
...@@ -489,7 +489,7 @@ void SimpleIndex::SetTrailerPrefetchSize(uint64_t entry_hash, int32_t size) { ...@@ -489,7 +489,7 @@ void SimpleIndex::SetTrailerPrefetchSize(uint64_t entry_hash, int32_t size) {
bool SimpleIndex::UpdateEntrySize(uint64_t entry_hash, bool SimpleIndex::UpdateEntrySize(uint64_t entry_hash,
base::StrictNumeric<uint32_t> entry_size) { base::StrictNumeric<uint32_t> entry_size) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto it = entries_set_.find(entry_hash); auto it = entries_set_.find(entry_hash);
if (it == entries_set_.end()) if (it == entries_set_.end())
return false; return false;
...@@ -505,7 +505,7 @@ bool SimpleIndex::UpdateEntrySize(uint64_t entry_hash, ...@@ -505,7 +505,7 @@ bool SimpleIndex::UpdateEntrySize(uint64_t entry_hash,
} }
void SimpleIndex::EvictionDone(int result) { void SimpleIndex::EvictionDone(int result) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Ignore the result of eviction. We did our best. // Ignore the result of eviction. We did our best.
eviction_in_progress_ = false; eviction_in_progress_ = false;
...@@ -549,7 +549,7 @@ bool SimpleIndex::UpdateEntryIteratorSize( ...@@ -549,7 +549,7 @@ bool SimpleIndex::UpdateEntryIteratorSize(
EntrySet::iterator* it, EntrySet::iterator* it,
base::StrictNumeric<uint32_t> entry_size) { base::StrictNumeric<uint32_t> entry_size) {
// Update the total cache size with the new entry size. // Update the total cache size with the new entry size.
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_GE(cache_size_, (*it)->second.GetEntrySize()); DCHECK_GE(cache_size_, (*it)->second.GetEntrySize());
uint32_t original_size = (*it)->second.GetEntrySize(); uint32_t original_size = (*it)->second.GetEntrySize();
cache_size_ -= (*it)->second.GetEntrySize(); cache_size_ -= (*it)->second.GetEntrySize();
...@@ -563,7 +563,7 @@ bool SimpleIndex::UpdateEntryIteratorSize( ...@@ -563,7 +563,7 @@ bool SimpleIndex::UpdateEntryIteratorSize(
void SimpleIndex::MergeInitializingSet( void SimpleIndex::MergeInitializingSet(
std::unique_ptr<SimpleIndexLoadResult> load_result) { std::unique_ptr<SimpleIndexLoadResult> load_result) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
EntrySet* index_file_entries = &load_result->entries; EntrySet* index_file_entries = &load_result->entries;
...@@ -619,7 +619,7 @@ void SimpleIndex::MergeInitializingSet( ...@@ -619,7 +619,7 @@ void SimpleIndex::MergeInitializingSet(
for (auto it = to_run_when_initialized_.begin(), for (auto it = to_run_when_initialized_.begin(),
end = to_run_when_initialized_.end(); end = to_run_when_initialized_.end();
it != end; ++it) { it != end; ++it) {
io_thread_->PostTask(FROM_HERE, base::BindOnce(std::move(*it), net::OK)); task_runner_->PostTask(FROM_HERE, base::BindOnce(std::move(*it), net::OK));
} }
to_run_when_initialized_.clear(); to_run_when_initialized_.clear();
} }
...@@ -627,7 +627,7 @@ void SimpleIndex::MergeInitializingSet( ...@@ -627,7 +627,7 @@ void SimpleIndex::MergeInitializingSet(
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void SimpleIndex::OnApplicationStateChange( void SimpleIndex::OnApplicationStateChange(
base::android::ApplicationState state) { base::android::ApplicationState state) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// For more info about android activities, see: // For more info about android activities, see:
// developer.android.com/training/basics/activity-lifecycle/pausing.html // developer.android.com/training/basics/activity-lifecycle/pausing.html
if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) { if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
...@@ -641,7 +641,7 @@ void SimpleIndex::OnApplicationStateChange( ...@@ -641,7 +641,7 @@ void SimpleIndex::OnApplicationStateChange(
#endif #endif
void SimpleIndex::WriteToDisk(IndexWriteToDiskReason reason) { void SimpleIndex::WriteToDisk(IndexWriteToDiskReason reason) {
DCHECK(io_thread_checker_.CalledOnValidThread()); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!initialized_) if (!initialized_)
return; return;
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/single_thread_task_runner.h" #include "base/sequence_checker.h"
#include "base/threading/thread_checker.h" #include "base/sequenced_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -134,7 +134,7 @@ class NET_EXPORT_PRIVATE SimpleIndex ...@@ -134,7 +134,7 @@ class NET_EXPORT_PRIVATE SimpleIndex
typedef std::vector<uint64_t> HashList; typedef std::vector<uint64_t> HashList;
SimpleIndex(const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, SimpleIndex(const scoped_refptr<base::SequencedTaskRunner>& task_runner,
scoped_refptr<BackendCleanupTracker> cleanup_tracker, scoped_refptr<BackendCleanupTracker> cleanup_tracker,
SimpleIndexDelegate* delegate, SimpleIndexDelegate* delegate,
net::CacheType cache_type, net::CacheType cache_type,
...@@ -289,11 +289,12 @@ class NET_EXPORT_PRIVATE SimpleIndex ...@@ -289,11 +289,12 @@ class NET_EXPORT_PRIVATE SimpleIndex
std::unique_ptr<SimpleIndexFile> index_file_; std::unique_ptr<SimpleIndexFile> index_file_;
scoped_refptr<base::SingleThreadTaskRunner> io_thread_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
// All nonstatic SimpleEntryImpl methods should always be called on the IO // All nonstatic SimpleEntryImpl methods should always be called on its
// thread, in all cases. |io_thread_checker_| documents and enforces this. // creation sequance, in all cases. |sequence_checker_| documents and
base::ThreadChecker io_thread_checker_; // enforces this.
SEQUENCE_CHECKER(sequence_checker_);
// Timestamp of the last time we wrote the index to disk. // Timestamp of the last time we wrote the index to disk.
// PostponeWritingToDisk() may give up postponing and allow the write if it // PostponeWritingToDisk() may give up postponing and allow the write if it
......
...@@ -48,7 +48,7 @@ struct NET_EXPORT_PRIVATE SimpleIndexLoadResult { ...@@ -48,7 +48,7 @@ struct NET_EXPORT_PRIVATE SimpleIndexLoadResult {
// the format see |SimpleIndexFile::Serialize()| and // the format see |SimpleIndexFile::Serialize()| and
// |SimpleIndexFile::LoadFromDisk()|. // |SimpleIndexFile::LoadFromDisk()|.
// //
// The non-static methods must run on the IO thread. All the real // The non-static methods must run on the source creation sequence. All the real
// work is done in the static methods, which are run on the cache thread // work is done in the static methods, which are run on the cache thread
// or in worker threads. Synchronization between methods is the // or in worker threads. Synchronization between methods is the
// responsibility of the caller. // responsibility of the caller.
...@@ -121,7 +121,8 @@ class NET_EXPORT_PRIVATE SimpleIndexFile { ...@@ -121,7 +121,8 @@ class NET_EXPORT_PRIVATE SimpleIndexFile {
int64_t size)>; int64_t size)>;
// When loading the entries from disk, add this many extra hash buckets to // When loading the entries from disk, add this many extra hash buckets to
// prevent reallocation on the IO thread when merging in new live entries. // prevent reallocation on the creation sequence when merging in new live
// entries.
static const int kExtraSizeForMerge = 512; static const int kExtraSizeForMerge = 512;
// Synchronous (IO performing) implementation of LoadIndexEntries. // Synchronous (IO performing) implementation of LoadIndexEntries.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment