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

Side by Side Diff: net/disk_cache/storage_block-inl.h

Issue 8658001: Disk cache: Add a hash to the entry's internal data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_DISK_CACHE_STORAGE_BLOCK_INL_H_ 5 #ifndef NET_DISK_CACHE_STORAGE_BLOCK_INL_H_
6 #define NET_DISK_CACHE_STORAGE_BLOCK_INL_H_ 6 #define NET_DISK_CACHE_STORAGE_BLOCK_INL_H_
7 #pragma once 7 #pragma once
8 8
9 #include "net/disk_cache/storage_block.h" 9 #include "net/disk_cache/storage_block.h"
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "net/disk_cache/hash.h"
12 #include "net/disk_cache/trace.h" 13 #include "net/disk_cache/trace.h"
13 14
14 namespace disk_cache { 15 namespace disk_cache {
15 16
16 template<typename T> StorageBlock<T>::StorageBlock(MappedFile* file, 17 template<typename T> StorageBlock<T>::StorageBlock(MappedFile* file,
17 Addr address) 18 Addr address)
18 : data_(NULL), file_(file), address_(address), modified_(false), 19 : data_(NULL), file_(file), address_(address), modified_(false),
19 own_data_(false), extended_(false) { 20 own_data_(false), extended_(false) {
20 if (address.num_blocks() > 1) 21 if (address.num_blocks() > 1)
21 extended_ = true; 22 extended_ = true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 template<typename T> T* StorageBlock<T>::Data() { 92 template<typename T> T* StorageBlock<T>::Data() {
92 if (!data_) 93 if (!data_)
93 AllocateData(); 94 AllocateData();
94 return data_; 95 return data_;
95 } 96 }
96 97
97 template<typename T> bool StorageBlock<T>::HasData() const { 98 template<typename T> bool StorageBlock<T>::HasData() const {
98 return (NULL != data_); 99 return (NULL != data_);
99 } 100 }
100 101
102 template<typename T> bool StorageBlock<T>::VerifyHash() const {
103 uint32 hash = CalculateHash();
104 return (!data_->self_hash || data_->self_hash == hash);
105 }
106
101 template<typename T> bool StorageBlock<T>::own_data() const { 107 template<typename T> bool StorageBlock<T>::own_data() const {
102 return own_data_; 108 return own_data_;
103 } 109 }
104 110
105 template<typename T> const Addr StorageBlock<T>::address() const { 111 template<typename T> const Addr StorageBlock<T>::address() const {
106 return address_; 112 return address_;
107 } 113 }
108 114
109 template<typename T> bool StorageBlock<T>::Load() { 115 template<typename T> bool StorageBlock<T>::Load() {
110 if (file_) { 116 if (file_) {
111 if (!data_) 117 if (!data_)
112 AllocateData(); 118 AllocateData();
113 119
114 if (file_->Load(this)) { 120 if (file_->Load(this)) {
115 modified_ = false; 121 modified_ = false;
116 return true; 122 return true;
117 } 123 }
118 } 124 }
119 LOG(WARNING) << "Failed data load."; 125 LOG(WARNING) << "Failed data load.";
120 Trace("Failed data load."); 126 Trace("Failed data load.");
121 return false; 127 return false;
122 } 128 }
123 129
124 template<typename T> bool StorageBlock<T>::Store() { 130 template<typename T> bool StorageBlock<T>::Store() {
125 if (file_ && data_) { 131 if (file_ && data_) {
132 data_->self_hash = CalculateHash();
126 if (file_->Store(this)) { 133 if (file_->Store(this)) {
127 modified_ = false; 134 modified_ = false;
128 return true; 135 return true;
129 } 136 }
130 } 137 }
131 LOG(ERROR) << "Failed data store."; 138 LOG(ERROR) << "Failed data store.";
132 Trace("Failed data store."); 139 Trace("Failed data store.");
133 return false; 140 return false;
134 } 141 }
135 142
(...skipping 13 matching lines...) Expand all
149 if (!extended_) { 156 if (!extended_) {
150 delete data_; 157 delete data_;
151 } else { 158 } else {
152 data_->~T(); 159 data_->~T();
153 delete[] reinterpret_cast<char*>(data_); 160 delete[] reinterpret_cast<char*>(data_);
154 } 161 }
155 own_data_ = false; 162 own_data_ = false;
156 } 163 }
157 } 164 }
158 165
166 template<typename T> uint32 StorageBlock<T>::CalculateHash() const {
167 return Hash(reinterpret_cast<char*>(data_), offsetof(T, self_hash));
168 }
169
159 } // namespace disk_cache 170 } // namespace disk_cache
160 171
161 #endif // NET_DISK_CACHE_STORAGE_BLOCK_INL_H_ 172 #endif // NET_DISK_CACHE_STORAGE_BLOCK_INL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698