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_util.h" | 5 #include "net/disk_cache/simple/simple_util.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 std::string GetSparseFilenameFromEntryHash(uint64_t entry_hash) { | 90 std::string GetSparseFilenameFromEntryHash(uint64_t entry_hash) { |
91 return base::StringPrintf("%016" PRIx64 "_s", entry_hash); | 91 return base::StringPrintf("%016" PRIx64 "_s", entry_hash); |
92 } | 92 } |
93 | 93 |
94 std::string GetFilenameFromKeyAndFileIndex(const std::string& key, | 94 std::string GetFilenameFromKeyAndFileIndex(const std::string& key, |
95 int file_index) { | 95 int file_index) { |
96 return GetEntryHashKeyAsHexString(key) + | 96 return GetEntryHashKeyAsHexString(key) + |
97 base::StringPrintf("_%1d", file_index); | 97 base::StringPrintf("_%1d", file_index); |
98 } | 98 } |
99 | 99 |
100 int32_t GetDataSizeFromKeyAndFileSize(const std::string& key, | 100 size_t GetHeaderSize(size_t key_length) { |
101 int64_t file_size) { | 101 return sizeof(SimpleFileHeader) + key_length; |
| 102 } |
| 103 |
| 104 int32_t GetDataSizeFromFileSize(size_t key_length, int64_t file_size) { |
102 int64_t data_size = | 105 int64_t data_size = |
103 file_size - key.size() - sizeof(SimpleFileHeader) - sizeof(SimpleFileEOF); | 106 file_size - key_length - sizeof(SimpleFileHeader) - sizeof(SimpleFileEOF); |
104 return base::checked_cast<int32_t>(data_size); | 107 return base::checked_cast<int32_t>(data_size); |
105 } | 108 } |
106 | 109 |
107 int64_t GetFileSizeFromKeyAndDataSize(const std::string& key, | 110 int64_t GetFileSizeFromDataSize(size_t key_length, int32_t data_size) { |
108 int32_t data_size) { | 111 return data_size + key_length + sizeof(SimpleFileHeader) + |
109 return data_size + key.size() + sizeof(SimpleFileHeader) + | 112 sizeof(SimpleFileEOF); |
110 sizeof(SimpleFileEOF); | |
111 } | 113 } |
112 | 114 |
113 int GetFileIndexFromStreamIndex(int stream_index) { | 115 int GetFileIndexFromStreamIndex(int stream_index) { |
114 return (stream_index == 2) ? 1 : 0; | 116 return (stream_index == 2) ? 1 : 0; |
115 } | 117 } |
116 | 118 |
117 // TODO(clamy, gavinp): this should go in base | 119 // TODO(clamy, gavinp): this should go in base |
118 bool GetMTime(const base::FilePath& path, base::Time* out_mtime) { | 120 bool GetMTime(const base::FilePath& path, base::Time* out_mtime) { |
119 DCHECK(out_mtime); | 121 DCHECK(out_mtime); |
120 #if defined(OS_POSIX) | 122 #if defined(OS_POSIX) |
(...skipping 13 matching lines...) Expand all Loading... |
134 base::File::Info file_info; | 136 base::File::Info file_info; |
135 if (!base::GetFileInfo(path, &file_info)) | 137 if (!base::GetFileInfo(path, &file_info)) |
136 return false; | 138 return false; |
137 *out_mtime = file_info.last_modified; | 139 *out_mtime = file_info.last_modified; |
138 return true; | 140 return true; |
139 } | 141 } |
140 | 142 |
141 } // namespace simple_backend | 143 } // namespace simple_backend |
142 | 144 |
143 } // namespace disk_cache | 145 } // namespace disk_cache |
OLD | NEW |