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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 sizeof(SimpleFileEOF); | 72 sizeof(SimpleFileEOF); |
73 DCHECK_GE(implicit_cast<int64>(std::numeric_limits<int32>::max()), data_size); | 73 DCHECK_GE(implicit_cast<int64>(std::numeric_limits<int32>::max()), data_size); |
74 return data_size; | 74 return data_size; |
75 } | 75 } |
76 | 76 |
77 int64 GetFileSizeFromKeyAndDataSize(const std::string& key, int32 data_size) { | 77 int64 GetFileSizeFromKeyAndDataSize(const std::string& key, int32 data_size) { |
78 return data_size + key.size() + sizeof(SimpleFileHeader) + | 78 return data_size + key.size() + sizeof(SimpleFileHeader) + |
79 sizeof(SimpleFileEOF); | 79 sizeof(SimpleFileEOF); |
80 } | 80 } |
81 | 81 |
82 int64 GetFileOffsetFromKeyAndDataOffset(const std::string& key, | 82 int GetFileIndexFromStreamIndex(int stream_index) { |
83 int data_offset) { | 83 return (stream_index == 2) ? 1 : 0; |
| 84 } |
| 85 |
| 86 int GetMaximumDataOffset(int file_index, const int data_size[]) { |
| 87 if (file_index == 0) |
| 88 return data_size[0] + data_size[1] + sizeof(SimpleFileEOF); |
| 89 return data_size[2]; |
| 90 } |
| 91 |
| 92 int64 GetFileOffsetFromDataOffset(const std::string& key, |
| 93 int data_offset, |
| 94 int index, |
| 95 int stream_1_size) { |
84 const int64 headers_size = sizeof(disk_cache::SimpleFileHeader) + key.size(); | 96 const int64 headers_size = sizeof(disk_cache::SimpleFileHeader) + key.size(); |
85 return headers_size + data_offset; | 97 const int64 additional_offset = |
| 98 index == 0 ? stream_1_size + sizeof(SimpleFileEOF) : 0; |
| 99 return headers_size + data_offset + additional_offset; |
86 } | 100 } |
87 | 101 |
88 // TODO(clamy, gavinp): this should go in base | 102 // TODO(clamy, gavinp): this should go in base |
89 bool GetMTime(const base::FilePath& path, base::Time* out_mtime) { | 103 bool GetMTime(const base::FilePath& path, base::Time* out_mtime) { |
90 DCHECK(out_mtime); | 104 DCHECK(out_mtime); |
91 base::PlatformFileInfo file_info; | 105 base::PlatformFileInfo file_info; |
92 if (!file_util::GetFileInfo(path, &file_info)) | 106 if (!file_util::GetFileInfo(path, &file_info)) |
93 return false; | 107 return false; |
94 *out_mtime = file_info.last_modified; | 108 *out_mtime = file_info.last_modified; |
95 return true; | 109 return true; |
96 } | 110 } |
97 | 111 |
98 } // namespace simple_backend | 112 } // namespace simple_backend |
99 | 113 |
100 } // namespace disk_cache | 114 } // namespace disk_cache |
OLD | NEW |