| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BLOCKFILE_STORAGE_BLOCK_INL_H_ | 5 #ifndef NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_INL_H_ |
| 6 #define NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_INL_H_ | 6 #define NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_INL_H_ |
| 7 | 7 |
| 8 #include "net/disk_cache/blockfile/storage_block.h" | 8 #include "net/disk_cache/blockfile/storage_block.h" |
| 9 | 9 |
| 10 #include <stddef.h> |
| 11 #include <stdint.h> |
| 12 |
| 10 #include "base/hash.h" | 13 #include "base/hash.h" |
| 11 #include "base/logging.h" | 14 #include "base/logging.h" |
| 12 #include "net/disk_cache/blockfile/trace.h" | 15 #include "net/disk_cache/blockfile/trace.h" |
| 13 | 16 |
| 14 namespace disk_cache { | 17 namespace disk_cache { |
| 15 | 18 |
| 16 template<typename T> StorageBlock<T>::StorageBlock(MappedFile* file, | 19 template<typename T> StorageBlock<T>::StorageBlock(MappedFile* file, |
| 17 Addr address) | 20 Addr address) |
| 18 : data_(NULL), file_(file), address_(address), modified_(false), | 21 : data_(NULL), file_(file), address_(address), modified_(false), |
| 19 own_data_(false), extended_(false) { | 22 own_data_(false), extended_(false) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 if (!data_) | 99 if (!data_) |
| 97 AllocateData(); | 100 AllocateData(); |
| 98 return data_; | 101 return data_; |
| 99 } | 102 } |
| 100 | 103 |
| 101 template<typename T> bool StorageBlock<T>::HasData() const { | 104 template<typename T> bool StorageBlock<T>::HasData() const { |
| 102 return (NULL != data_); | 105 return (NULL != data_); |
| 103 } | 106 } |
| 104 | 107 |
| 105 template<typename T> bool StorageBlock<T>::VerifyHash() const { | 108 template<typename T> bool StorageBlock<T>::VerifyHash() const { |
| 106 uint32 hash = CalculateHash(); | 109 uint32_t hash = CalculateHash(); |
| 107 return (!data_->self_hash || data_->self_hash == hash); | 110 return (!data_->self_hash || data_->self_hash == hash); |
| 108 } | 111 } |
| 109 | 112 |
| 110 template<typename T> bool StorageBlock<T>::own_data() const { | 113 template<typename T> bool StorageBlock<T>::own_data() const { |
| 111 return own_data_; | 114 return own_data_; |
| 112 } | 115 } |
| 113 | 116 |
| 114 template<typename T> const Addr StorageBlock<T>::address() const { | 117 template<typename T> const Addr StorageBlock<T>::address() const { |
| 115 return address_; | 118 return address_; |
| 116 } | 119 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if (!extended_) { | 192 if (!extended_) { |
| 190 delete data_; | 193 delete data_; |
| 191 } else { | 194 } else { |
| 192 data_->~T(); | 195 data_->~T(); |
| 193 delete[] reinterpret_cast<char*>(data_); | 196 delete[] reinterpret_cast<char*>(data_); |
| 194 } | 197 } |
| 195 own_data_ = false; | 198 own_data_ = false; |
| 196 } | 199 } |
| 197 } | 200 } |
| 198 | 201 |
| 199 template<typename T> uint32 StorageBlock<T>::CalculateHash() const { | 202 template <typename T> |
| 203 uint32_t StorageBlock<T>::CalculateHash() const { |
| 200 return base::Hash(reinterpret_cast<char*>(data_), offsetof(T, self_hash)); | 204 return base::Hash(reinterpret_cast<char*>(data_), offsetof(T, self_hash)); |
| 201 } | 205 } |
| 202 | 206 |
| 203 } // namespace disk_cache | 207 } // namespace disk_cache |
| 204 | 208 |
| 205 #endif // NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_INL_H_ | 209 #endif // NET_DISK_CACHE_BLOCKFILE_STORAGE_BLOCK_INL_H_ |
| OLD | NEW |