OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "net/disk_cache/simple/simple_synchronous_entry.h" | 5 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 return disk_cache::GetEntryHashForKey(key) + | 43 return disk_cache::GetEntryHashForKey(key) + |
44 base::StringPrintf("_%1d", index); | 44 base::StringPrintf("_%1d", index); |
45 } | 45 } |
46 | 46 |
47 int32 DataSizeFromKeyAndFileSize(size_t key_size, int64 file_size) { | 47 int32 DataSizeFromKeyAndFileSize(size_t key_size, int64 file_size) { |
48 int64 data_size = file_size - key_size - sizeof(disk_cache::SimpleFileHeader); | 48 int64 data_size = file_size - key_size - sizeof(disk_cache::SimpleFileHeader); |
49 DCHECK_GE(implicit_cast<int64>(std::numeric_limits<int32>::max()), data_size); | 49 DCHECK_GE(implicit_cast<int64>(std::numeric_limits<int32>::max()), data_size); |
50 return data_size; | 50 return data_size; |
51 } | 51 } |
52 | 52 |
53 int64 FileSizeFromKeyAndDataSize(size_t key_size, int32 data_size) { | |
54 return data_size + key_size + sizeof(disk_cache::SimpleFileHeader); | |
55 } | |
56 | |
53 int64 FileOffsetFromDataOffset(size_t key_size, int data_offset) { | 57 int64 FileOffsetFromDataOffset(size_t key_size, int data_offset) { |
54 const int64 headers_size = sizeof(disk_cache::SimpleFileHeader) + | 58 const int64 headers_size = sizeof(disk_cache::SimpleFileHeader) + |
55 key_size; | 59 key_size; |
56 return headers_size + data_offset; | 60 return headers_size + data_offset; |
57 } | 61 } |
58 | 62 |
59 } // namespace | 63 } // namespace |
60 | 64 |
61 namespace disk_cache { | 65 namespace disk_cache { |
62 | 66 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 continue; | 210 continue; |
207 } | 211 } |
208 last_used_ = std::max(last_used_, file_info.last_accessed); | 212 last_used_ = std::max(last_used_, file_info.last_accessed); |
209 last_modified_ = std::max(last_modified_, file_info.last_modified); | 213 last_modified_ = std::max(last_modified_, file_info.last_modified); |
210 data_size_[i] = DataSizeFromKeyAndFileSize(key_.size(), file_info.size); | 214 data_size_[i] = DataSizeFromKeyAndFileSize(key_.size(), file_info.size); |
211 } | 215 } |
212 | 216 |
213 return true; | 217 return true; |
214 } | 218 } |
215 | 219 |
220 int64 SimpleSynchronousEntry::GetFileSize() const { | |
gavinp
2013/04/10 10:33:23
Ordering: methods in a .cc file should be in the s
| |
221 int64 file_size = 0; | |
222 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | |
223 file_size += FileSizeFromKeyAndDataSize(key_.size(), data_size_[i]); | |
224 } | |
225 return file_size; | |
226 } | |
227 | |
216 bool SimpleSynchronousEntry::InitializeForOpen() { | 228 bool SimpleSynchronousEntry::InitializeForOpen() { |
217 DCHECK(!initialized_); | 229 DCHECK(!initialized_); |
218 if (!OpenOrCreateFiles(false)) | 230 if (!OpenOrCreateFiles(false)) |
219 return false; | 231 return false; |
220 | 232 |
221 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 233 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
222 SimpleFileHeader header; | 234 SimpleFileHeader header; |
223 int header_read_result = | 235 int header_read_result = |
224 ReadPlatformFile(files_[i], 0, reinterpret_cast<char*>(&header), | 236 ReadPlatformFile(files_[i], 0, reinterpret_cast<char*>(&header), |
225 sizeof(header)); | 237 sizeof(header)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 // TODO(gavinp): Clean up created files. | 305 // TODO(gavinp): Clean up created files. |
294 DLOG(WARNING) << "Could not write keys to new cache entry."; | 306 DLOG(WARNING) << "Could not write keys to new cache entry."; |
295 return false; | 307 return false; |
296 } | 308 } |
297 } | 309 } |
298 initialized_ = true; | 310 initialized_ = true; |
299 return true; | 311 return true; |
300 } | 312 } |
301 | 313 |
302 } // namespace disk_cache | 314 } // namespace disk_cache |
OLD | NEW |