Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: net/disk_cache/entry_impl.cc

Issue 165030: Disk Cache: Don't depend on the backend being enabled to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/entry_impl.h ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/entry_impl.cc
===================================================================
--- net/disk_cache/entry_impl.cc (revision 22579)
+++ net/disk_cache/entry_impl.cc (working copy)
@@ -84,6 +84,7 @@
for (int i = 0; i < kNumStreams; i++) {
unreported_size_[i] = 0;
}
+ key_file_ = NULL;
}
// When an entry is deleted from the cache, we clean up all the data associated
@@ -139,25 +140,29 @@
std::string EntryImpl::GetKey() const {
CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_);
- if (entry->Data()->key_len > kMaxInternalKeyLength) {
- Addr address(entry->Data()->long_key);
- DCHECK(address.is_initialized());
- COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
- File* file = const_cast<EntryImpl*>(this)->GetBackingFile(address,
- kKeyFileIndex);
+ if (entry->Data()->key_len <= kMaxInternalKeyLength)
+ return std::string(entry->Data()->key);
- size_t offset = 0;
- if (address.is_block_file())
- offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
+ Addr address(entry->Data()->long_key);
+ DCHECK(address.is_initialized());
+ size_t offset = 0;
+ if (address.is_block_file())
+ offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
- std::string key;
- if (!file || !file->Read(WriteInto(&key, entry->Data()->key_len + 1),
- entry->Data()->key_len + 1, offset))
- key.clear();
- return key;
- } else {
- return std::string(entry->Data()->key);
+ if (!key_file_) {
+ // We keep a copy of the file needed to access the key so that we can
+ // always return this object's key, even if the backend is disabled.
+ COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index);
+ key_file_ = const_cast<EntryImpl*>(this)->GetBackingFile(address,
+ kKeyFileIndex);
}
+
+ std::string key;
+ if (!key_file_ ||
+ !key_file_->Read(WriteInto(&key, entry->Data()->key_len + 1),
+ entry->Data()->key_len + 1, offset))
+ key.clear();
+ return key;
}
Time EntryImpl::GetLastUsed() const {
@@ -402,19 +407,19 @@
return false;
entry_store->long_key = address.value();
- File* file = GetBackingFile(address, kKeyFileIndex);
+ key_file_ = GetBackingFile(address, kKeyFileIndex);
size_t offset = 0;
if (address.is_block_file())
offset = address.start_block() * address.BlockSize() + kBlockHeaderSize;
- if (!file || !file->Write(key.data(), key.size(), offset)) {
+ if (!key_file_ || !key_file_->Write(key.data(), key.size(), offset)) {
DeleteData(address, kKeyFileIndex);
return false;
}
if (address.is_separate_file())
- file->SetLength(key.size() + 1);
+ key_file_->SetLength(key.size() + 1);
} else {
memcpy(entry_store->key, key.data(), key.size());
entry_store->key[key.size()] = '\0';
« no previous file with comments | « net/disk_cache/entry_impl.h ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698