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

Unified Diff: net/disk_cache/storage_block-inl.h

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: IndexTable review Created 7 years, 1 month 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/storage_block.h ('k') | net/disk_cache/storage_block_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/storage_block-inl.h
===================================================================
--- net/disk_cache/storage_block-inl.h (revision 199883)
+++ net/disk_cache/storage_block-inl.h (working copy)
@@ -13,6 +13,14 @@
namespace disk_cache {
+template<typename T> StorageBlock<T>::StorageBlock()
+ : data_(NULL),
+ file_(NULL),
+ modified_(false),
+ own_data_(false),
+ extended_(false) {
+}
+
template<typename T> StorageBlock<T>::StorageBlock(MappedFile* file,
Addr address)
: data_(NULL), file_(file), address_(address), modified_(false),
@@ -98,6 +106,18 @@
return data_;
}
+template<typename T> T* StorageBlock<T>::ReleaseData() {
+ if (!own_data_ || !data_)
+ return NULL;
+
+ data_->self_hash = CalculateHash();
+ T* result = data_;
+ data_ = NULL;
+ own_data_ = false;
+ modified_ = false;
+ return result;
+}
+
template<typename T> bool StorageBlock<T>::HasData() const {
return (NULL != data_);
}
@@ -107,6 +127,10 @@
return (!data_->self_hash || data_->self_hash == hash);
}
+template<typename T> void StorageBlock<T>::UpdateHash() {
+ data_->self_hash = CalculateHash();
+}
+
template<typename T> bool StorageBlock<T>::own_data() const {
return own_data_;
}
@@ -143,6 +167,36 @@
return false;
}
+template<typename T> bool StorageBlock<T>::Load(FileIOCallback* callback,
+ bool* completed) {
+ if (file_) {
+ if (!data_)
+ AllocateData();
+
+ if (file_->Load(this, callback, completed)) {
+ modified_ = false;
+ return true;
+ }
+ }
+ LOG(WARNING) << "Failed data load.";
+ Trace("Failed data load.");
+ return false;
+}
+
+template<typename T> bool StorageBlock<T>::Store(FileIOCallback* callback,
+ bool* completed) {
+ if (file_ && data_) {
+ data_->self_hash = CalculateHash();
+ if (file_->Store(this, callback, completed)) {
+ modified_ = false;
+ return true;
+ }
+ }
+ LOG(ERROR) << "Failed data store.";
+ Trace("Failed data store.");
+ return false;
+}
+
template<typename T> void StorageBlock<T>::AllocateData() {
DCHECK(!data_);
if (!extended_) {
« no previous file with comments | « net/disk_cache/storage_block.h ('k') | net/disk_cache/storage_block_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698