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

Side by Side Diff: net/disk_cache/simple/simple_synchronous_entry.cc

Issue 13913010: Add Cache size to the Simple Index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: syncing Created 7 years, 8 months 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
« no previous file with comments | « net/disk_cache/simple/simple_synchronous_entry.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) + key_size; 58 const int64 headers_size = sizeof(disk_cache::SimpleFileHeader) + key_size;
55 return headers_size + data_offset; 59 return headers_size + data_offset;
56 } 60 }
57 61
58 } // namespace 62 } // namespace
59 63
60 namespace disk_cache { 64 namespace disk_cache {
61 65
62 // static 66 // static
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 continue; 209 continue;
206 } 210 }
207 last_used_ = std::max(last_used_, file_info.last_accessed); 211 last_used_ = std::max(last_used_, file_info.last_accessed);
208 last_modified_ = std::max(last_modified_, file_info.last_modified); 212 last_modified_ = std::max(last_modified_, file_info.last_modified);
209 data_size_[i] = DataSizeFromKeyAndFileSize(key_.size(), file_info.size); 213 data_size_[i] = DataSizeFromKeyAndFileSize(key_.size(), file_info.size);
210 } 214 }
211 215
212 return true; 216 return true;
213 } 217 }
214 218
219 int64 SimpleSynchronousEntry::GetFileSize() const {
220 int64 file_size = 0;
221 for (int i = 0; i < kSimpleEntryFileCount; ++i) {
222 file_size += FileSizeFromKeyAndDataSize(key_.size(), data_size_[i]);
223 }
224 return file_size;
225 }
226
215 bool SimpleSynchronousEntry::InitializeForOpen() { 227 bool SimpleSynchronousEntry::InitializeForOpen() {
216 DCHECK(!initialized_); 228 DCHECK(!initialized_);
217 if (!OpenOrCreateFiles(false)) 229 if (!OpenOrCreateFiles(false))
218 return false; 230 return false;
219 231
220 for (int i = 0; i < kSimpleEntryFileCount; ++i) { 232 for (int i = 0; i < kSimpleEntryFileCount; ++i) {
221 SimpleFileHeader header; 233 SimpleFileHeader header;
222 int header_read_result = 234 int header_read_result =
223 ReadPlatformFile(files_[i], 0, reinterpret_cast<char*>(&header), 235 ReadPlatformFile(files_[i], 0, reinterpret_cast<char*>(&header),
224 sizeof(header)); 236 sizeof(header));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // TODO(gavinp): Clean up created files. 304 // TODO(gavinp): Clean up created files.
293 DLOG(WARNING) << "Could not write keys to new cache entry."; 305 DLOG(WARNING) << "Could not write keys to new cache entry.";
294 return false; 306 return false;
295 } 307 }
296 } 308 }
297 initialized_ = true; 309 initialized_ = true;
298 return true; 310 return true;
299 } 311 }
300 312
301 } // namespace disk_cache 313 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_synchronous_entry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698