diff options
Diffstat (limited to 'chromium/net/disk_cache/simple')
21 files changed, 113 insertions, 139 deletions
diff --git a/chromium/net/disk_cache/simple/post_doom_waiter.cc b/chromium/net/disk_cache/simple/post_doom_waiter.cc index 8814efbfb0e..717adda347d 100644 --- a/chromium/net/disk_cache/simple/post_doom_waiter.cc +++ b/chromium/net/disk_cache/simple/post_doom_waiter.cc @@ -11,7 +11,7 @@ namespace disk_cache { -SimplePostDoomWaiter::SimplePostDoomWaiter() {} +SimplePostDoomWaiter::SimplePostDoomWaiter() = default; SimplePostDoomWaiter::SimplePostDoomWaiter(base::OnceClosure to_run_post_doom) : run_post_doom(std::move(to_run_post_doom)) {} @@ -20,7 +20,7 @@ SimplePostDoomWaiter::SimplePostDoomWaiter(SimplePostDoomWaiter&& other) = default; SimplePostDoomWaiter& SimplePostDoomWaiter::operator=( SimplePostDoomWaiter&& other) = default; -SimplePostDoomWaiter::~SimplePostDoomWaiter() {} +SimplePostDoomWaiter::~SimplePostDoomWaiter() = default; SimplePostDoomWaiterTable::SimplePostDoomWaiterTable(net::CacheType cache_type) : cache_type_(cache_type) {} diff --git a/chromium/net/disk_cache/simple/post_doom_waiter.h b/chromium/net/disk_cache/simple/post_doom_waiter.h index 01c563c8607..3fde99253e3 100644 --- a/chromium/net/disk_cache/simple/post_doom_waiter.h +++ b/chromium/net/disk_cache/simple/post_doom_waiter.h @@ -19,7 +19,7 @@ namespace disk_cache { struct SimplePostDoomWaiter { SimplePostDoomWaiter(); explicit SimplePostDoomWaiter(base::OnceClosure to_run_post_doom); - explicit SimplePostDoomWaiter(SimplePostDoomWaiter&& other); + SimplePostDoomWaiter(SimplePostDoomWaiter&& other); ~SimplePostDoomWaiter(); SimplePostDoomWaiter& operator=(SimplePostDoomWaiter&& other); diff --git a/chromium/net/disk_cache/simple/simple_backend_impl.cc b/chromium/net/disk_cache/simple/simple_backend_impl.cc index cec9824dbc1..e0be60eb39b 100644 --- a/chromium/net/disk_cache/simple/simple_backend_impl.cc +++ b/chromium/net/disk_cache/simple/simple_backend_impl.cc @@ -22,6 +22,7 @@ #include "base/files/file_util.h" #include "base/lazy_instance.h" #include "base/location.h" +#include "base/memory/ptr_util.h" #include "base/metrics/field_trial.h" #include "base/metrics/field_trial_params.h" #include "base/metrics/histogram_functions.h" @@ -192,9 +193,7 @@ class SimpleBackendImpl::ActiveEntryProxy static std::unique_ptr<SimpleEntryImpl::ActiveEntryProxy> Create( int64_t entry_hash, SimpleBackendImpl* backend) { - std::unique_ptr<SimpleEntryImpl::ActiveEntryProxy> proxy( - new ActiveEntryProxy(entry_hash, backend)); - return proxy; + return base::WrapUnique(new ActiveEntryProxy(entry_hash, backend)); } private: @@ -248,7 +247,7 @@ void SimpleBackendImpl::SetTaskRunnerForTesting( std::move(task_runner)); } -net::Error SimpleBackendImpl::Init(CompletionOnceCallback completion_callback) { +void SimpleBackendImpl::Init(CompletionOnceCallback completion_callback) { auto index_task_runner = base::ThreadPool::CreateSequencedTaskRunner( {base::MayBlock(), base::WithBaseSyncPrimitives(), base::TaskPriority::USER_BLOCKING, @@ -273,7 +272,6 @@ net::Error SimpleBackendImpl::Init(CompletionOnceCallback completion_callback) { GetCacheType()), base::BindOnce(&SimpleBackendImpl::InitializeIndex, AsWeakPtr(), std::move(completion_callback))); - return net::ERR_IO_PENDING; } bool SimpleBackendImpl::SetMaxSize(int64_t max_bytes) { @@ -301,8 +299,7 @@ scoped_refptr<SimplePostDoomWaiterTable> SimpleBackendImpl::OnDoomStart( void SimpleBackendImpl::DoomEntries(std::vector<uint64_t>* entry_hashes, net::CompletionOnceCallback callback) { - std::unique_ptr<std::vector<uint64_t>> mass_doom_entry_hashes( - new std::vector<uint64_t>()); + auto mass_doom_entry_hashes = std::make_unique<std::vector<uint64_t>>(); mass_doom_entry_hashes->swap(*entry_hashes); std::vector<uint64_t> to_doom_individually_hashes; @@ -629,7 +626,7 @@ class SimpleBackendImpl::SimpleIterator final : public Iterator { }; std::unique_ptr<Backend::Iterator> SimpleBackendImpl::CreateIterator() { - return std::unique_ptr<Iterator>(new SimpleIterator(AsWeakPtr())); + return std::make_unique<SimpleIterator>(AsWeakPtr()); } void SimpleBackendImpl::GetStats(base::StringPairs* stats) { @@ -780,7 +777,7 @@ SimpleBackendImpl::CreateOrFindActiveOrDoomedEntry( return nullptr; std::pair<EntryMap::iterator, bool> insert_result = - active_entries_.insert(EntryMap::value_type(entry_hash, NULL)); + active_entries_.insert(EntryMap::value_type(entry_hash, nullptr)); EntryMap::iterator& it = insert_result.first; const bool did_insert = insert_result.second; if (did_insert) { @@ -841,9 +838,6 @@ EntryResult SimpleBackendImpl::OpenEntryFromHash(uint64_t entry_hash, net::Error SimpleBackendImpl::DoomEntryFromHash( uint64_t entry_hash, CompletionOnceCallback callback) { - Entry** entry = new Entry*(); - std::unique_ptr<Entry*> scoped_entry(entry); - std::vector<SimplePostDoomWaiter>* post_doom = post_doom_waiting_->Find(entry_hash); if (post_doom) { diff --git a/chromium/net/disk_cache/simple/simple_backend_impl.h b/chromium/net/disk_cache/simple/simple_backend_impl.h index 46859670b34..84ca265f3ef 100644 --- a/chromium/net/disk_cache/simple/simple_backend_impl.h +++ b/chromium/net/disk_cache/simple/simple_backend_impl.h @@ -63,6 +63,7 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, // Note: only pass non-nullptr for |file_tracker| if you don't want the global // one (which things other than tests would want). |file_tracker| must outlive // the backend and all the entries, including their asynchronous close. + // |Init()| must be called to finish the initialization process. SimpleBackendImpl( scoped_refptr<BackendFileOperationsFactory> file_operations_factory, const base::FilePath& path, @@ -79,7 +80,8 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, void SetTaskRunnerForTesting( scoped_refptr<base::SequencedTaskRunner> task_runner); - net::Error Init(CompletionOnceCallback completion_callback); + // Finishes initialization. Always asynchronous. + void Init(CompletionOnceCallback completion_callback); // Sets the maximum size for the total amount of data stored by this instance. bool SetMaxSize(int64_t max_bytes); diff --git a/chromium/net/disk_cache/simple/simple_entry_format_history.h b/chromium/net/disk_cache/simple/simple_entry_format_history.h index 3bcb8b44917..5936c8807d3 100644 --- a/chromium/net/disk_cache/simple/simple_entry_format_history.h +++ b/chromium/net/disk_cache/simple/simple_entry_format_history.h @@ -9,9 +9,7 @@ #include "net/base/net_export.h" -namespace disk_cache { - -namespace simplecache_v5 { +namespace disk_cache::simplecache_v5 { const uint64_t kSimpleInitialMagicNumber = UINT64_C(0xfcfb6d1ba7725c30); const uint64_t kSimpleFinalMagicNumber = UINT64_C(0xf4fa6f45970d41d8); @@ -55,8 +53,6 @@ struct NET_EXPORT_PRIVATE SimpleFileEOF { uint32_t stream_size; }; -} // namespace simplecache_v5 - -} // namespace disk_cache +} // namespace disk_cache::simplecache_v5 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_HISTORY_H_ diff --git a/chromium/net/disk_cache/simple/simple_entry_impl.cc b/chromium/net/disk_cache/simple/simple_entry_impl.cc index 116ce16838c..02d2005d86e 100644 --- a/chromium/net/disk_cache/simple/simple_entry_impl.cc +++ b/chromium/net/disk_cache/simple/simple_entry_impl.cc @@ -788,9 +788,8 @@ void SimpleEntryImpl::OpenEntryInternal( DCHECK(!synchronous_entry_); state_ = STATE_IO_PENDING; const base::TimeTicks start_time = base::TimeTicks::Now(); - std::unique_ptr<SimpleEntryCreationResults> results( - new SimpleEntryCreationResults(SimpleEntryStat( - last_used_, last_modified_, data_size_, sparse_data_size_))); + auto results = std::make_unique<SimpleEntryCreationResults>(SimpleEntryStat( + last_used_, last_modified_, data_size_, sparse_data_size_)); int32_t trailer_prefetch_size = -1; base::Time last_used_time; @@ -846,9 +845,8 @@ void SimpleEntryImpl::CreateEntryInternal( last_used_ = last_modified_ = base::Time::Now(); const base::TimeTicks start_time = base::TimeTicks::Now(); - std::unique_ptr<SimpleEntryCreationResults> results( - new SimpleEntryCreationResults(SimpleEntryStat( - last_used_, last_modified_, data_size_, sparse_data_size_))); + auto results = std::make_unique<SimpleEntryCreationResults>(SimpleEntryStat( + last_used_, last_modified_, data_size_, sparse_data_size_)); OnceClosure task = base::BindOnce(&SimpleSynchronousEntry::CreateEntry, cache_type_, path_, @@ -897,9 +895,8 @@ void SimpleEntryImpl::OpenOrCreateEntryInternal( DCHECK(!synchronous_entry_); state_ = STATE_IO_PENDING; const base::TimeTicks start_time = base::TimeTicks::Now(); - std::unique_ptr<SimpleEntryCreationResults> results( - new SimpleEntryCreationResults(SimpleEntryStat( - last_used_, last_modified_, data_size_, sparse_data_size_))); + auto results = std::make_unique<SimpleEntryCreationResults>(SimpleEntryStat( + last_used_, last_modified_, data_size_, sparse_data_size_)); int32_t trailer_prefetch_size = -1; base::Time last_used_time; @@ -937,8 +934,7 @@ void SimpleEntryImpl::CloseInternal() { } typedef SimpleSynchronousEntry::CRCRecord CRCRecord; - std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write( - new std::vector<CRCRecord>()); + auto crc32s_to_write = std::make_unique<std::vector<CRCRecord>>(); net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_BEGIN); @@ -959,8 +955,7 @@ void SimpleEntryImpl::CloseInternal() { DCHECK(STATE_UNINITIALIZED == state_ || STATE_FAILURE == state_); } - std::unique_ptr<SimpleEntryCloseResults> results = - std::make_unique<SimpleEntryCloseResults>(); + auto results = std::make_unique<SimpleEntryCloseResults>(); if (synchronous_entry_) { OnceClosure task = base::BindOnce( &SimpleSynchronousEntry::Close, base::Unretained(synchronous_entry_), @@ -1049,10 +1044,9 @@ int SimpleEntryImpl::ReadDataInternal(bool sync_possible, read_req.request_verify_crc = !have_written_[stream_index]; } - std::unique_ptr<SimpleSynchronousEntry::ReadResult> result = - std::make_unique<SimpleSynchronousEntry::ReadResult>(); - std::unique_ptr<SimpleEntryStat> entry_stat(new SimpleEntryStat( - last_used_, last_modified_, data_size_, sparse_data_size_)); + auto result = std::make_unique<SimpleSynchronousEntry::ReadResult>(); + auto entry_stat = std::make_unique<SimpleEntryStat>( + last_used_, last_modified_, data_size_, sparse_data_size_); OnceClosure task = base::BindOnce( &SimpleSynchronousEntry::ReadData, base::Unretained(synchronous_entry_), read_req, entry_stat.get(), base::RetainedRef(buf), result.get()); @@ -1139,8 +1133,8 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, } // |entry_stat| needs to be initialized before modifying |data_size_|. - std::unique_ptr<SimpleEntryStat> entry_stat(new SimpleEntryStat( - last_used_, last_modified_, data_size_, sparse_data_size_)); + auto entry_stat = std::make_unique<SimpleEntryStat>( + last_used_, last_modified_, data_size_, sparse_data_size_); if (truncate) { data_size_[stream_index] = offset + buf_len; } else { @@ -1148,8 +1142,7 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index, GetDataSize(stream_index)); } - std::unique_ptr<SimpleSynchronousEntry::WriteResult> write_result = - std::make_unique<SimpleSynchronousEntry::WriteResult>(); + auto write_result = std::make_unique<SimpleSynchronousEntry::WriteResult>(); // Since we don't know the correct values for |last_used_| and // |last_modified_| yet, we make this approximation. @@ -1212,8 +1205,8 @@ void SimpleEntryImpl::ReadSparseDataInternal( DCHECK_EQ(STATE_READY, state_); state_ = STATE_IO_PENDING; - std::unique_ptr<int> result(new int()); - std::unique_ptr<base::Time> last_used(new base::Time()); + auto result = std::make_unique<int>(); + auto last_used = std::make_unique<base::Time>(); OnceClosure task = base::BindOnce( &SimpleSynchronousEntry::ReadSparseData, base::Unretained(synchronous_entry_), @@ -1263,12 +1256,12 @@ void SimpleEntryImpl::WriteSparseDataInternal( max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; } - std::unique_ptr<SimpleEntryStat> entry_stat(new SimpleEntryStat( - last_used_, last_modified_, data_size_, sparse_data_size_)); + auto entry_stat = std::make_unique<SimpleEntryStat>( + last_used_, last_modified_, data_size_, sparse_data_size_); last_used_ = last_modified_ = base::Time::Now(); - std::unique_ptr<int> result(new int()); + auto result = std::make_unique<int>(); OnceClosure task = base::BindOnce( &SimpleSynchronousEntry::WriteSparseData, base::Unretained(synchronous_entry_), @@ -1405,8 +1398,8 @@ void SimpleEntryImpl::CreationOperationComplete( // If this is a successful creation (rather than open), mark all streams to be // saved on close. if (in_results->created) { - for (int i = 0; i < kSimpleEntryStreamCount; ++i) - have_written_[i] = true; + for (bool& have_written : have_written_) + have_written = true; } // Make sure to keep the index up-to-date. We likely already did this when @@ -1460,9 +1453,15 @@ void SimpleEntryImpl::CreationOperationComplete( net_log_.AddEvent(end_event_type); + const bool created = in_results->created; + + // We need to release `in_results` before going out of scope, because + // `operation_runner` destruction might call a close operation, that will + // ultimately release `in_results->sync_entry`, and thus leading to having a + // dangling pointer here. + in_results = nullptr; if (result_state == SimpleEntryOperation::ENTRY_NEEDS_CALLBACK) { - ReturnEntryToCallerAsync(!in_results->created, - std::move(completion_callback)); + ReturnEntryToCallerAsync(!created, std::move(completion_callback)); } } @@ -1657,9 +1656,8 @@ void SimpleEntryImpl::UpdateDataFromEntryStat( int64_t SimpleEntryImpl::GetDiskUsage() const { int64_t file_size = 0; - for (int i = 0; i < kSimpleEntryStreamCount; ++i) { - file_size += - simple_util::GetFileSizeFromDataSize(key_.size(), data_size_[i]); + for (int data_size : data_size_) { + file_size += simple_util::GetFileSizeFromDataSize(key_.size(), data_size); } file_size += sparse_data_size_; return file_size; diff --git a/chromium/net/disk_cache/simple/simple_file_tracker.cc b/chromium/net/disk_cache/simple/simple_file_tracker.cc index 45a783052a3..7560a8622cc 100644 --- a/chromium/net/disk_cache/simple/simple_file_tracker.cc +++ b/chromium/net/disk_cache/simple/simple_file_tracker.cc @@ -63,7 +63,7 @@ void SimpleFileTracker::Register(const SimpleSynchronousEntry* owner, } if (!owners_files) { - candidates.emplace_back(new TrackedFiles()); + candidates.emplace_back(std::make_unique<TrackedFiles>()); owners_files = candidates.back().get(); owners_files->owner = owner; owners_files->key = owner->entry_file_key(); diff --git a/chromium/net/disk_cache/simple/simple_file_tracker.h b/chromium/net/disk_cache/simple/simple_file_tracker.h index d9bf2d0682c..3262bd75b00 100644 --- a/chromium/net/disk_cache/simple/simple_file_tracker.h +++ b/chromium/net/disk_cache/simple/simple_file_tracker.h @@ -75,7 +75,7 @@ class NET_EXPORT_PRIVATE SimpleFileTracker { }; struct EntryFileKey { - EntryFileKey() {} + EntryFileKey() = default; explicit EntryFileKey(uint64_t hash) : entry_hash(hash) {} uint64_t entry_hash = 0; @@ -90,7 +90,7 @@ class NET_EXPORT_PRIVATE SimpleFileTracker { // The default limit here is half of what's available on our target OS where // Chrome has the lowest limit. - SimpleFileTracker(int file_limit = 512); + explicit SimpleFileTracker(int file_limit = 512); SimpleFileTracker(const SimpleFileTracker&) = delete; SimpleFileTracker& operator=(const SimpleFileTracker&) = delete; diff --git a/chromium/net/disk_cache/simple/simple_file_tracker_unittest.cc b/chromium/net/disk_cache/simple/simple_file_tracker_unittest.cc index ec501d7d631..0708ac9f31c 100644 --- a/chromium/net/disk_cache/simple/simple_file_tracker_unittest.cc +++ b/chromium/net/disk_cache/simple/simple_file_tracker_unittest.cc @@ -38,7 +38,8 @@ class SimpleFileTrackerTest : public DiskCacheTest { // create/delete SimpleSynchronousEntry objects. class SyncEntryDeleter { public: - SyncEntryDeleter(SimpleFileTrackerTest* fixture) : fixture_(fixture) {} + explicit SyncEntryDeleter(SimpleFileTrackerTest* fixture) + : fixture_(fixture) {} void operator()(SimpleSynchronousEntry* entry) { fixture_->DeleteSyncEntry(entry); } @@ -230,8 +231,8 @@ TEST_F(SimpleFileTrackerTest, PointerStability) { borrow->Write(0, msg.data(), msg.size())); } - for (int i = 0; i < kEntries; ++i) - file_tracker_.Close(entries[i].get(), SimpleFileTracker::SubFile::FILE_0); + for (const auto& entry : entries) + file_tracker_.Close(entry.get(), SimpleFileTracker::SubFile::FILE_0); // Verify the file. std::string verify; diff --git a/chromium/net/disk_cache/simple/simple_index.cc b/chromium/net/disk_cache/simple/simple_index.cc index 044df008225..10f9e62153e 100644 --- a/chromium/net/disk_cache/simple/simple_index.cc +++ b/chromium/net/disk_cache/simple/simple_index.cc @@ -193,10 +193,8 @@ SimpleIndex::~SimpleIndex() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // Fail all callbacks waiting for the index to come up. - for (auto it = to_run_when_initialized_.begin(), - end = to_run_when_initialized_.end(); - it != end; ++it) { - std::move(*it).Run(net::ERR_ABORTED); + for (auto& callback : to_run_when_initialized_) { + std::move(callback).Run(net::ERR_ABORTED); } } @@ -215,12 +213,13 @@ void SimpleIndex::Initialize(base::Time cache_mtime) { } #endif - SimpleIndexLoadResult* load_result = new SimpleIndexLoadResult(); - std::unique_ptr<SimpleIndexLoadResult> load_result_scoped(load_result); - base::OnceClosure reply = + auto load_result = std::make_unique<SimpleIndexLoadResult>(); + auto* load_result_ptr = load_result.get(); + index_file_->LoadIndexEntries( + cache_mtime, base::BindOnce(&SimpleIndex::MergeInitializingSet, AsWeakPtr(), - std::move(load_result_scoped)); - index_file_->LoadIndexEntries(cache_mtime, std::move(reply), load_result); + std::move(load_result)), + load_result_ptr); } void SimpleIndex::SetMaxSize(uint64_t max_bytes) { @@ -258,7 +257,7 @@ std::unique_ptr<SimpleIndex::HashList> SimpleIndex::GetEntriesBetween( end_time += EntryMetadata::GetUpperEpsilonForTimeComparisons(); DCHECK(end_time >= initial_time); - std::unique_ptr<HashList> ret_hashes(new HashList()); + auto ret_hashes = std::make_unique<HashList>(); for (const auto& entry : entries_set_) { const EntryMetadata& metadata = entry.second; base::Time entry_time = metadata.GetLastUsedTime(); @@ -546,25 +545,23 @@ void SimpleIndex::MergeInitializingSet( EntrySet* index_file_entries = &load_result->entries; - for (auto it = removed_entries_.begin(); it != removed_entries_.end(); ++it) { - index_file_entries->erase(*it); + for (uint64_t removed_entry : removed_entries_) { + index_file_entries->erase(removed_entry); } removed_entries_.clear(); - for (EntrySet::const_iterator it = entries_set_.begin(); - it != entries_set_.end(); ++it) { - const uint64_t entry_hash = it->first; + for (const auto& it : entries_set_) { + const uint64_t entry_hash = it.first; std::pair<EntrySet::iterator, bool> insert_result = index_file_entries->insert(EntrySet::value_type(entry_hash, EntryMetadata())); EntrySet::iterator& possibly_inserted_entry = insert_result.first; - possibly_inserted_entry->second = it->second; + possibly_inserted_entry->second = it.second; } uint64_t merged_cache_size = 0; - for (auto it = index_file_entries->begin(); it != index_file_entries->end(); - ++it) { - merged_cache_size += it->second.GetEntrySize(); + for (const auto& index_file_entry : *index_file_entries) { + merged_cache_size += index_file_entry.second.GetEntrySize(); } entries_set_.swap(*index_file_entries); @@ -587,10 +584,9 @@ void SimpleIndex::MergeInitializingSet( static_cast<base::HistogramBase::Sample>(max_size_ / kBytesInKb)); // Run all callbacks waiting for the index to come up. - for (auto it = to_run_when_initialized_.begin(), - end = to_run_when_initialized_.end(); - it != end; ++it) { - task_runner_->PostTask(FROM_HERE, base::BindOnce(std::move(*it), net::OK)); + for (auto& callback : to_run_when_initialized_) { + task_runner_->PostTask(FROM_HERE, + base::BindOnce(std::move(callback), net::OK)); } to_run_when_initialized_.clear(); } diff --git a/chromium/net/disk_cache/simple/simple_index_delegate.h b/chromium/net/disk_cache/simple/simple_index_delegate.h index 0ff77c29a08..00e02a8c987 100644 --- a/chromium/net/disk_cache/simple/simple_index_delegate.h +++ b/chromium/net/disk_cache/simple/simple_index_delegate.h @@ -16,7 +16,7 @@ namespace disk_cache { class NET_EXPORT_PRIVATE SimpleIndexDelegate { public: - virtual ~SimpleIndexDelegate() {} + virtual ~SimpleIndexDelegate() = default; // Dooms all entries in |entries|, calling |callback| with the result // asynchronously. |entries| is mutated in an undefined way by this call, diff --git a/chromium/net/disk_cache/simple/simple_index_file.cc b/chromium/net/disk_cache/simple/simple_index_file.cc index c60d833fe4d..bc36558d2cc 100644 --- a/chromium/net/disk_cache/simple/simple_index_file.cc +++ b/chromium/net/disk_cache/simple/simple_index_file.cc @@ -518,9 +518,9 @@ std::unique_ptr<base::Pickle> SimpleIndexFile::Serialize( std::unique_ptr<base::Pickle> pickle = std::make_unique<SimpleIndexPickle>(); index_metadata.Serialize(pickle.get()); - for (auto it = entries.begin(); it != entries.end(); ++it) { - pickle->WriteUInt64(it->first); - it->second.Serialize(cache_type, pickle.get()); + for (const auto& entry : entries) { + pickle->WriteUInt64(entry.first); + entry.second.Serialize(cache_type, pickle.get()); } return pickle; } diff --git a/chromium/net/disk_cache/simple/simple_index_file_unittest.cc b/chromium/net/disk_cache/simple/simple_index_file_unittest.cc index ebf2de335e8..7802c98675f 100644 --- a/chromium/net/disk_cache/simple/simple_index_file_unittest.cc +++ b/chromium/net/disk_cache/simple/simple_index_file_unittest.cc @@ -493,8 +493,8 @@ TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) { EXPECT_FALSE(load_index_result.flush_required); EXPECT_EQ(kNumHashes, load_index_result.entries.size()); - for (size_t i = 0; i < kNumHashes; ++i) - EXPECT_EQ(1U, load_index_result.entries.count(kHashes[i])); + for (uint64_t hash : kHashes) + EXPECT_EQ(1U, load_index_result.entries.count(hash)); } TEST_F(SimpleIndexFileTest, LoadCorruptIndex) { @@ -603,10 +603,10 @@ TEST_F(SimpleIndexFileTest, SimpleCacheUpgrade) { /*file_tracker=*/nullptr, 0, net::DISK_CACHE, /*net_log=*/nullptr); net::TestCompletionCallback cb; - int rv = simple_cache->Init(cb.callback()); - EXPECT_THAT(cb.GetResult(rv), IsOk()); + simple_cache->Init(cb.callback()); + EXPECT_THAT(cb.WaitForResult(), IsOk()); simple_cache->index()->ExecuteWhenReady(cb.callback()); - rv = cb.WaitForResult(); + int rv = cb.WaitForResult(); EXPECT_THAT(rv, IsOk()); simple_cache.reset(); cleanup_tracker = nullptr; diff --git a/chromium/net/disk_cache/simple/simple_index_unittest.cc b/chromium/net/disk_cache/simple/simple_index_unittest.cc index 92cde3b83ed..34d2266fed9 100644 --- a/chromium/net/disk_cache/simple/simple_index_unittest.cc +++ b/chromium/net/disk_cache/simple/simple_index_unittest.cc @@ -114,8 +114,7 @@ class SimpleIndexTest : public net::TestWithTaskEnvironment, } void SetUp() override { - std::unique_ptr<MockSimpleIndexFile> index_file( - new MockSimpleIndexFile(CacheType())); + auto index_file = std::make_unique<MockSimpleIndexFile>(CacheType()); index_file_ = index_file->AsWeakPtr(); index_ = std::make_unique<SimpleIndex>(/* io_thread = */ nullptr, @@ -263,13 +262,13 @@ TEST_F(SimpleIndexTest, IndexSizeCorrectOnMerge) { index()->UpdateEntrySize(hashes_.at<4>(), 4u * kSizeResolution); EXPECT_EQ(9u * kSizeResolution, index()->cache_size_); { - std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); + auto result = std::make_unique<SimpleIndexLoadResult>(); result->did_load = true; index()->MergeInitializingSet(std::move(result)); } EXPECT_EQ(9u * kSizeResolution, index()->cache_size_); { - std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); + auto result = std::make_unique<SimpleIndexLoadResult>(); result->did_load = true; const uint64_t new_hash_key = hashes_.at<11>(); result->entries.insert(std::make_pair( diff --git a/chromium/net/disk_cache/simple/simple_net_log_parameters.cc b/chromium/net/disk_cache/simple/simple_net_log_parameters.cc index ee3241ba989..b6d06026193 100644 --- a/chromium/net/disk_cache/simple/simple_net_log_parameters.cc +++ b/chromium/net/disk_cache/simple/simple_net_log_parameters.cc @@ -20,20 +20,20 @@ namespace { base::Value NetLogSimpleEntryConstructionParams( const disk_cache::SimpleEntryImpl* entry) { - base::Value dict(base::Value::Type::DICTIONARY); - dict.SetStringKey("entry_hash", - base::StringPrintf("%#016" PRIx64, entry->entry_hash())); - return dict; + base::Value::Dict dict; + dict.Set("entry_hash", + base::StringPrintf("%#016" PRIx64, entry->entry_hash())); + return base::Value(std::move(dict)); } base::Value NetLogSimpleEntryCreationParams( const disk_cache::SimpleEntryImpl* entry, int net_error) { - base::Value dict(base::Value::Type::DICTIONARY); - dict.SetIntKey("net_error", net_error); + base::Value::Dict dict; + dict.Set("net_error", net_error); if (net_error == net::OK) - dict.SetStringKey("key", entry->key()); - return dict; + dict.Set("key", entry->key()); + return base::Value(std::move(dict)); } } // namespace diff --git a/chromium/net/disk_cache/simple/simple_synchronous_entry.cc b/chromium/net/disk_cache/simple/simple_synchronous_entry.cc index 4102a28ba2f..8ac5d028cdf 100644 --- a/chromium/net/disk_cache/simple/simple_synchronous_entry.cc +++ b/chromium/net/disk_cache/simple/simple_synchronous_entry.cc @@ -1067,8 +1067,8 @@ void SimpleSynchronousEntry::Close( base::ElapsedTimer close_time; DCHECK(stream_0_data); - for (auto it = crc32s_to_write->begin(); it != crc32s_to_write->end(); ++it) { - const int stream_index = it->index; + for (auto& crc_record : *crc32s_to_write) { + const int stream_index = crc_record.index; const int file_index = GetFileIndexFromStreamIndex(stream_index); if (empty_file_omitted_[file_index]) continue; @@ -1103,10 +1103,10 @@ void SimpleSynchronousEntry::Close( // Re-compute stream 0 CRC if the data got changed (we may be here even // if it didn't change if stream 0's position on disk got changed due to // stream 1 write). - if (!it->has_crc32) { - it->data_crc32 = + if (!crc_record.has_crc32) { + crc_record.data_crc32 = simple_util::Crc32(stream_0_data->data(), entry_stat.data_size(0)); - it->has_crc32 = true; + crc_record.has_crc32 = true; } out_results->estimated_trailer_prefetch_size = @@ -1117,11 +1117,11 @@ void SimpleSynchronousEntry::Close( eof_record.stream_size = entry_stat.data_size(stream_index); eof_record.final_magic_number = kSimpleFinalMagicNumber; eof_record.flags = 0; - if (it->has_crc32) + if (crc_record.has_crc32) eof_record.flags |= SimpleFileEOF::FLAG_HAS_CRC32; if (stream_index == 0) eof_record.flags |= SimpleFileEOF::FLAG_HAS_KEY_SHA256; - eof_record.data_crc32 = it->data_crc32; + eof_record.data_crc32 = crc_record.data_crc32; int eof_offset = entry_stat.GetEOFOffsetInFile(key_.size(), stream_index); // If stream 0 changed size, the file needs to be resized, otherwise the // next open will yield wrong stream sizes. On stream 1 and stream 2 proper @@ -1179,8 +1179,9 @@ SimpleSynchronousEntry::SimpleSynchronousEntry( file_tracker_(file_tracker), unbound_file_operations_(std::move(unbound_file_operations)), trailer_prefetch_size_(trailer_prefetch_size) { - for (int i = 0; i < kSimpleEntryNormalFileCount; ++i) - empty_file_omitted_[i] = false; + for (bool& empty_file_omitted : empty_file_omitted_) { + empty_file_omitted = false; + } } SimpleSynchronousEntry::~SimpleSynchronousEntry() { diff --git a/chromium/net/disk_cache/simple/simple_test_util.cc b/chromium/net/disk_cache/simple/simple_test_util.cc index 0251f3ad914..d62320e0690 100644 --- a/chromium/net/disk_cache/simple/simple_test_util.cc +++ b/chromium/net/disk_cache/simple/simple_test_util.cc @@ -10,8 +10,7 @@ #include "net/disk_cache/simple/simple_entry_format.h" #include "net/disk_cache/simple/simple_util.h" -namespace disk_cache { -namespace simple_util { +namespace disk_cache::simple_util { using base::File; using base::FilePath; @@ -131,5 +130,4 @@ bool CorruptStream0LengthFromEntry(const std::string& key, return true; } -} // namespace simple_util -} // namespace disk_cache +} // namespace disk_cache::simple_util diff --git a/chromium/net/disk_cache/simple/simple_test_util.h b/chromium/net/disk_cache/simple/simple_test_util.h index 36af9285b9c..701e1eb3a85 100644 --- a/chromium/net/disk_cache/simple/simple_test_util.h +++ b/chromium/net/disk_cache/simple/simple_test_util.h @@ -15,8 +15,7 @@ namespace base { class FilePath; } -namespace disk_cache { -namespace simple_util { +namespace disk_cache::simple_util { // Immutable array with compile-time bound-checking. template <typename T, size_t Size> @@ -24,7 +23,8 @@ class ImmutableArray { public: static const size_t size = Size; - ImmutableArray(const base::RepeatingCallback<T(size_t index)>& initializer) { + explicit ImmutableArray( + const base::RepeatingCallback<T(size_t index)>& initializer) { for (size_t i = 0; i < size; ++i) data_[i] = initializer.Run(i); } @@ -55,7 +55,6 @@ bool CorruptKeySHA256FromEntry(const std::string& key, bool CorruptStream0LengthFromEntry(const std::string& key, const base::FilePath& cache_path); -} // namespace simple_util -} // namespace disk_cache +} // namespace disk_cache::simple_util #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_TEST_UTIL_H_ diff --git a/chromium/net/disk_cache/simple/simple_util.cc b/chromium/net/disk_cache/simple/simple_util.cc index d9fc89080fc..ed0b382221d 100644 --- a/chromium/net/disk_cache/simple/simple_util.cc +++ b/chromium/net/disk_cache/simple/simple_util.cc @@ -25,9 +25,7 @@ const size_t kEntryHashKeyAsHexStringSize = 2 * sizeof(uint64_t); } // namespace -namespace disk_cache { - -namespace simple_util { +namespace disk_cache::simple_util { std::string ConvertEntryHashKeyToHexString(uint64_t hash_key) { const std::string hash_key_str = base::StringPrintf("%016" PRIx64, hash_key); @@ -115,6 +113,4 @@ uint32_t IncrementalCrc32(uint32_t previous_crc, const char* data, int length) { return crc32(previous_crc, reinterpret_cast<const Bytef*>(data), length); } -} // namespace simple_util - -} // namespace disk_cache +} // namespace disk_cache::simple_util diff --git a/chromium/net/disk_cache/simple/simple_util.h b/chromium/net/disk_cache/simple/simple_util.h index b74632139ae..6860e39350d 100644 --- a/chromium/net/disk_cache/simple/simple_util.h +++ b/chromium/net/disk_cache/simple/simple_util.h @@ -17,9 +17,7 @@ namespace base { class FilePath; } -namespace disk_cache { - -namespace simple_util { +namespace disk_cache::simple_util { NET_EXPORT_PRIVATE std::string ConvertEntryHashKeyToHexString( uint64_t hash_key); @@ -83,8 +81,6 @@ uint32_t Crc32(const char* data, int length); uint32_t IncrementalCrc32(uint32_t previous_crc, const char* data, int length); -} // namespace simple_util - -} // namespace disk_cache +} // namespace disk_cache::simple_util #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_UTIL_H_ diff --git a/chromium/net/disk_cache/simple/simple_util_posix.cc b/chromium/net/disk_cache/simple/simple_util_posix.cc index 129b9ee7cd7..0a72be27c39 100644 --- a/chromium/net/disk_cache/simple/simple_util_posix.cc +++ b/chromium/net/disk_cache/simple/simple_util_posix.cc @@ -6,12 +6,10 @@ #include "base/files/file_util.h" -namespace disk_cache { -namespace simple_util { +namespace disk_cache::simple_util { bool SimpleCacheDeleteFile(const base::FilePath& path) { return base::DeleteFile(path); } -} // namespace simple_util -} // namespace disk_cache +} // namespace disk_cache::simple_util |