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_) { |