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 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 uint32_t* out_stream_0_crc32) { | 1051 uint32_t* out_stream_0_crc32) { |
1052 DCHECK(!initialized_); | 1052 DCHECK(!initialized_); |
1053 if (!OpenFiles(out_entry_stat)) { | 1053 if (!OpenFiles(out_entry_stat)) { |
1054 DLOG(WARNING) << "Could not open platform files for entry."; | 1054 DLOG(WARNING) << "Could not open platform files for entry."; |
1055 return net::ERR_FAILED; | 1055 return net::ERR_FAILED; |
1056 } | 1056 } |
1057 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 1057 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
1058 if (empty_file_omitted_[i]) | 1058 if (empty_file_omitted_[i]) |
1059 continue; | 1059 continue; |
1060 | 1060 |
1061 if (!key_.empty()) { | 1061 if (key_.empty()) { |
1062 header_and_key_check_needed_[i] = true; | 1062 // If |key_| is empty, we were opened via the iterator interface, without |
1063 } else { | 1063 // knowing what our key is. We must therefore read the header immediately |
| 1064 // to discover it, so SimpleEntryImpl can make it available to |
| 1065 // disk_cache::Entry::GetKey(). |
1064 if (!CheckHeaderAndKey(i)) | 1066 if (!CheckHeaderAndKey(i)) |
1065 return net::ERR_FAILED; | 1067 return net::ERR_FAILED; |
| 1068 } else { |
| 1069 // If we do know which key were are looking for, we still need to |
| 1070 // check that the file actually has it (rather than just being a hash |
| 1071 // collision or some sort of file system accident), but that can be put |
| 1072 // off until opportune time: either the read of the footer, or when we |
| 1073 // start reading in the data, depending on stream # and format revision. |
| 1074 header_and_key_check_needed_[i] = true; |
1066 } | 1075 } |
1067 | 1076 |
1068 if (i == 0) { | 1077 if (i == 0) { |
1069 // File size for stream 0 has been stored temporarily in data_size[1]. | 1078 // File size for stream 0 has been stored temporarily in data_size[1]. |
1070 int ret_value_stream_0 = | 1079 int ret_value_stream_0 = |
1071 ReadAndValidateStream0(out_entry_stat->data_size(1), out_entry_stat, | 1080 ReadAndValidateStream0(out_entry_stat->data_size(1), out_entry_stat, |
1072 stream_0_data, out_stream_0_crc32); | 1081 stream_0_data, out_stream_0_crc32); |
1073 if (ret_value_stream_0 != net::OK) | 1082 if (ret_value_stream_0 != net::OK) |
1074 return ret_value_stream_0; | 1083 return ret_value_stream_0; |
1075 } else { | 1084 } else { |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 range.offset = offset; | 1603 range.offset = offset; |
1595 range.length = len; | 1604 range.length = len; |
1596 range.data_crc32 = data_crc32; | 1605 range.data_crc32 = data_crc32; |
1597 range.file_offset = data_file_offset; | 1606 range.file_offset = data_file_offset; |
1598 sparse_ranges_.insert(std::make_pair(offset, range)); | 1607 sparse_ranges_.insert(std::make_pair(offset, range)); |
1599 | 1608 |
1600 return true; | 1609 return true; |
1601 } | 1610 } |
1602 | 1611 |
1603 } // namespace disk_cache | 1612 } // namespace disk_cache |
OLD | NEW |