Chromium Code Reviews| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 const base::TimeTicks& time_enqueued, | 261 const base::TimeTicks& time_enqueued, |
| 262 SimpleEntryCreationResults* out_results) { | 262 SimpleEntryCreationResults* out_results) { |
| 263 base::TimeTicks start_sync_open_entry = base::TimeTicks::Now(); | 263 base::TimeTicks start_sync_open_entry = base::TimeTicks::Now(); |
| 264 SIMPLE_CACHE_UMA(TIMES, "QueueLatency.OpenEntry", cache_type, | 264 SIMPLE_CACHE_UMA(TIMES, "QueueLatency.OpenEntry", cache_type, |
| 265 (start_sync_open_entry - time_enqueued)); | 265 (start_sync_open_entry - time_enqueued)); |
| 266 | 266 |
| 267 SimpleSynchronousEntry* sync_entry = | 267 SimpleSynchronousEntry* sync_entry = |
| 268 new SimpleSynchronousEntry(cache_type, path, key, entry_hash, had_index); | 268 new SimpleSynchronousEntry(cache_type, path, key, entry_hash, had_index); |
| 269 out_results->result = sync_entry->InitializeForOpen( | 269 out_results->result = sync_entry->InitializeForOpen( |
| 270 &out_results->entry_stat, &out_results->stream_0_data, | 270 &out_results->entry_stat, &out_results->stream_0_data, |
| 271 &out_results->stream_0_crc32); | 271 &out_results->stream_0_crc32, &out_results->stream_1_prefetch_data); |
| 272 if (out_results->result != net::OK) { | 272 if (out_results->result != net::OK) { |
| 273 sync_entry->Doom(); | 273 sync_entry->Doom(); |
| 274 delete sync_entry; | 274 delete sync_entry; |
| 275 out_results->sync_entry = NULL; | 275 out_results->sync_entry = nullptr; |
| 276 out_results->stream_0_data = NULL; | 276 out_results->stream_0_data = nullptr; |
| 277 out_results->stream_1_prefetch_data = nullptr; | |
| 277 return; | 278 return; |
| 278 } | 279 } |
| 279 SIMPLE_CACHE_UMA(TIMES, "DiskOpenLatency", cache_type, | 280 SIMPLE_CACHE_UMA(TIMES, "DiskOpenLatency", cache_type, |
| 280 base::TimeTicks::Now() - start_sync_open_entry); | 281 base::TimeTicks::Now() - start_sync_open_entry); |
| 281 out_results->sync_entry = sync_entry; | 282 out_results->sync_entry = sync_entry; |
| 282 } | 283 } |
| 283 | 284 |
| 284 // static | 285 // static |
| 285 void SimpleSynchronousEntry::CreateEntry( | 286 void SimpleSynchronousEntry::CreateEntry( |
| 286 net::CacheType cache_type, | 287 net::CacheType cache_type, |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 } | 1073 } |
| 1073 } | 1074 } |
| 1074 | 1075 |
| 1075 header_and_key_check_needed_[file_index] = false; | 1076 header_and_key_check_needed_[file_index] = false; |
| 1076 return true; | 1077 return true; |
| 1077 } | 1078 } |
| 1078 | 1079 |
| 1079 int SimpleSynchronousEntry::InitializeForOpen( | 1080 int SimpleSynchronousEntry::InitializeForOpen( |
| 1080 SimpleEntryStat* out_entry_stat, | 1081 SimpleEntryStat* out_entry_stat, |
| 1081 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, | 1082 scoped_refptr<net::GrowableIOBuffer>* stream_0_data, |
| 1082 uint32_t* out_stream_0_crc32) { | 1083 uint32_t* out_stream_0_crc32, |
| 1084 scoped_refptr<net::GrowableIOBuffer>* stream_1_prefetch_data) { | |
| 1083 DCHECK(!initialized_); | 1085 DCHECK(!initialized_); |
| 1084 if (!OpenFiles(out_entry_stat)) { | 1086 if (!OpenFiles(out_entry_stat)) { |
| 1085 DLOG(WARNING) << "Could not open platform files for entry."; | 1087 DLOG(WARNING) << "Could not open platform files for entry."; |
| 1086 return net::ERR_FAILED; | 1088 return net::ERR_FAILED; |
| 1087 } | 1089 } |
| 1090 bool iterator_open = false; | |
| 1088 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 1091 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
| 1089 if (empty_file_omitted_[i]) | 1092 if (empty_file_omitted_[i]) |
| 1090 continue; | 1093 continue; |
| 1091 | 1094 |
| 1092 if (key_.empty()) { | 1095 if (key_.empty()) { |
| 1093 // If |key_| is empty, we were opened via the iterator interface, without | 1096 // If |key_| is empty, we were opened via the iterator interface, without |
| 1094 // knowing what our key is. We must therefore read the header immediately | 1097 // knowing what our key is. We must therefore read the header immediately |
| 1095 // to discover it, so SimpleEntryImpl can make it available to | 1098 // to discover it, so SimpleEntryImpl can make it available to |
| 1096 // disk_cache::Entry::GetKey(). | 1099 // disk_cache::Entry::GetKey(). |
| 1100 iterator_open = true; | |
| 1097 if (!CheckHeaderAndKey(i)) | 1101 if (!CheckHeaderAndKey(i)) |
| 1098 return net::ERR_FAILED; | 1102 return net::ERR_FAILED; |
| 1099 } else { | 1103 } else { |
| 1100 // If we do know which key were are looking for, we still need to | 1104 // If we do know which key were are looking for, we still need to |
| 1101 // check that the file actually has it (rather than just being a hash | 1105 // check that the file actually has it (rather than just being a hash |
| 1102 // collision or some sort of file system accident), but that can be put | 1106 // collision or some sort of file system accident), but that can be put |
| 1103 // off until opportune time: either the read of the footer, or when we | 1107 // off until opportune time: either the read of the footer, or when we |
| 1104 // start reading in the data, depending on stream # and format revision. | 1108 // start reading in the data, depending on stream # and format revision. |
| 1105 header_and_key_check_needed_[i] = true; | 1109 header_and_key_check_needed_[i] = true; |
| 1106 } | 1110 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1141 DeleteFileForEntryHash(path_, entry_hash_, stream2_file_index); | 1145 DeleteFileForEntryHash(path_, entry_hash_, stream2_file_index); |
| 1142 empty_file_omitted_[stream2_file_index] = true; | 1146 empty_file_omitted_[stream2_file_index] = true; |
| 1143 removed_stream2 = true; | 1147 removed_stream2 = true; |
| 1144 } | 1148 } |
| 1145 | 1149 |
| 1146 SIMPLE_CACHE_UMA(BOOLEAN, "EntryOpenedAndStream2Removed", cache_type_, | 1150 SIMPLE_CACHE_UMA(BOOLEAN, "EntryOpenedAndStream2Removed", cache_type_, |
| 1147 removed_stream2); | 1151 removed_stream2); |
| 1148 | 1152 |
| 1149 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_SUCCESS, had_index_); | 1153 RecordSyncOpenResult(cache_type_, OPEN_ENTRY_SUCCESS, had_index_); |
| 1150 initialized_ = true; | 1154 initialized_ = true; |
| 1155 | |
| 1156 // If there is data to read and it's not partial, read some. | |
| 1157 if (out_entry_stat->sparse_data_size() == 0 && | |
|
jkarlin
2017/05/09 15:56:45
The bits in this conditional are completely broken
| |
| 1158 out_entry_stat->data_size(1) > 0) { | |
| 1159 // Figure out if we should be computing the checksum for this read, | |
| 1160 // and whether we should be verifying it, too. | |
| 1161 std::unique_ptr<CRCRequest> crc_request; | |
| 1162 if (crc32s_end_offset_[stream_index] == 0) { | |
| 1163 crc_request = base::MakeUnique<CRCRequest>(); | |
| 1164 crc_request->data_crc32 = crc32(0, Z_NULL, 0); | |
| 1165 crc_request->request_verify = true; | |
| 1166 } | |
| 1167 | |
| 1168 std::unique_ptr<int> result = base::MakeUnique<int>(0); | |
| 1169 std::unique_ptr<SimpleEntryStat> entry_stat = | |
| 1170 base::MakeUnique<SimpleEntryStat>(last_used_, last_modified_, | |
| 1171 data_size_, sparse_data_size_); | |
| 1172 Closure task = base::Bind(&SimpleSynchronousEntry::ReadData, | |
| 1173 base::Unretained(synchronous_entry_), | |
| 1174 SimpleSynchronousEntry::EntryOperationData( | |
| 1175 stream_index, offset, buf_len), | |
| 1176 crc_request.get(), entry_stat.get(), | |
| 1177 base::RetainedRef(buf), result.get()); | |
| 1178 | |
| 1179 ReadData | |
| 1180 } | |
| 1181 | |
| 1151 return net::OK; | 1182 return net::OK; |
| 1152 } | 1183 } |
| 1153 | 1184 |
| 1154 bool SimpleSynchronousEntry::InitializeCreatedFile( | 1185 bool SimpleSynchronousEntry::InitializeCreatedFile( |
| 1155 int file_index, | 1186 int file_index, |
| 1156 CreateEntryResult* out_result) { | 1187 CreateEntryResult* out_result) { |
| 1157 SimpleFileHeader header; | 1188 SimpleFileHeader header; |
| 1158 header.initial_magic_number = kSimpleInitialMagicNumber; | 1189 header.initial_magic_number = kSimpleInitialMagicNumber; |
| 1159 header.version = kSimpleEntryVersionOnDisk; | 1190 header.version = kSimpleEntryVersionOnDisk; |
| 1160 | 1191 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1634 range.offset = offset; | 1665 range.offset = offset; |
| 1635 range.length = len; | 1666 range.length = len; |
| 1636 range.data_crc32 = data_crc32; | 1667 range.data_crc32 = data_crc32; |
| 1637 range.file_offset = data_file_offset; | 1668 range.file_offset = data_file_offset; |
| 1638 sparse_ranges_.insert(std::make_pair(offset, range)); | 1669 sparse_ranges_.insert(std::make_pair(offset, range)); |
| 1639 | 1670 |
| 1640 return true; | 1671 return true; |
| 1641 } | 1672 } |
| 1642 | 1673 |
| 1643 } // namespace disk_cache | 1674 } // namespace disk_cache |
| OLD | NEW |