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 <functional> | 9 #include <functional> |
10 #include <limits> | 10 #include <limits> |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 const int32 sparse_data_size) | 127 const int32 sparse_data_size) |
128 : last_used_(last_used), | 128 : last_used_(last_used), |
129 last_modified_(last_modified), | 129 last_modified_(last_modified), |
130 sparse_data_size_(sparse_data_size) { | 130 sparse_data_size_(sparse_data_size) { |
131 memcpy(data_size_, data_size, sizeof(data_size_)); | 131 memcpy(data_size_, data_size, sizeof(data_size_)); |
132 } | 132 } |
133 | 133 |
134 int SimpleEntryStat::GetOffsetInFile(const std::string& key, | 134 int SimpleEntryStat::GetOffsetInFile(const std::string& key, |
135 int offset, | 135 int offset, |
136 int stream_index) const { | 136 int stream_index) const { |
137 const int64 headers_size = sizeof(SimpleFileHeader) + key.size(); | 137 const size_t headers_size = sizeof(SimpleFileHeader) + key.size(); |
138 const int64 additional_offset = | 138 const size_t additional_offset = |
139 stream_index == 0 ? data_size_[1] + sizeof(SimpleFileEOF) : 0; | 139 stream_index == 0 ? data_size_[1] + sizeof(SimpleFileEOF) : 0; |
140 return headers_size + offset + additional_offset; | 140 return headers_size + offset + additional_offset; |
141 } | 141 } |
142 | 142 |
143 int SimpleEntryStat::GetEOFOffsetInFile(const std::string& key, | 143 int SimpleEntryStat::GetEOFOffsetInFile(const std::string& key, |
144 int stream_index) const { | 144 int stream_index) const { |
145 return GetOffsetInFile(key, data_size_[stream_index], stream_index); | 145 return GetOffsetInFile(key, data_size_[stream_index], stream_index); |
146 } | 146 } |
147 | 147 |
148 int SimpleEntryStat::GetLastEOFOffsetInFile(const std::string& key, | 148 int SimpleEntryStat::GetLastEOFOffsetInFile(const std::string& key, |
149 int stream_index) const { | 149 int stream_index) const { |
150 const int file_index = GetFileIndexFromStreamIndex(stream_index); | 150 const int file_index = GetFileIndexFromStreamIndex(stream_index); |
151 const int eof_data_offset = | 151 const int eof_data_offset = |
152 file_index == 0 ? data_size_[0] + data_size_[1] + sizeof(SimpleFileEOF) | 152 file_index == 0 ? data_size_[0] + data_size_[1] + sizeof(SimpleFileEOF) |
153 : data_size_[2]; | 153 : data_size_[2]; |
154 return GetOffsetInFile(key, eof_data_offset, stream_index); | 154 return GetOffsetInFile(key, eof_data_offset, stream_index); |
155 } | 155 } |
156 | 156 |
157 int SimpleEntryStat::GetFileSize(const std::string& key, int file_index) const { | 157 int64 SimpleEntryStat::GetFileSize(const std::string& key, |
158 const int total_data_size = | 158 int file_index) const { |
| 159 const int32 total_data_size = |
159 file_index == 0 ? data_size_[0] + data_size_[1] + sizeof(SimpleFileEOF) | 160 file_index == 0 ? data_size_[0] + data_size_[1] + sizeof(SimpleFileEOF) |
160 : data_size_[2]; | 161 : data_size_[2]; |
161 return GetFileSizeFromKeyAndDataSize(key, total_data_size); | 162 return GetFileSizeFromKeyAndDataSize(key, total_data_size); |
162 } | 163 } |
163 | 164 |
164 SimpleEntryCreationResults::SimpleEntryCreationResults( | 165 SimpleEntryCreationResults::SimpleEntryCreationResults( |
165 SimpleEntryStat entry_stat) | 166 SimpleEntryStat entry_stat) |
166 : sync_entry(NULL), | 167 : sync_entry(NULL), |
167 entry_stat(entry_stat), | 168 entry_stat(entry_stat), |
168 stream_0_crc32(crc32(0, Z_NULL, 0)), | 169 stream_0_crc32(crc32(0, Z_NULL, 0)), |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 read_so_far += len_to_read; | 445 read_so_far += len_to_read; |
445 ++it; | 446 ++it; |
446 } | 447 } |
447 | 448 |
448 *out_result = read_so_far; | 449 *out_result = read_so_far; |
449 } | 450 } |
450 | 451 |
451 void SimpleSynchronousEntry::WriteSparseData( | 452 void SimpleSynchronousEntry::WriteSparseData( |
452 const EntryOperationData& in_entry_op, | 453 const EntryOperationData& in_entry_op, |
453 net::IOBuffer* in_buf, | 454 net::IOBuffer* in_buf, |
454 int64 max_sparse_data_size, | 455 uint64 max_sparse_data_size, |
455 SimpleEntryStat* out_entry_stat, | 456 SimpleEntryStat* out_entry_stat, |
456 int* out_result) { | 457 int* out_result) { |
457 DCHECK(initialized_); | 458 DCHECK(initialized_); |
458 int64 offset = in_entry_op.sparse_offset; | 459 int64 offset = in_entry_op.sparse_offset; |
459 int buf_len = in_entry_op.buf_len; | 460 int buf_len = in_entry_op.buf_len; |
460 | 461 |
461 const char* buf = in_buf->data(); | 462 const char* buf = in_buf->data(); |
462 int written_so_far = 0; | 463 int written_so_far = 0; |
463 int appended_so_far = 0; | 464 int appended_so_far = 0; |
464 | 465 |
465 if (!sparse_file_open() && !CreateSparseFile()) { | 466 if (!sparse_file_open() && !CreateSparseFile()) { |
466 *out_result = net::ERR_CACHE_WRITE_FAILURE; | 467 *out_result = net::ERR_CACHE_WRITE_FAILURE; |
467 return; | 468 return; |
468 } | 469 } |
469 | 470 |
470 int64 sparse_data_size = out_entry_stat->sparse_data_size(); | 471 uint64 sparse_data_size = out_entry_stat->sparse_data_size(); |
471 // This is a pessimistic estimate; it assumes the entire buffer is going to | 472 // This is a pessimistic estimate; it assumes the entire buffer is going to |
472 // be appended as a new range, not written over existing ranges. | 473 // be appended as a new range, not written over existing ranges. |
473 if (sparse_data_size + buf_len > max_sparse_data_size) { | 474 if (sparse_data_size + buf_len > max_sparse_data_size) { |
474 DVLOG(1) << "Truncating sparse data file (" << sparse_data_size << " + " | 475 DVLOG(1) << "Truncating sparse data file (" << sparse_data_size << " + " |
475 << buf_len << " > " << max_sparse_data_size << ")"; | 476 << buf_len << " > " << max_sparse_data_size << ")"; |
476 TruncateSparseFile(); | 477 TruncateSparseFile(); |
477 } | 478 } |
478 | 479 |
479 SparseRangeIterator it = sparse_ranges_.lower_bound(offset); | 480 SparseRangeIterator it = sparse_ranges_.lower_bound(offset); |
480 | 481 |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 range.offset = offset; | 1427 range.offset = offset; |
1427 range.length = len; | 1428 range.length = len; |
1428 range.data_crc32 = data_crc32; | 1429 range.data_crc32 = data_crc32; |
1429 range.file_offset = data_file_offset; | 1430 range.file_offset = data_file_offset; |
1430 sparse_ranges_.insert(std::make_pair(offset, range)); | 1431 sparse_ranges_.insert(std::make_pair(offset, range)); |
1431 | 1432 |
1432 return true; | 1433 return true; |
1433 } | 1434 } |
1434 | 1435 |
1435 } // namespace disk_cache | 1436 } // namespace disk_cache |
OLD | NEW |