Commit abd72909 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Use base::PersistentHash() in //net/disk_cache

Disk cache is, by definition, persisted, so use base::PersistentHash(),
which currently has the exact same behavior as base::Hash(), but is
actually guaranteed not to change.

Bug: 1025358
Change-Id: I43c53197d97c7781ef0fcfbacb89cdb214abc24e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1924603Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarAdenilson Cavalcanti <cavalcantii@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716939}
parent cbe377d8
...@@ -498,7 +498,7 @@ void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { ...@@ -498,7 +498,7 @@ void BackendImpl::SyncOnExternalCacheHit(const std::string& key) {
if (disabled_) if (disabled_)
return; return;
uint32_t hash = base::Hash(key); uint32_t hash = base::PersistentHash(key);
bool error; bool error;
scoped_refptr<EntryImpl> cache_entry = scoped_refptr<EntryImpl> cache_entry =
MatchEntry(key, hash, false, Addr(), &error); MatchEntry(key, hash, false, Addr(), &error);
...@@ -511,7 +511,7 @@ scoped_refptr<EntryImpl> BackendImpl::OpenEntryImpl(const std::string& key) { ...@@ -511,7 +511,7 @@ scoped_refptr<EntryImpl> BackendImpl::OpenEntryImpl(const std::string& key) {
return nullptr; return nullptr;
TimeTicks start = TimeTicks::Now(); TimeTicks start = TimeTicks::Now();
uint32_t hash = base::Hash(key); uint32_t hash = base::PersistentHash(key);
Trace("Open hash 0x%x", hash); Trace("Open hash 0x%x", hash);
bool error; bool error;
...@@ -552,7 +552,7 @@ scoped_refptr<EntryImpl> BackendImpl::CreateEntryImpl(const std::string& key) { ...@@ -552,7 +552,7 @@ scoped_refptr<EntryImpl> BackendImpl::CreateEntryImpl(const std::string& key) {
return nullptr; return nullptr;
TimeTicks start = TimeTicks::Now(); TimeTicks start = TimeTicks::Now();
uint32_t hash = base::Hash(key); uint32_t hash = base::PersistentHash(key);
Trace("Create hash 0x%x", hash); Trace("Create hash 0x%x", hash);
scoped_refptr<EntryImpl> parent; scoped_refptr<EntryImpl> parent;
......
...@@ -648,7 +648,7 @@ bool EntryImpl::DataSanityCheck() { ...@@ -648,7 +648,7 @@ bool EntryImpl::DataSanityCheck() {
if (!key_addr.is_initialized() && stored->key[stored->key_len]) if (!key_addr.is_initialized() && stored->key[stored->key_len])
return false; return false;
if (stored->hash != base::Hash(GetKey())) if (stored->hash != base::PersistentHash(GetKey()))
return false; return false;
for (int i = 0; i < kNumStreams; i++) { for (int i = 0; i < kNumStreams; i++) {
......
...@@ -217,7 +217,7 @@ template<typename T> void StorageBlock<T>::DeleteData() { ...@@ -217,7 +217,7 @@ template<typename T> void StorageBlock<T>::DeleteData() {
template <typename T> template <typename T>
uint32_t StorageBlock<T>::CalculateHash() const { uint32_t StorageBlock<T>::CalculateHash() const {
return base::Hash(data_, offsetof(T, self_hash)); return base::PersistentHash(data_, offsetof(T, self_hash));
} }
} // namespace disk_cache } // namespace disk_cache
......
...@@ -437,7 +437,10 @@ TEST_F(DiskCachePerfTest, BlockfileHashes) { ...@@ -437,7 +437,10 @@ TEST_F(DiskCachePerfTest, BlockfileHashes) {
base::ElapsedTimer timer; base::ElapsedTimer timer;
for (int i = 0; i < 300000; i++) { for (int i = 0; i < 300000; i++) {
std::string key = GenerateKey(true); std::string key = GenerateKey(true);
base::Hash(key); // TODO(dcheng): It's unclear if this is sufficient to keep a sufficiently
// smart optimizer from simply discarding the function call if it realizes
// there are no side effects.
base::PersistentHash(key);
} }
reporter.AddResult(kMetricCacheKeysHashTimeMs, reporter.AddResult(kMetricCacheKeysHashTimeMs,
timer.Elapsed().InMillisecondsF()); timer.Elapsed().InMillisecondsF());
......
...@@ -1362,7 +1362,7 @@ bool SimpleSynchronousEntry::CheckHeaderAndKey(base::File* file, ...@@ -1362,7 +1362,7 @@ bool SimpleSynchronousEntry::CheckHeaderAndKey(base::File* file,
} }
char* key_data = header_data.data() + sizeof(*header); char* key_data = header_data.data() + sizeof(*header);
if (base::Hash(key_data, header->key_length) != header->key_hash) { if (base::PersistentHash(key_data, header->key_length) != header->key_hash) {
RecordSyncOpenResult(cache_type_, OPEN_ENTRY_KEY_HASH_MISMATCH); RecordSyncOpenResult(cache_type_, OPEN_ENTRY_KEY_HASH_MISMATCH);
return false; return false;
} }
...@@ -1483,7 +1483,7 @@ bool SimpleSynchronousEntry::InitializeCreatedFile( ...@@ -1483,7 +1483,7 @@ bool SimpleSynchronousEntry::InitializeCreatedFile(
header.version = kSimpleEntryVersionOnDisk; header.version = kSimpleEntryVersionOnDisk;
header.key_length = key_.size(); header.key_length = key_.size();
header.key_hash = base::Hash(key_); header.key_hash = base::PersistentHash(key_);
int bytes_written = int bytes_written =
file->Write(0, reinterpret_cast<char*>(&header), sizeof(header)); file->Write(0, reinterpret_cast<char*>(&header), sizeof(header));
...@@ -1873,7 +1873,7 @@ bool SimpleSynchronousEntry::InitializeSparseFile(base::File* sparse_file) { ...@@ -1873,7 +1873,7 @@ bool SimpleSynchronousEntry::InitializeSparseFile(base::File* sparse_file) {
header.initial_magic_number = kSimpleInitialMagicNumber; header.initial_magic_number = kSimpleInitialMagicNumber;
header.version = kSimpleVersion; header.version = kSimpleVersion;
header.key_length = key_.size(); header.key_length = key_.size();
header.key_hash = base::Hash(key_); header.key_hash = base::PersistentHash(key_);
int header_write_result = int header_write_result =
sparse_file->Write(0, reinterpret_cast<char*>(&header), sizeof(header)); sparse_file->Write(0, reinterpret_cast<char*>(&header), sizeof(header));
......
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