| 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_entry_impl.h" | 5 #include "net/disk_cache/simple/simple_entry_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 op_callback)); | 472 op_callback)); |
| 473 return ret_value; | 473 return ret_value; |
| 474 } | 474 } |
| 475 | 475 |
| 476 int SimpleEntryImpl::ReadSparseData(int64_t offset, | 476 int SimpleEntryImpl::ReadSparseData(int64_t offset, |
| 477 net::IOBuffer* buf, | 477 net::IOBuffer* buf, |
| 478 int buf_len, | 478 int buf_len, |
| 479 const CompletionCallback& callback) { | 479 const CompletionCallback& callback) { |
| 480 DCHECK(io_thread_checker_.CalledOnValidThread()); | 480 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 481 | 481 |
| 482 if (net_log_.IsCapturing()) { |
| 483 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_CALL, |
| 484 CreateNetLogSparseOperationCallback(offset, buf_len)); |
| 485 } |
| 486 |
| 482 ScopedOperationRunner operation_runner(this); | 487 ScopedOperationRunner operation_runner(this); |
| 483 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation( | 488 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation( |
| 484 this, offset, buf_len, buf, callback)); | 489 this, offset, buf_len, buf, callback)); |
| 485 return net::ERR_IO_PENDING; | 490 return net::ERR_IO_PENDING; |
| 486 } | 491 } |
| 487 | 492 |
| 488 int SimpleEntryImpl::WriteSparseData(int64_t offset, | 493 int SimpleEntryImpl::WriteSparseData(int64_t offset, |
| 489 net::IOBuffer* buf, | 494 net::IOBuffer* buf, |
| 490 int buf_len, | 495 int buf_len, |
| 491 const CompletionCallback& callback) { | 496 const CompletionCallback& callback) { |
| 492 DCHECK(io_thread_checker_.CalledOnValidThread()); | 497 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 493 | 498 |
| 499 if (net_log_.IsCapturing()) { |
| 500 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_CALL, |
| 501 CreateNetLogSparseOperationCallback(offset, buf_len)); |
| 502 } |
| 503 |
| 494 ScopedOperationRunner operation_runner(this); | 504 ScopedOperationRunner operation_runner(this); |
| 495 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation( | 505 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation( |
| 496 this, offset, buf_len, buf, callback)); | 506 this, offset, buf_len, buf, callback)); |
| 497 return net::ERR_IO_PENDING; | 507 return net::ERR_IO_PENDING; |
| 498 } | 508 } |
| 499 | 509 |
| 500 int SimpleEntryImpl::GetAvailableRange(int64_t offset, | 510 int SimpleEntryImpl::GetAvailableRange(int64_t offset, |
| 501 int len, | 511 int len, |
| 502 int64_t* start, | 512 int64_t* start, |
| 503 const CompletionCallback& callback) { | 513 const CompletionCallback& callback) { |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 } | 995 } |
| 986 | 996 |
| 987 void SimpleEntryImpl::ReadSparseDataInternal( | 997 void SimpleEntryImpl::ReadSparseDataInternal( |
| 988 int64_t sparse_offset, | 998 int64_t sparse_offset, |
| 989 net::IOBuffer* buf, | 999 net::IOBuffer* buf, |
| 990 int buf_len, | 1000 int buf_len, |
| 991 const CompletionCallback& callback) { | 1001 const CompletionCallback& callback) { |
| 992 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1002 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 993 ScopedOperationRunner operation_runner(this); | 1003 ScopedOperationRunner operation_runner(this); |
| 994 | 1004 |
| 1005 if (net_log_.IsCapturing()) { |
| 1006 net_log_.AddEvent( |
| 1007 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN, |
| 1008 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); |
| 1009 } |
| 1010 |
| 995 DCHECK_EQ(STATE_READY, state_); | 1011 DCHECK_EQ(STATE_READY, state_); |
| 996 state_ = STATE_IO_PENDING; | 1012 state_ = STATE_IO_PENDING; |
| 997 | 1013 |
| 998 scoped_ptr<int> result(new int()); | 1014 scoped_ptr<int> result(new int()); |
| 999 scoped_ptr<base::Time> last_used(new base::Time()); | 1015 scoped_ptr<base::Time> last_used(new base::Time()); |
| 1000 Closure task = base::Bind(&SimpleSynchronousEntry::ReadSparseData, | 1016 Closure task = base::Bind(&SimpleSynchronousEntry::ReadSparseData, |
| 1001 base::Unretained(synchronous_entry_), | 1017 base::Unretained(synchronous_entry_), |
| 1002 SimpleSynchronousEntry::EntryOperationData( | 1018 SimpleSynchronousEntry::EntryOperationData( |
| 1003 sparse_offset, buf_len), | 1019 sparse_offset, buf_len), |
| 1004 make_scoped_refptr(buf), | 1020 make_scoped_refptr(buf), |
| 1005 last_used.get(), | 1021 last_used.get(), |
| 1006 result.get()); | 1022 result.get()); |
| 1007 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete, | 1023 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete, |
| 1008 this, | 1024 this, |
| 1009 callback, | 1025 callback, |
| 1010 base::Passed(&last_used), | 1026 base::Passed(&last_used), |
| 1011 base::Passed(&result)); | 1027 base::Passed(&result)); |
| 1012 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); | 1028 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); |
| 1013 } | 1029 } |
| 1014 | 1030 |
| 1015 void SimpleEntryImpl::WriteSparseDataInternal( | 1031 void SimpleEntryImpl::WriteSparseDataInternal( |
| 1016 int64_t sparse_offset, | 1032 int64_t sparse_offset, |
| 1017 net::IOBuffer* buf, | 1033 net::IOBuffer* buf, |
| 1018 int buf_len, | 1034 int buf_len, |
| 1019 const CompletionCallback& callback) { | 1035 const CompletionCallback& callback) { |
| 1020 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1036 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1021 ScopedOperationRunner operation_runner(this); | 1037 ScopedOperationRunner operation_runner(this); |
| 1022 | 1038 |
| 1039 if (net_log_.IsCapturing()) { |
| 1040 net_log_.AddEvent( |
| 1041 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_BEGIN, |
| 1042 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); |
| 1043 } |
| 1044 |
| 1023 DCHECK_EQ(STATE_READY, state_); | 1045 DCHECK_EQ(STATE_READY, state_); |
| 1024 state_ = STATE_IO_PENDING; | 1046 state_ = STATE_IO_PENDING; |
| 1025 | 1047 |
| 1026 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max(); | 1048 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max(); |
| 1027 if (backend_.get()) { | 1049 if (backend_.get()) { |
| 1028 uint64_t max_cache_size = backend_->index()->max_size(); | 1050 uint64_t max_cache_size = backend_->index()->max_size(); |
| 1029 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; | 1051 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; |
| 1030 } | 1052 } |
| 1031 | 1053 |
| 1032 scoped_ptr<SimpleEntryStat> entry_stat( | 1054 scoped_ptr<SimpleEntryStat> entry_stat( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 } | 1279 } |
| 1258 | 1280 |
| 1259 void SimpleEntryImpl::ReadSparseOperationComplete( | 1281 void SimpleEntryImpl::ReadSparseOperationComplete( |
| 1260 const CompletionCallback& completion_callback, | 1282 const CompletionCallback& completion_callback, |
| 1261 scoped_ptr<base::Time> last_used, | 1283 scoped_ptr<base::Time> last_used, |
| 1262 scoped_ptr<int> result) { | 1284 scoped_ptr<int> result) { |
| 1263 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1285 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1264 DCHECK(synchronous_entry_); | 1286 DCHECK(synchronous_entry_); |
| 1265 DCHECK(result); | 1287 DCHECK(result); |
| 1266 | 1288 |
| 1289 if (net_log_.IsCapturing()) { |
| 1290 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_END, |
| 1291 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1292 } |
| 1293 |
| 1267 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_, | 1294 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_, |
| 1268 sparse_data_size_); | 1295 sparse_data_size_); |
| 1269 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); | 1296 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); |
| 1270 } | 1297 } |
| 1271 | 1298 |
| 1272 void SimpleEntryImpl::WriteSparseOperationComplete( | 1299 void SimpleEntryImpl::WriteSparseOperationComplete( |
| 1273 const CompletionCallback& completion_callback, | 1300 const CompletionCallback& completion_callback, |
| 1274 scoped_ptr<SimpleEntryStat> entry_stat, | 1301 scoped_ptr<SimpleEntryStat> entry_stat, |
| 1275 scoped_ptr<int> result) { | 1302 scoped_ptr<int> result) { |
| 1276 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1303 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1277 DCHECK(synchronous_entry_); | 1304 DCHECK(synchronous_entry_); |
| 1278 DCHECK(result); | 1305 DCHECK(result); |
| 1279 | 1306 |
| 1307 if (net_log_.IsCapturing()) { |
| 1308 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_END, |
| 1309 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1310 } |
| 1311 |
| 1280 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1312 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1281 } | 1313 } |
| 1282 | 1314 |
| 1283 void SimpleEntryImpl::GetAvailableRangeOperationComplete( | 1315 void SimpleEntryImpl::GetAvailableRangeOperationComplete( |
| 1284 const CompletionCallback& completion_callback, | 1316 const CompletionCallback& completion_callback, |
| 1285 scoped_ptr<int> result) { | 1317 scoped_ptr<int> result) { |
| 1286 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1318 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1287 DCHECK(synchronous_entry_); | 1319 DCHECK(synchronous_entry_); |
| 1288 DCHECK(result); | 1320 DCHECK(result); |
| 1289 | 1321 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1520 } | 1552 } |
| 1521 crc32s_end_offset_[stream_index] = offset + length; | 1553 crc32s_end_offset_[stream_index] = offset + length; |
| 1522 } else if (offset < crc32s_end_offset_[stream_index]) { | 1554 } else if (offset < crc32s_end_offset_[stream_index]) { |
| 1523 // If a range for which the crc32 was already computed is rewritten, the | 1555 // If a range for which the crc32 was already computed is rewritten, the |
| 1524 // computation of the crc32 need to start from 0 again. | 1556 // computation of the crc32 need to start from 0 again. |
| 1525 crc32s_end_offset_[stream_index] = 0; | 1557 crc32s_end_offset_[stream_index] = 0; |
| 1526 } | 1558 } |
| 1527 } | 1559 } |
| 1528 | 1560 |
| 1529 } // namespace disk_cache | 1561 } // namespace disk_cache |
| OLD | NEW |