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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/numerics/safe_conversions.h" |
12 #include "base/sha1.h" | 13 #include "base/sha1.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "net/disk_cache/simple/simple_entry_format.h" | 18 #include "net/disk_cache/simple/simple_entry_format.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Size of the uint64 hash_key number in Hex format in a string. | 22 // Size of the uint64 hash_key number in Hex format in a string. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 91 |
91 std::string GetFilenameFromKeyAndFileIndex(const std::string& key, | 92 std::string GetFilenameFromKeyAndFileIndex(const std::string& key, |
92 int file_index) { | 93 int file_index) { |
93 return GetEntryHashKeyAsHexString(key) + | 94 return GetEntryHashKeyAsHexString(key) + |
94 base::StringPrintf("_%1d", file_index); | 95 base::StringPrintf("_%1d", file_index); |
95 } | 96 } |
96 | 97 |
97 int32 GetDataSizeFromKeyAndFileSize(const std::string& key, int64 file_size) { | 98 int32 GetDataSizeFromKeyAndFileSize(const std::string& key, int64 file_size) { |
98 int64 data_size = file_size - key.size() - sizeof(SimpleFileHeader) - | 99 int64 data_size = file_size - key.size() - sizeof(SimpleFileHeader) - |
99 sizeof(SimpleFileEOF); | 100 sizeof(SimpleFileEOF); |
100 DCHECK_GE(implicit_cast<int64>(std::numeric_limits<int32>::max()), data_size); | 101 return base::checked_cast<int32>(data_size); |
101 return data_size; | |
102 } | 102 } |
103 | 103 |
104 int64 GetFileSizeFromKeyAndDataSize(const std::string& key, int32 data_size) { | 104 int64 GetFileSizeFromKeyAndDataSize(const std::string& key, int32 data_size) { |
105 return data_size + key.size() + sizeof(SimpleFileHeader) + | 105 return data_size + key.size() + sizeof(SimpleFileHeader) + |
106 sizeof(SimpleFileEOF); | 106 sizeof(SimpleFileEOF); |
107 } | 107 } |
108 | 108 |
109 int GetFileIndexFromStreamIndex(int stream_index) { | 109 int GetFileIndexFromStreamIndex(int stream_index) { |
110 return (stream_index == 2) ? 1 : 0; | 110 return (stream_index == 2) ? 1 : 0; |
111 } | 111 } |
(...skipping 18 matching lines...) Expand all Loading... |
130 base::File::Info file_info; | 130 base::File::Info file_info; |
131 if (!base::GetFileInfo(path, &file_info)) | 131 if (!base::GetFileInfo(path, &file_info)) |
132 return false; | 132 return false; |
133 *out_mtime = file_info.last_modified; | 133 *out_mtime = file_info.last_modified; |
134 return true; | 134 return true; |
135 } | 135 } |
136 | 136 |
137 } // namespace simple_backend | 137 } // namespace simple_backend |
138 | 138 |
139 } // namespace disk_cache | 139 } // namespace disk_cache |
OLD | NEW |