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 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 | 932 |
933 if (header.version != kSimpleEntryVersionOnDisk) { | 933 if (header.version != kSimpleEntryVersionOnDisk) { |
934 DLOG(WARNING) << "Unreadable version."; | 934 DLOG(WARNING) << "Unreadable version."; |
935 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_BAD_VERSION, had_index); | 935 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_BAD_VERSION, had_index); |
936 return net::ERR_FAILED; | 936 return net::ERR_FAILED; |
937 } | 937 } |
938 | 938 |
939 scoped_ptr<char[]> key(new char[header.key_length]); | 939 scoped_ptr<char[]> key(new char[header.key_length]); |
940 int key_read_result = files_[i].Read(sizeof(header), key.get(), | 940 int key_read_result = files_[i].Read(sizeof(header), key.get(), |
941 header.key_length); | 941 header.key_length); |
942 if (key_read_result != implicit_cast<int>(header.key_length)) { | 942 if (key_read_result != base::checked_cast<int>(header.key_length)) { |
943 DLOG(WARNING) << "Cannot read key from entry."; | 943 DLOG(WARNING) << "Cannot read key from entry."; |
944 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_CANT_READ_KEY, had_index); | 944 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_CANT_READ_KEY, had_index); |
945 return net::ERR_FAILED; | 945 return net::ERR_FAILED; |
946 } | 946 } |
947 | 947 |
948 key_ = std::string(key.get(), header.key_length); | 948 key_ = std::string(key.get(), header.key_length); |
949 if (i == 0) { | 949 if (i == 0) { |
950 // File size for stream 0 has been stored temporarily in data_size[1]. | 950 // File size for stream 0 has been stored temporarily in data_size[1]. |
951 int total_data_size = | 951 int total_data_size = |
952 GetDataSizeFromKeyAndFileSize(key_, out_entry_stat->data_size(1)); | 952 GetDataSizeFromKeyAndFileSize(key_, out_entry_stat->data_size(1)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 | 1011 |
1012 int bytes_written = files_[file_index].Write( | 1012 int bytes_written = files_[file_index].Write( |
1013 0, reinterpret_cast<char*>(&header), sizeof(header)); | 1013 0, reinterpret_cast<char*>(&header), sizeof(header)); |
1014 if (bytes_written != sizeof(header)) { | 1014 if (bytes_written != sizeof(header)) { |
1015 *out_result = CREATE_ENTRY_CANT_WRITE_HEADER; | 1015 *out_result = CREATE_ENTRY_CANT_WRITE_HEADER; |
1016 return false; | 1016 return false; |
1017 } | 1017 } |
1018 | 1018 |
1019 bytes_written = files_[file_index].Write(sizeof(header), key_.data(), | 1019 bytes_written = files_[file_index].Write(sizeof(header), key_.data(), |
1020 key_.size()); | 1020 key_.size()); |
1021 if (bytes_written != implicit_cast<int>(key_.size())) { | 1021 if (bytes_written != base::checked_cast<int>(key_.size())) { |
1022 *out_result = CREATE_ENTRY_CANT_WRITE_KEY; | 1022 *out_result = CREATE_ENTRY_CANT_WRITE_KEY; |
1023 return false; | 1023 return false; |
1024 } | 1024 } |
1025 | 1025 |
1026 return true; | 1026 return true; |
1027 } | 1027 } |
1028 | 1028 |
1029 int SimpleSynchronousEntry::InitializeForCreate( | 1029 int SimpleSynchronousEntry::InitializeForCreate( |
1030 bool had_index, | 1030 bool had_index, |
1031 SimpleEntryStat* out_entry_stat) { | 1031 SimpleEntryStat* out_entry_stat) { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 | 1241 |
1242 int header_write_result = | 1242 int header_write_result = |
1243 sparse_file_.Write(0, reinterpret_cast<char*>(&header), sizeof(header)); | 1243 sparse_file_.Write(0, reinterpret_cast<char*>(&header), sizeof(header)); |
1244 if (header_write_result != sizeof(header)) { | 1244 if (header_write_result != sizeof(header)) { |
1245 DLOG(WARNING) << "Could not write sparse file header"; | 1245 DLOG(WARNING) << "Could not write sparse file header"; |
1246 return false; | 1246 return false; |
1247 } | 1247 } |
1248 | 1248 |
1249 int key_write_result = sparse_file_.Write(sizeof(header), key_.data(), | 1249 int key_write_result = sparse_file_.Write(sizeof(header), key_.data(), |
1250 key_.size()); | 1250 key_.size()); |
1251 if (key_write_result != implicit_cast<int>(key_.size())) { | 1251 if (key_write_result != base::checked_cast<int>(key_.size())) { |
1252 DLOG(WARNING) << "Could not write sparse file key"; | 1252 DLOG(WARNING) << "Could not write sparse file key"; |
1253 return false; | 1253 return false; |
1254 } | 1254 } |
1255 | 1255 |
1256 sparse_ranges_.clear(); | 1256 sparse_ranges_.clear(); |
1257 sparse_tail_offset_ = sizeof(header) + key_.size(); | 1257 sparse_tail_offset_ = sizeof(header) + key_.size(); |
1258 | 1258 |
1259 return true; | 1259 return true; |
1260 } | 1260 } |
1261 | 1261 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 | 1371 |
1372 SimpleFileSparseRangeHeader header; | 1372 SimpleFileSparseRangeHeader header; |
1373 header.sparse_range_magic_number = kSimpleSparseRangeMagicNumber; | 1373 header.sparse_range_magic_number = kSimpleSparseRangeMagicNumber; |
1374 header.offset = range->offset; | 1374 header.offset = range->offset; |
1375 header.length = range->length; | 1375 header.length = range->length; |
1376 header.data_crc32 = range->data_crc32; | 1376 header.data_crc32 = range->data_crc32; |
1377 | 1377 |
1378 int bytes_written = sparse_file_.Write(range->file_offset - sizeof(header), | 1378 int bytes_written = sparse_file_.Write(range->file_offset - sizeof(header), |
1379 reinterpret_cast<char*>(&header), | 1379 reinterpret_cast<char*>(&header), |
1380 sizeof(header)); | 1380 sizeof(header)); |
1381 if (bytes_written != implicit_cast<int>(sizeof(header))) { | 1381 if (bytes_written != base::checked_cast<int>(sizeof(header))) { |
1382 DLOG(WARNING) << "Could not rewrite sparse range header."; | 1382 DLOG(WARNING) << "Could not rewrite sparse range header."; |
1383 return false; | 1383 return false; |
1384 } | 1384 } |
1385 } | 1385 } |
1386 | 1386 |
1387 int bytes_written = sparse_file_.Write(range->file_offset + offset, buf, len); | 1387 int bytes_written = sparse_file_.Write(range->file_offset + offset, buf, len); |
1388 if (bytes_written < len) { | 1388 if (bytes_written < len) { |
1389 DLOG(WARNING) << "Could not write sparse range."; | 1389 DLOG(WARNING) << "Could not write sparse range."; |
1390 return false; | 1390 return false; |
1391 } | 1391 } |
(...skipping 14 matching lines...) Expand all Loading... |
1406 | 1406 |
1407 SimpleFileSparseRangeHeader header; | 1407 SimpleFileSparseRangeHeader header; |
1408 header.sparse_range_magic_number = kSimpleSparseRangeMagicNumber; | 1408 header.sparse_range_magic_number = kSimpleSparseRangeMagicNumber; |
1409 header.offset = offset; | 1409 header.offset = offset; |
1410 header.length = len; | 1410 header.length = len; |
1411 header.data_crc32 = data_crc32; | 1411 header.data_crc32 = data_crc32; |
1412 | 1412 |
1413 int bytes_written = sparse_file_.Write(sparse_tail_offset_, | 1413 int bytes_written = sparse_file_.Write(sparse_tail_offset_, |
1414 reinterpret_cast<char*>(&header), | 1414 reinterpret_cast<char*>(&header), |
1415 sizeof(header)); | 1415 sizeof(header)); |
1416 if (bytes_written != implicit_cast<int>(sizeof(header))) { | 1416 if (bytes_written != base::checked_cast<int>(sizeof(header))) { |
1417 DLOG(WARNING) << "Could not append sparse range header."; | 1417 DLOG(WARNING) << "Could not append sparse range header."; |
1418 return false; | 1418 return false; |
1419 } | 1419 } |
1420 sparse_tail_offset_ += bytes_written; | 1420 sparse_tail_offset_ += bytes_written; |
1421 | 1421 |
1422 bytes_written = sparse_file_.Write(sparse_tail_offset_, buf, len); | 1422 bytes_written = sparse_file_.Write(sparse_tail_offset_, buf, len); |
1423 if (bytes_written < len) { | 1423 if (bytes_written < len) { |
1424 DLOG(WARNING) << "Could not append sparse range data."; | 1424 DLOG(WARNING) << "Could not append sparse range data."; |
1425 return false; | 1425 return false; |
1426 } | 1426 } |
1427 int64 data_file_offset = sparse_tail_offset_; | 1427 int64 data_file_offset = sparse_tail_offset_; |
1428 sparse_tail_offset_ += bytes_written; | 1428 sparse_tail_offset_ += bytes_written; |
1429 | 1429 |
1430 SparseRange range; | 1430 SparseRange range; |
1431 range.offset = offset; | 1431 range.offset = offset; |
1432 range.length = len; | 1432 range.length = len; |
1433 range.data_crc32 = data_crc32; | 1433 range.data_crc32 = data_crc32; |
1434 range.file_offset = data_file_offset; | 1434 range.file_offset = data_file_offset; |
1435 sparse_ranges_.insert(std::make_pair(offset, range)); | 1435 sparse_ranges_.insert(std::make_pair(offset, range)); |
1436 | 1436 |
1437 return true; | 1437 return true; |
1438 } | 1438 } |
1439 | 1439 |
1440 } // namespace disk_cache | 1440 } // namespace disk_cache |
OLD | NEW |