Index: net/disk_cache/simple/simple_backend_impl.cc |
diff --git a/net/disk_cache/simple/simple_backend_impl.cc b/net/disk_cache/simple/simple_backend_impl.cc |
index 5e8c3f2ffbfe38fdfcec27b8f93f87697f7ad97d..af333fce869ce795c17238745bcd1ddedd7c4ecb 100644 |
--- a/net/disk_cache/simple/simple_backend_impl.cc |
+++ b/net/disk_cache/simple/simple_backend_impl.cc |
@@ -73,8 +73,8 @@ void MaybeCreateSequencedWorkerPool() { |
std::max(1, std::atoi(thread_count_field_trial.c_str())); |
} |
- g_sequenced_worker_pool = new SequencedWorkerPool(max_worker_threads, |
- kThreadNamePrefix); |
+ g_sequenced_worker_pool = |
+ new SequencedWorkerPool(max_worker_threads, kThreadNamePrefix); |
g_sequenced_worker_pool->AddRef(); // Leak it. |
} |
} |
@@ -88,9 +88,9 @@ void MaybeHistogramFdLimit(net::CacheType cache_type) { |
// Used in histograms; add new entries at end. |
enum FdLimitStatus { |
FD_LIMIT_STATUS_UNSUPPORTED = 0, |
- FD_LIMIT_STATUS_FAILED = 1, |
- FD_LIMIT_STATUS_SUCCEEDED = 2, |
- FD_LIMIT_STATUS_MAX = 3 |
+ FD_LIMIT_STATUS_FAILED = 1, |
+ FD_LIMIT_STATUS_SUCCEEDED = 2, |
+ FD_LIMIT_STATUS_MAX = 3 |
}; |
FdLimitStatus fd_limit_status = FD_LIMIT_STATUS_UNSUPPORTED; |
int soft_fd_limit = 0; |
@@ -108,13 +108,15 @@ void MaybeHistogramFdLimit(net::CacheType cache_type) { |
#endif |
SIMPLE_CACHE_UMA(ENUMERATION, |
- "FileDescriptorLimitStatus", cache_type, |
- fd_limit_status, FD_LIMIT_STATUS_MAX); |
+ "FileDescriptorLimitStatus", |
+ cache_type, |
+ fd_limit_status, |
+ FD_LIMIT_STATUS_MAX); |
if (fd_limit_status == FD_LIMIT_STATUS_SUCCEEDED) { |
- SIMPLE_CACHE_UMA(SPARSE_SLOWLY, |
- "FileDescriptorLimitSoft", cache_type, soft_fd_limit); |
- SIMPLE_CACHE_UMA(SPARSE_SLOWLY, |
- "FileDescriptorLimitHard", cache_type, hard_fd_limit); |
+ SIMPLE_CACHE_UMA( |
+ SPARSE_SLOWLY, "FileDescriptorLimitSoft", cache_type, soft_fd_limit); |
+ SIMPLE_CACHE_UMA( |
+ SPARSE_SLOWLY, "FileDescriptorLimitHard", cache_type, hard_fd_limit); |
} |
g_fd_limit_histogram_has_been_populated = true; |
@@ -134,9 +136,7 @@ bool FileStructureConsistent(const base::FilePath& path) { |
// A context used by a BarrierCompletionCallback to track state. |
struct BarrierContext { |
BarrierContext(int expected) |
- : expected(expected), |
- count(0), |
- had_error(false) {} |
+ : expected(expected), count(0), had_error(false) {} |
const int expected; |
int count; |
@@ -168,8 +168,8 @@ net::CompletionCallback MakeBarrierCompletionCallback( |
int count, |
const net::CompletionCallback& final_callback) { |
BarrierContext* context = new BarrierContext(count); |
- return base::Bind(&BarrierCompletionCallbackImpl, |
- base::Owned(context), final_callback); |
+ return base::Bind( |
+ &BarrierCompletionCallbackImpl, base::Owned(context), final_callback); |
} |
// A short bindable thunk that ensures a completion callback is always called |
@@ -185,13 +185,13 @@ void RunOperationAndCallback( |
void RecordIndexLoad(net::CacheType cache_type, |
base::TimeTicks constructed_since, |
int result) { |
- const base::TimeDelta creation_to_index = base::TimeTicks::Now() - |
- constructed_since; |
+ const base::TimeDelta creation_to_index = |
+ base::TimeTicks::Now() - constructed_since; |
if (result == net::OK) { |
SIMPLE_CACHE_UMA(TIMES, "CreationToIndex", cache_type, creation_to_index); |
} else { |
- SIMPLE_CACHE_UMA(TIMES, |
- "CreationToIndexFail", cache_type, creation_to_index); |
+ SIMPLE_CACHE_UMA( |
+ TIMES, "CreationToIndexFail", cache_type, creation_to_index); |
} |
} |
@@ -206,10 +206,9 @@ SimpleBackendImpl::SimpleBackendImpl(const FilePath& path, |
cache_type_(cache_type), |
cache_thread_(cache_thread), |
orig_max_size_(max_bytes), |
- entry_operations_mode_( |
- cache_type == net::DISK_CACHE ? |
- SimpleEntryImpl::OPTIMISTIC_OPERATIONS : |
- SimpleEntryImpl::NON_OPTIMISTIC_OPERATIONS), |
+ entry_operations_mode_(cache_type == net::DISK_CACHE |
+ ? SimpleEntryImpl::OPTIMISTIC_OPERATIONS |
+ : SimpleEntryImpl::NON_OPTIMISTIC_OPERATIONS), |
net_log_(net_log) { |
MaybeHistogramFdLimit(cache_type_); |
} |
@@ -224,19 +223,22 @@ int SimpleBackendImpl::Init(const CompletionCallback& completion_callback) { |
worker_pool_ = g_sequenced_worker_pool->GetTaskRunnerWithShutdownBehavior( |
SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
- index_.reset(new SimpleIndex(MessageLoopProxy::current(), this, cache_type_, |
- make_scoped_ptr(new SimpleIndexFile( |
- cache_thread_.get(), worker_pool_.get(), |
- cache_type_, path_)))); |
+ index_.reset(new SimpleIndex( |
+ MessageLoopProxy::current(), |
+ this, |
+ cache_type_, |
+ make_scoped_ptr(new SimpleIndexFile( |
+ cache_thread_.get(), worker_pool_.get(), cache_type_, path_)))); |
index_->ExecuteWhenReady( |
base::Bind(&RecordIndexLoad, cache_type_, base::TimeTicks::Now())); |
PostTaskAndReplyWithResult( |
cache_thread_, |
FROM_HERE, |
- base::Bind(&SimpleBackendImpl::InitCacheStructureOnDisk, path_, |
- orig_max_size_), |
- base::Bind(&SimpleBackendImpl::InitializeIndex, AsWeakPtr(), |
+ base::Bind( |
+ &SimpleBackendImpl::InitCacheStructureOnDisk, path_, orig_max_size_), |
+ base::Bind(&SimpleBackendImpl::InitializeIndex, |
+ AsWeakPtr(), |
completion_callback)); |
return net::ERR_IO_PENDING; |
} |
@@ -270,14 +272,15 @@ void SimpleBackendImpl::OnDoomComplete(uint64 entry_hash) { |
to_run_closures.swap(it->second); |
entries_pending_doom_.erase(it); |
- std::for_each(to_run_closures.begin(), to_run_closures.end(), |
+ std::for_each(to_run_closures.begin(), |
+ to_run_closures.end(), |
std::mem_fun_ref(&Closure::Run)); |
} |
void SimpleBackendImpl::DoomEntries(std::vector<uint64>* entry_hashes, |
const net::CompletionCallback& callback) { |
- scoped_ptr<std::vector<uint64> > |
- mass_doom_entry_hashes(new std::vector<uint64>()); |
+ scoped_ptr<std::vector<uint64> > mass_doom_entry_hashes( |
+ new std::vector<uint64>()); |
mass_doom_entry_hashes->swap(*entry_hashes); |
std::vector<uint64> to_doom_individually_hashes; |
@@ -305,12 +308,13 @@ void SimpleBackendImpl::DoomEntries(std::vector<uint64>* entry_hashes, |
mass_doom_entry_hashes->resize(mass_doom_entry_hashes->size() - 1); |
} |
- net::CompletionCallback barrier_callback = |
- MakeBarrierCompletionCallback(to_doom_individually_hashes.size() + 1, |
- callback); |
+ net::CompletionCallback barrier_callback = MakeBarrierCompletionCallback( |
+ to_doom_individually_hashes.size() + 1, callback); |
for (std::vector<uint64>::const_iterator |
it = to_doom_individually_hashes.begin(), |
- end = to_doom_individually_hashes.end(); it != end; ++it) { |
+ end = to_doom_individually_hashes.end(); |
+ it != end; |
+ ++it) { |
const int doom_result = DoomEntryFromHash(*it, barrier_callback); |
// TODO(ttuttle): Revert to DCHECK once http://crbug.com/317138 is fixed. |
CHECK_EQ(net::ERR_IO_PENDING, doom_result); |
@@ -319,7 +323,8 @@ void SimpleBackendImpl::DoomEntries(std::vector<uint64>* entry_hashes, |
for (std::vector<uint64>::const_iterator it = mass_doom_entry_hashes->begin(), |
end = mass_doom_entry_hashes->end(); |
- it != end; ++it) { |
+ it != end; |
+ ++it) { |
index_->Remove(*it); |
OnDoomStart(*it); |
} |
@@ -328,13 +333,15 @@ void SimpleBackendImpl::DoomEntries(std::vector<uint64>* entry_hashes, |
// base::Passed before mass_doom_entry_hashes.get(). |
std::vector<uint64>* mass_doom_entry_hashes_ptr = |
mass_doom_entry_hashes.get(); |
- PostTaskAndReplyWithResult( |
- worker_pool_, FROM_HERE, |
- base::Bind(&SimpleSynchronousEntry::DoomEntrySet, |
- mass_doom_entry_hashes_ptr, path_), |
- base::Bind(&SimpleBackendImpl::DoomEntriesComplete, |
- AsWeakPtr(), base::Passed(&mass_doom_entry_hashes), |
- barrier_callback)); |
+ PostTaskAndReplyWithResult(worker_pool_, |
+ FROM_HERE, |
+ base::Bind(&SimpleSynchronousEntry::DoomEntrySet, |
+ mass_doom_entry_hashes_ptr, |
+ path_), |
+ base::Bind(&SimpleBackendImpl::DoomEntriesComplete, |
+ AsWeakPtr(), |
+ base::Passed(&mass_doom_entry_hashes), |
+ barrier_callback)); |
} |
net::CacheType SimpleBackendImpl::GetCacheType() const { |
@@ -356,11 +363,10 @@ int SimpleBackendImpl::OpenEntry(const std::string& key, |
base::hash_map<uint64, std::vector<Closure> >::iterator it = |
entries_pending_doom_.find(entry_hash); |
if (it != entries_pending_doom_.end()) { |
- Callback<int(const net::CompletionCallback&)> operation = |
- base::Bind(&SimpleBackendImpl::OpenEntry, |
- base::Unretained(this), key, entry); |
- it->second.push_back(base::Bind(&RunOperationAndCallback, |
- operation, callback)); |
+ Callback<int(const net::CompletionCallback&)> operation = base::Bind( |
+ &SimpleBackendImpl::OpenEntry, base::Unretained(this), key, entry); |
+ it->second.push_back( |
+ base::Bind(&RunOperationAndCallback, operation, callback)); |
return net::ERR_IO_PENDING; |
} |
scoped_refptr<SimpleEntryImpl> simple_entry = |
@@ -384,11 +390,10 @@ int SimpleBackendImpl::CreateEntry(const std::string& key, |
base::hash_map<uint64, std::vector<Closure> >::iterator it = |
entries_pending_doom_.find(entry_hash); |
if (it != entries_pending_doom_.end()) { |
- Callback<int(const net::CompletionCallback&)> operation = |
- base::Bind(&SimpleBackendImpl::CreateEntry, |
- base::Unretained(this), key, entry); |
- it->second.push_back(base::Bind(&RunOperationAndCallback, |
- operation, callback)); |
+ Callback<int(const net::CompletionCallback&)> operation = base::Bind( |
+ &SimpleBackendImpl::CreateEntry, base::Unretained(this), key, entry); |
+ it->second.push_back( |
+ base::Bind(&RunOperationAndCallback, operation, callback)); |
return net::ERR_IO_PENDING; |
} |
scoped_refptr<SimpleEntryImpl> simple_entry = |
@@ -405,8 +410,8 @@ int SimpleBackendImpl::DoomEntry(const std::string& key, |
if (it != entries_pending_doom_.end()) { |
Callback<int(const net::CompletionCallback&)> operation = |
base::Bind(&SimpleBackendImpl::DoomEntry, base::Unretained(this), key); |
- it->second.push_back(base::Bind(&RunOperationAndCallback, |
- operation, callback)); |
+ it->second.push_back( |
+ base::Bind(&RunOperationAndCallback, operation, callback)); |
return net::ERR_IO_PENDING; |
} |
scoped_refptr<SimpleEntryImpl> simple_entry = |
@@ -431,18 +436,19 @@ void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, |
DoomEntries(removed_key_hashes.get(), callback); |
} |
-int SimpleBackendImpl::DoomEntriesBetween( |
- const Time initial_time, |
- const Time end_time, |
- const CompletionCallback& callback) { |
+int SimpleBackendImpl::DoomEntriesBetween(const Time initial_time, |
+ const Time end_time, |
+ const CompletionCallback& callback) { |
return index_->ExecuteWhenReady( |
- base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(), |
- initial_time, end_time, callback)); |
+ base::Bind(&SimpleBackendImpl::IndexReadyForDoom, |
+ AsWeakPtr(), |
+ initial_time, |
+ end_time, |
+ callback)); |
} |
-int SimpleBackendImpl::DoomEntriesSince( |
- const Time initial_time, |
- const CompletionCallback& callback) { |
+int SimpleBackendImpl::DoomEntriesSince(const Time initial_time, |
+ const CompletionCallback& callback) { |
return DoomEntriesBetween(initial_time, Time(), callback); |
} |
@@ -450,8 +456,11 @@ int SimpleBackendImpl::OpenNextEntry(void** iter, |
Entry** next_entry, |
const CompletionCallback& callback) { |
CompletionCallback get_next_entry = |
- base::Bind(&SimpleBackendImpl::GetNextEntryInIterator, AsWeakPtr(), iter, |
- next_entry, callback); |
+ base::Bind(&SimpleBackendImpl::GetNextEntryInIterator, |
+ AsWeakPtr(), |
+ iter, |
+ next_entry, |
+ callback); |
return index_->ExecuteWhenReady(get_next_entry); |
} |
@@ -510,9 +519,8 @@ scoped_refptr<SimpleEntryImpl> SimpleBackendImpl::CreateOrFindActiveEntry( |
const uint64 entry_hash, |
const std::string& key) { |
DCHECK_EQ(entry_hash, simple_util::GetEntryHashKey(key)); |
- std::pair<EntryMap::iterator, bool> insert_result = |
- active_entries_.insert(std::make_pair(entry_hash, |
- base::WeakPtr<SimpleEntryImpl>())); |
+ std::pair<EntryMap::iterator, bool> insert_result = active_entries_.insert( |
+ std::make_pair(entry_hash, base::WeakPtr<SimpleEntryImpl>())); |
EntryMap::iterator& it = insert_result.first; |
if (insert_result.second) |
DCHECK(!it->second.get()); |
@@ -541,9 +549,11 @@ int SimpleBackendImpl::OpenEntryFromHash(uint64 entry_hash, |
if (it != entries_pending_doom_.end()) { |
Callback<int(const net::CompletionCallback&)> operation = |
base::Bind(&SimpleBackendImpl::OpenEntryFromHash, |
- base::Unretained(this), entry_hash, entry); |
- it->second.push_back(base::Bind(&RunOperationAndCallback, |
- operation, callback)); |
+ base::Unretained(this), |
+ entry_hash, |
+ entry); |
+ it->second.push_back( |
+ base::Bind(&RunOperationAndCallback, operation, callback)); |
return net::ERR_IO_PENDING; |
} |
@@ -556,7 +566,11 @@ int SimpleBackendImpl::OpenEntryFromHash(uint64 entry_hash, |
cache_type_, path_, entry_hash, entry_operations_mode_, this, net_log_); |
CompletionCallback backend_callback = |
base::Bind(&SimpleBackendImpl::OnEntryOpenedFromHash, |
- AsWeakPtr(), entry_hash, entry, simple_entry, callback); |
+ AsWeakPtr(), |
+ entry_hash, |
+ entry, |
+ simple_entry, |
+ callback); |
return simple_entry->OpenEntry(entry, backend_callback); |
} |
@@ -570,9 +584,10 @@ int SimpleBackendImpl::DoomEntryFromHash(uint64 entry_hash, |
if (pending_it != entries_pending_doom_.end()) { |
Callback<int(const net::CompletionCallback&)> operation = |
base::Bind(&SimpleBackendImpl::DoomEntryFromHash, |
- base::Unretained(this), entry_hash); |
- pending_it->second.push_back(base::Bind(&RunOperationAndCallback, |
- operation, callback)); |
+ base::Unretained(this), |
+ entry_hash); |
+ pending_it->second.push_back( |
+ base::Bind(&RunOperationAndCallback, operation, callback)); |
return net::ERR_IO_PENDING; |
} |
@@ -607,15 +622,14 @@ void SimpleBackendImpl::GetNextEntryInIterator( |
entry_list->pop_back(); |
if (index()->Has(entry_hash)) { |
*next_entry = NULL; |
- CompletionCallback continue_iteration = base::Bind( |
- &SimpleBackendImpl::CheckIterationReturnValue, |
- AsWeakPtr(), |
- iter, |
- next_entry, |
- callback); |
- int error_code_open = OpenEntryFromHash(entry_hash, |
- next_entry, |
- continue_iteration); |
+ CompletionCallback continue_iteration = |
+ base::Bind(&SimpleBackendImpl::CheckIterationReturnValue, |
+ AsWeakPtr(), |
+ iter, |
+ next_entry, |
+ callback); |
+ int error_code_open = |
+ OpenEntryFromHash(entry_hash, next_entry, continue_iteration); |
if (error_code_open == net::ERR_IO_PENDING) |
return; |
if (error_code_open != net::ERR_FAILED) { |
@@ -638,9 +652,8 @@ void SimpleBackendImpl::OnEntryOpenedFromHash( |
return; |
} |
DCHECK(*entry); |
- std::pair<EntryMap::iterator, bool> insert_result = |
- active_entries_.insert(std::make_pair(hash, |
- base::WeakPtr<SimpleEntryImpl>())); |
+ std::pair<EntryMap::iterator, bool> insert_result = active_entries_.insert( |
+ std::make_pair(hash, base::WeakPtr<SimpleEntryImpl>())); |
EntryMap::iterator& it = insert_result.first; |
const bool did_insert = insert_result.second; |
if (did_insert) { |
@@ -697,9 +710,9 @@ void SimpleBackendImpl::DoomEntriesComplete( |
const net::CompletionCallback& callback, |
int result) { |
std::for_each( |
- entry_hashes->begin(), entry_hashes->end(), |
- std::bind1st(std::mem_fun(&SimpleBackendImpl::OnDoomComplete), |
- this)); |
+ entry_hashes->begin(), |
+ entry_hashes->end(), |
+ std::bind1st(std::mem_fun(&SimpleBackendImpl::OnDoomComplete), this)); |
callback.Run(result); |
} |