| 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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 *out_result = net::ERR_CACHE_CHECKSUM_MISMATCH; | 633 *out_result = net::ERR_CACHE_CHECKSUM_MISMATCH; |
| 634 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_CRC_MISMATCH); | 634 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_CRC_MISMATCH); |
| 635 Doom(); | 635 Doom(); |
| 636 return; | 636 return; |
| 637 } | 637 } |
| 638 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_SUCCESS); | 638 RecordCheckEOFResult(cache_type_, CHECK_EOF_RESULT_SUCCESS); |
| 639 } | 639 } |
| 640 | 640 |
| 641 void SimpleSynchronousEntry::Close( | 641 void SimpleSynchronousEntry::Close( |
| 642 const SimpleEntryStat& entry_stat, | 642 const SimpleEntryStat& entry_stat, |
| 643 scoped_ptr<std::vector<CRCRecord> > crc32s_to_write, | 643 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write, |
| 644 net::GrowableIOBuffer* stream_0_data) { | 644 net::GrowableIOBuffer* stream_0_data) { |
| 645 DCHECK(stream_0_data); | 645 DCHECK(stream_0_data); |
| 646 // Write stream 0 data. | 646 // Write stream 0 data. |
| 647 int stream_0_offset = entry_stat.GetOffsetInFile(key_, 0, 0); | 647 int stream_0_offset = entry_stat.GetOffsetInFile(key_, 0, 0); |
| 648 if (files_[0].Write(stream_0_offset, stream_0_data->data(), | 648 if (files_[0].Write(stream_0_offset, stream_0_data->data(), |
| 649 entry_stat.data_size(0)) != | 649 entry_stat.data_size(0)) != |
| 650 entry_stat.data_size(0)) { | 650 entry_stat.data_size(0)) { |
| 651 RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE); | 651 RecordCloseResult(cache_type_, CLOSE_RESULT_WRITE_FAILURE); |
| 652 DVLOG(1) << "Could not write stream 0 data."; | 652 DVLOG(1) << "Could not write stream 0 data."; |
| 653 Doom(); | 653 Doom(); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_BAD_MAGIC_NUMBER, had_index); | 948 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_BAD_MAGIC_NUMBER, had_index); |
| 949 return net::ERR_FAILED; | 949 return net::ERR_FAILED; |
| 950 } | 950 } |
| 951 | 951 |
| 952 if (header.version != kSimpleEntryVersionOnDisk) { | 952 if (header.version != kSimpleEntryVersionOnDisk) { |
| 953 DLOG(WARNING) << "Unreadable version."; | 953 DLOG(WARNING) << "Unreadable version."; |
| 954 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_BAD_VERSION, had_index); | 954 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_BAD_VERSION, had_index); |
| 955 return net::ERR_FAILED; | 955 return net::ERR_FAILED; |
| 956 } | 956 } |
| 957 | 957 |
| 958 scoped_ptr<char[]> key(new char[header.key_length]); | 958 std::unique_ptr<char[]> key(new char[header.key_length]); |
| 959 int key_read_result = files_[i].Read(sizeof(header), key.get(), | 959 int key_read_result = files_[i].Read(sizeof(header), key.get(), |
| 960 header.key_length); | 960 header.key_length); |
| 961 if (key_read_result != base::checked_cast<int>(header.key_length)) { | 961 if (key_read_result != base::checked_cast<int>(header.key_length)) { |
| 962 DLOG(WARNING) << "Cannot read key from entry."; | 962 DLOG(WARNING) << "Cannot read key from entry."; |
| 963 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_CANT_READ_KEY, had_index); | 963 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_CANT_READ_KEY, had_index); |
| 964 return net::ERR_FAILED; | 964 return net::ERR_FAILED; |
| 965 } | 965 } |
| 966 | 966 |
| 967 key_ = std::string(key.get(), header.key_length); | 967 key_ = std::string(key.get(), header.key_length); |
| 968 if (i == 0) { | 968 if (i == 0) { |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 range.offset = offset; | 1465 range.offset = offset; |
| 1466 range.length = len; | 1466 range.length = len; |
| 1467 range.data_crc32 = data_crc32; | 1467 range.data_crc32 = data_crc32; |
| 1468 range.file_offset = data_file_offset; | 1468 range.file_offset = data_file_offset; |
| 1469 sparse_ranges_.insert(std::make_pair(offset, range)); | 1469 sparse_ranges_.insert(std::make_pair(offset, range)); |
| 1470 | 1470 |
| 1471 return true; | 1471 return true; |
| 1472 } | 1472 } |
| 1473 | 1473 |
| 1474 } // namespace disk_cache | 1474 } // namespace disk_cache |
| OLD | NEW |