| 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 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 // |last_modified_| yet, we make this approximation. | 966 // |last_modified_| yet, we make this approximation. |
| 967 last_used_ = last_modified_ = base::Time::Now(); | 967 last_used_ = last_modified_ = base::Time::Now(); |
| 968 | 968 |
| 969 have_written_[stream_index] = true; | 969 have_written_[stream_index] = true; |
| 970 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF | 970 // Writing on stream 1 affects the placement of stream 0 in the file, the EOF |
| 971 // record will have to be rewritten. | 971 // record will have to be rewritten. |
| 972 if (stream_index == 1) | 972 if (stream_index == 1) |
| 973 have_written_[0] = true; | 973 have_written_[0] = true; |
| 974 | 974 |
| 975 std::unique_ptr<int> result(new int()); | 975 std::unique_ptr<int> result(new int()); |
| 976 | |
| 977 // Retain a reference to |buf| in |reply| instead of |task|, so that we can | |
| 978 // reduce cross thread malloc/free pairs. The cross thread malloc/free pair | |
| 979 // increases the apparent memory usage due to the thread cached free list. | |
| 980 Closure task = base::Bind( | 976 Closure task = base::Bind( |
| 981 &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_), | 977 &SimpleSynchronousEntry::WriteData, base::Unretained(synchronous_entry_), |
| 982 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len, | 978 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len, |
| 983 truncate, doomed_), | 979 truncate, doomed_), |
| 984 base::Unretained(buf), entry_stat.get(), result.get()); | 980 base::RetainedRef(buf), entry_stat.get(), result.get()); |
| 985 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, this, | 981 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, |
| 986 stream_index, callback, base::Passed(&entry_stat), | 982 this, |
| 987 base::Passed(&result), base::RetainedRef(buf)); | 983 stream_index, |
| 984 callback, |
| 985 base::Passed(&entry_stat), |
| 986 base::Passed(&result)); |
| 988 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); | 987 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); |
| 989 } | 988 } |
| 990 | 989 |
| 991 void SimpleEntryImpl::ReadSparseDataInternal( | 990 void SimpleEntryImpl::ReadSparseDataInternal( |
| 992 int64_t sparse_offset, | 991 int64_t sparse_offset, |
| 993 net::IOBuffer* buf, | 992 net::IOBuffer* buf, |
| 994 int buf_len, | 993 int buf_len, |
| 995 const CompletionCallback& callback) { | 994 const CompletionCallback& callback) { |
| 996 DCHECK(io_thread_checker_.CalledOnValidThread()); | 995 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 997 ScopedOperationRunner operation_runner(this); | 996 ScopedOperationRunner operation_runner(this); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 CreateNetLogReadWriteCompleteCallback(*result)); | 1264 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1266 } | 1265 } |
| 1267 | 1266 |
| 1268 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1267 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1269 } | 1268 } |
| 1270 | 1269 |
| 1271 void SimpleEntryImpl::WriteOperationComplete( | 1270 void SimpleEntryImpl::WriteOperationComplete( |
| 1272 int stream_index, | 1271 int stream_index, |
| 1273 const CompletionCallback& completion_callback, | 1272 const CompletionCallback& completion_callback, |
| 1274 std::unique_ptr<SimpleEntryStat> entry_stat, | 1273 std::unique_ptr<SimpleEntryStat> entry_stat, |
| 1275 std::unique_ptr<int> result, | 1274 std::unique_ptr<int> result) { |
| 1276 net::IOBuffer* buf) { | |
| 1277 if (*result >= 0) | 1275 if (*result >= 0) |
| 1278 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); | 1276 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); |
| 1279 else | 1277 else |
| 1280 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); | 1278 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); |
| 1281 if (net_log_.IsCapturing()) { | 1279 if (net_log_.IsCapturing()) { |
| 1282 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END, | 1280 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END, |
| 1283 CreateNetLogReadWriteCompleteCallback(*result)); | 1281 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1284 } | 1282 } |
| 1285 | 1283 |
| 1286 if (*result < 0) { | 1284 if (*result < 0) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1564 } | 1562 } |
| 1565 crc32s_end_offset_[stream_index] = offset + length; | 1563 crc32s_end_offset_[stream_index] = offset + length; |
| 1566 } else if (offset < crc32s_end_offset_[stream_index]) { | 1564 } else if (offset < crc32s_end_offset_[stream_index]) { |
| 1567 // If a range for which the crc32 was already computed is rewritten, the | 1565 // If a range for which the crc32 was already computed is rewritten, the |
| 1568 // computation of the crc32 need to start from 0 again. | 1566 // computation of the crc32 need to start from 0 again. |
| 1569 crc32s_end_offset_[stream_index] = 0; | 1567 crc32s_end_offset_[stream_index] = 0; |
| 1570 } | 1568 } |
| 1571 } | 1569 } |
| 1572 | 1570 |
| 1573 } // namespace disk_cache | 1571 } // namespace disk_cache |
| OLD | NEW |