Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Side by Side Diff: net/disk_cache/simple/simple_entry_impl.cc

Issue 1498003003: Remove kint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: INT64_MAX Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | net/quic/quic_time.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 10 #include <vector>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
13 #include "base/callback.h" 14 #include "base/callback.h"
14 #include "base/location.h" 15 #include "base/location.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/task_runner.h" 18 #include "base/task_runner.h"
18 #include "base/task_runner_util.h" 19 #include "base/task_runner_util.h"
19 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
20 #include "base/time/time.h" 21 #include "base/time/time.h"
21 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
22 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
23 #include "net/disk_cache/net_log_parameters.h" 24 #include "net/disk_cache/net_log_parameters.h"
24 #include "net/disk_cache/simple/simple_backend_impl.h" 25 #include "net/disk_cache/simple/simple_backend_impl.h"
25 #include "net/disk_cache/simple/simple_histogram_macros.h" 26 #include "net/disk_cache/simple/simple_histogram_macros.h"
26 #include "net/disk_cache/simple/simple_index.h" 27 #include "net/disk_cache/simple/simple_index.h"
27 #include "net/disk_cache/simple/simple_net_log_parameters.h" 28 #include "net/disk_cache/simple/simple_net_log_parameters.h"
28 #include "net/disk_cache/simple/simple_synchronous_entry.h" 29 #include "net/disk_cache/simple/simple_synchronous_entry.h"
29 #include "net/disk_cache/simple/simple_util.h" 30 #include "net/disk_cache/simple/simple_util.h"
30 #include "third_party/zlib/zlib.h" 31 #include "third_party/zlib/zlib.h"
31 32
32 namespace disk_cache { 33 namespace disk_cache {
33 namespace { 34 namespace {
34 35
35 // An entry can store sparse data taking up to 1 / kMaxSparseDataSizeDivisor of 36 // An entry can store sparse data taking up to 1 / kMaxSparseDataSizeDivisor of
36 // the cache. 37 // the cache.
37 const int64 kMaxSparseDataSizeDivisor = 10; 38 const int64_t kMaxSparseDataSizeDivisor = 10;
38 39
39 // Used in histograms, please only add entries at the end. 40 // Used in histograms, please only add entries at the end.
40 enum ReadResult { 41 enum ReadResult {
41 READ_RESULT_SUCCESS = 0, 42 READ_RESULT_SUCCESS = 0,
42 READ_RESULT_INVALID_ARGUMENT = 1, 43 READ_RESULT_INVALID_ARGUMENT = 1,
43 READ_RESULT_NONBLOCK_EMPTY_RETURN = 2, 44 READ_RESULT_NONBLOCK_EMPTY_RETURN = 2,
44 READ_RESULT_BAD_STATE = 3, 45 READ_RESULT_BAD_STATE = 3,
45 READ_RESULT_FAST_EMPTY_RETURN = 4, 46 READ_RESULT_FAST_EMPTY_RETURN = 4,
46 READ_RESULT_SYNC_READ_FAILURE = 5, 47 READ_RESULT_SYNC_READ_FAILURE = 5,
47 READ_RESULT_SYNC_CHECKSUM_FAILURE = 6, 48 READ_RESULT_SYNC_CHECKSUM_FAILURE = 6,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 158 }
158 159
159 private: 160 private:
160 SimpleEntryImpl* const entry_; 161 SimpleEntryImpl* const entry_;
161 }; 162 };
162 163
163 SimpleEntryImpl::ActiveEntryProxy::~ActiveEntryProxy() {} 164 SimpleEntryImpl::ActiveEntryProxy::~ActiveEntryProxy() {}
164 165
165 SimpleEntryImpl::SimpleEntryImpl(net::CacheType cache_type, 166 SimpleEntryImpl::SimpleEntryImpl(net::CacheType cache_type,
166 const FilePath& path, 167 const FilePath& path,
167 const uint64 entry_hash, 168 const uint64_t entry_hash,
168 OperationsMode operations_mode, 169 OperationsMode operations_mode,
169 SimpleBackendImpl* backend, 170 SimpleBackendImpl* backend,
170 net::NetLog* net_log) 171 net::NetLog* net_log)
171 : backend_(backend->AsWeakPtr()), 172 : backend_(backend->AsWeakPtr()),
172 cache_type_(cache_type), 173 cache_type_(cache_type),
173 worker_pool_(backend->worker_pool()), 174 worker_pool_(backend->worker_pool()),
174 path_(path), 175 path_(path),
175 entry_hash_(entry_hash), 176 entry_hash_(entry_hash),
176 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS), 177 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS),
177 last_used_(Time::Now()), 178 last_used_(Time::Now()),
178 last_modified_(last_used_), 179 last_modified_(last_used_),
179 sparse_data_size_(0), 180 sparse_data_size_(0),
180 open_count_(0), 181 open_count_(0),
181 doomed_(false), 182 doomed_(false),
182 state_(STATE_UNINITIALIZED), 183 state_(STATE_UNINITIALIZED),
183 synchronous_entry_(NULL), 184 synchronous_entry_(NULL),
184 net_log_(net::BoundNetLog::Make( 185 net_log_(net::BoundNetLog::Make(net_log,
185 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY)), 186 net::NetLog::SOURCE_DISK_CACHE_ENTRY)),
186 stream_0_data_(new net::GrowableIOBuffer()) { 187 stream_0_data_(new net::GrowableIOBuffer()) {
187 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_), 188 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_),
188 "arrays should be the same size"); 189 "arrays should be the same size");
189 static_assert(arraysize(data_size_) == arraysize(crc32s_), 190 static_assert(arraysize(data_size_) == arraysize(crc32s_),
190 "arrays should be the same size"); 191 "arrays should be the same size");
191 static_assert(arraysize(data_size_) == arraysize(have_written_), 192 static_assert(arraysize(data_size_) == arraysize(have_written_),
192 "arrays should be the same size"); 193 "arrays should be the same size");
193 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), 194 static_assert(arraysize(data_size_) == arraysize(crc_check_state_),
194 "arrays should be the same size"); 195 "arrays should be the same size");
195 MakeUninitialized(); 196 MakeUninitialized();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 Time SimpleEntryImpl::GetLastUsed() const { 327 Time SimpleEntryImpl::GetLastUsed() const {
327 DCHECK(io_thread_checker_.CalledOnValidThread()); 328 DCHECK(io_thread_checker_.CalledOnValidThread());
328 return last_used_; 329 return last_used_;
329 } 330 }
330 331
331 Time SimpleEntryImpl::GetLastModified() const { 332 Time SimpleEntryImpl::GetLastModified() const {
332 DCHECK(io_thread_checker_.CalledOnValidThread()); 333 DCHECK(io_thread_checker_.CalledOnValidThread());
333 return last_modified_; 334 return last_modified_;
334 } 335 }
335 336
336 int32 SimpleEntryImpl::GetDataSize(int stream_index) const { 337 int32_t SimpleEntryImpl::GetDataSize(int stream_index) const {
337 DCHECK(io_thread_checker_.CalledOnValidThread()); 338 DCHECK(io_thread_checker_.CalledOnValidThread());
338 DCHECK_LE(0, data_size_[stream_index]); 339 DCHECK_LE(0, data_size_[stream_index]);
339 return data_size_[stream_index]; 340 return data_size_[stream_index];
340 } 341 }
341 342
342 int SimpleEntryImpl::ReadData(int stream_index, 343 int SimpleEntryImpl::ReadData(int stream_index,
343 int offset, 344 int offset,
344 net::IOBuffer* buf, 345 net::IOBuffer* buf,
345 int buf_len, 346 int buf_len,
346 const CompletionCallback& callback) { 347 const CompletionCallback& callback) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 stream_index, 465 stream_index,
465 offset, 466 offset,
466 buf_len, 467 buf_len,
467 op_buf.get(), 468 op_buf.get(),
468 truncate, 469 truncate,
469 optimistic, 470 optimistic,
470 op_callback)); 471 op_callback));
471 return ret_value; 472 return ret_value;
472 } 473 }
473 474
474 int SimpleEntryImpl::ReadSparseData(int64 offset, 475 int SimpleEntryImpl::ReadSparseData(int64_t offset,
475 net::IOBuffer* buf, 476 net::IOBuffer* buf,
476 int buf_len, 477 int buf_len,
477 const CompletionCallback& callback) { 478 const CompletionCallback& callback) {
478 DCHECK(io_thread_checker_.CalledOnValidThread()); 479 DCHECK(io_thread_checker_.CalledOnValidThread());
479 480
480 ScopedOperationRunner operation_runner(this); 481 ScopedOperationRunner operation_runner(this);
481 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation( 482 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation(
482 this, offset, buf_len, buf, callback)); 483 this, offset, buf_len, buf, callback));
483 return net::ERR_IO_PENDING; 484 return net::ERR_IO_PENDING;
484 } 485 }
485 486
486 int SimpleEntryImpl::WriteSparseData(int64 offset, 487 int SimpleEntryImpl::WriteSparseData(int64_t offset,
487 net::IOBuffer* buf, 488 net::IOBuffer* buf,
488 int buf_len, 489 int buf_len,
489 const CompletionCallback& callback) { 490 const CompletionCallback& callback) {
490 DCHECK(io_thread_checker_.CalledOnValidThread()); 491 DCHECK(io_thread_checker_.CalledOnValidThread());
491 492
492 ScopedOperationRunner operation_runner(this); 493 ScopedOperationRunner operation_runner(this);
493 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation( 494 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation(
494 this, offset, buf_len, buf, callback)); 495 this, offset, buf_len, buf, callback));
495 return net::ERR_IO_PENDING; 496 return net::ERR_IO_PENDING;
496 } 497 }
497 498
498 int SimpleEntryImpl::GetAvailableRange(int64 offset, 499 int SimpleEntryImpl::GetAvailableRange(int64_t offset,
499 int len, 500 int len,
500 int64* start, 501 int64_t* start,
501 const CompletionCallback& callback) { 502 const CompletionCallback& callback) {
502 DCHECK(io_thread_checker_.CalledOnValidThread()); 503 DCHECK(io_thread_checker_.CalledOnValidThread());
503 504
504 ScopedOperationRunner operation_runner(this); 505 ScopedOperationRunner operation_runner(this);
505 pending_operations_.push(SimpleEntryOperation::GetAvailableRangeOperation( 506 pending_operations_.push(SimpleEntryOperation::GetAvailableRangeOperation(
506 this, offset, len, start, callback)); 507 this, offset, len, start, callback));
507 return net::ERR_IO_PENDING; 508 return net::ERR_IO_PENDING;
508 } 509 }
509 510
510 bool SimpleEntryImpl::CouldBeSparse() const { 511 bool SimpleEntryImpl::CouldBeSparse() const {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 crc32s_to_write(new std::vector<CRCRecord>()); 759 crc32s_to_write(new std::vector<CRCRecord>());
759 760
760 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_BEGIN); 761 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_BEGIN);
761 762
762 if (state_ == STATE_READY) { 763 if (state_ == STATE_READY) {
763 DCHECK(synchronous_entry_); 764 DCHECK(synchronous_entry_);
764 state_ = STATE_IO_PENDING; 765 state_ = STATE_IO_PENDING;
765 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 766 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
766 if (have_written_[i]) { 767 if (have_written_[i]) {
767 if (GetDataSize(i) == crc32s_end_offset_[i]) { 768 if (GetDataSize(i) == crc32s_end_offset_[i]) {
768 int32 crc = GetDataSize(i) == 0 ? crc32(0, Z_NULL, 0) : crc32s_[i]; 769 int32_t crc = GetDataSize(i) == 0 ? crc32(0, Z_NULL, 0) : crc32s_[i];
769 crc32s_to_write->push_back(CRCRecord(i, true, crc)); 770 crc32s_to_write->push_back(CRCRecord(i, true, crc));
770 } else { 771 } else {
771 crc32s_to_write->push_back(CRCRecord(i, false, 0)); 772 crc32s_to_write->push_back(CRCRecord(i, false, 0));
772 } 773 }
773 } 774 }
774 } 775 }
775 } else { 776 } else {
776 DCHECK(STATE_UNINITIALIZED == state_ || STATE_FAILURE == state_); 777 DCHECK(STATE_UNINITIALIZED == state_ || STATE_FAILURE == state_);
777 } 778 }
778 779
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 base::ThreadTaskRunnerHandle::Get()->PostTask( 852 base::ThreadTaskRunnerHandle::Get()->PostTask(
852 FROM_HERE, base::Bind(callback, ret_value)); 853 FROM_HERE, base::Bind(callback, ret_value));
853 } 854 }
854 return; 855 return;
855 } 856 }
856 857
857 state_ = STATE_IO_PENDING; 858 state_ = STATE_IO_PENDING;
858 if (!doomed_ && backend_.get()) 859 if (!doomed_ && backend_.get())
859 backend_->index()->UseIfExists(entry_hash_); 860 backend_->index()->UseIfExists(entry_hash_);
860 861
861 scoped_ptr<uint32> read_crc32(new uint32()); 862 scoped_ptr<uint32_t> read_crc32(new uint32_t());
862 scoped_ptr<int> result(new int()); 863 scoped_ptr<int> result(new int());
863 scoped_ptr<SimpleEntryStat> entry_stat( 864 scoped_ptr<SimpleEntryStat> entry_stat(
864 new SimpleEntryStat(last_used_, last_modified_, data_size_, 865 new SimpleEntryStat(last_used_, last_modified_, data_size_,
865 sparse_data_size_)); 866 sparse_data_size_));
866 Closure task = base::Bind( 867 Closure task = base::Bind(
867 &SimpleSynchronousEntry::ReadData, 868 &SimpleSynchronousEntry::ReadData,
868 base::Unretained(synchronous_entry_), 869 base::Unretained(synchronous_entry_),
869 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len), 870 SimpleSynchronousEntry::EntryOperationData(stream_index, offset, buf_len),
870 make_scoped_refptr(buf), 871 make_scoped_refptr(buf),
871 read_crc32.get(), 872 read_crc32.get(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 int ret_value = SetStream0Data(buf, offset, buf_len, truncate); 921 int ret_value = SetStream0Data(buf, offset, buf_len, truncate);
921 if (!callback.is_null()) { 922 if (!callback.is_null()) {
922 base::ThreadTaskRunnerHandle::Get()->PostTask( 923 base::ThreadTaskRunnerHandle::Get()->PostTask(
923 FROM_HERE, base::Bind(callback, ret_value)); 924 FROM_HERE, base::Bind(callback, ret_value));
924 } 925 }
925 return; 926 return;
926 } 927 }
927 928
928 // Ignore zero-length writes that do not change the file size. 929 // Ignore zero-length writes that do not change the file size.
929 if (buf_len == 0) { 930 if (buf_len == 0) {
930 int32 data_size = data_size_[stream_index]; 931 int32_t data_size = data_size_[stream_index];
931 if (truncate ? (offset == data_size) : (offset <= data_size)) { 932 if (truncate ? (offset == data_size) : (offset <= data_size)) {
932 RecordWriteResult(cache_type_, WRITE_RESULT_FAST_EMPTY_RETURN); 933 RecordWriteResult(cache_type_, WRITE_RESULT_FAST_EMPTY_RETURN);
933 if (!callback.is_null()) { 934 if (!callback.is_null()) {
934 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 935 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
935 base::Bind(callback, 0)); 936 base::Bind(callback, 0));
936 } 937 }
937 return; 938 return;
938 } 939 }
939 } 940 }
940 state_ = STATE_IO_PENDING; 941 state_ = STATE_IO_PENDING;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete, 977 Closure reply = base::Bind(&SimpleEntryImpl::WriteOperationComplete,
977 this, 978 this,
978 stream_index, 979 stream_index,
979 callback, 980 callback,
980 base::Passed(&entry_stat), 981 base::Passed(&entry_stat),
981 base::Passed(&result)); 982 base::Passed(&result));
982 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 983 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
983 } 984 }
984 985
985 void SimpleEntryImpl::ReadSparseDataInternal( 986 void SimpleEntryImpl::ReadSparseDataInternal(
986 int64 sparse_offset, 987 int64_t sparse_offset,
987 net::IOBuffer* buf, 988 net::IOBuffer* buf,
988 int buf_len, 989 int buf_len,
989 const CompletionCallback& callback) { 990 const CompletionCallback& callback) {
990 DCHECK(io_thread_checker_.CalledOnValidThread()); 991 DCHECK(io_thread_checker_.CalledOnValidThread());
991 ScopedOperationRunner operation_runner(this); 992 ScopedOperationRunner operation_runner(this);
992 993
993 DCHECK_EQ(STATE_READY, state_); 994 DCHECK_EQ(STATE_READY, state_);
994 state_ = STATE_IO_PENDING; 995 state_ = STATE_IO_PENDING;
995 996
996 scoped_ptr<int> result(new int()); 997 scoped_ptr<int> result(new int());
997 scoped_ptr<base::Time> last_used(new base::Time()); 998 scoped_ptr<base::Time> last_used(new base::Time());
998 Closure task = base::Bind(&SimpleSynchronousEntry::ReadSparseData, 999 Closure task = base::Bind(&SimpleSynchronousEntry::ReadSparseData,
999 base::Unretained(synchronous_entry_), 1000 base::Unretained(synchronous_entry_),
1000 SimpleSynchronousEntry::EntryOperationData( 1001 SimpleSynchronousEntry::EntryOperationData(
1001 sparse_offset, buf_len), 1002 sparse_offset, buf_len),
1002 make_scoped_refptr(buf), 1003 make_scoped_refptr(buf),
1003 last_used.get(), 1004 last_used.get(),
1004 result.get()); 1005 result.get());
1005 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete, 1006 Closure reply = base::Bind(&SimpleEntryImpl::ReadSparseOperationComplete,
1006 this, 1007 this,
1007 callback, 1008 callback,
1008 base::Passed(&last_used), 1009 base::Passed(&last_used),
1009 base::Passed(&result)); 1010 base::Passed(&result));
1010 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 1011 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
1011 } 1012 }
1012 1013
1013 void SimpleEntryImpl::WriteSparseDataInternal( 1014 void SimpleEntryImpl::WriteSparseDataInternal(
1014 int64 sparse_offset, 1015 int64_t sparse_offset,
1015 net::IOBuffer* buf, 1016 net::IOBuffer* buf,
1016 int buf_len, 1017 int buf_len,
1017 const CompletionCallback& callback) { 1018 const CompletionCallback& callback) {
1018 DCHECK(io_thread_checker_.CalledOnValidThread()); 1019 DCHECK(io_thread_checker_.CalledOnValidThread());
1019 ScopedOperationRunner operation_runner(this); 1020 ScopedOperationRunner operation_runner(this);
1020 1021
1021 DCHECK_EQ(STATE_READY, state_); 1022 DCHECK_EQ(STATE_READY, state_);
1022 state_ = STATE_IO_PENDING; 1023 state_ = STATE_IO_PENDING;
1023 1024
1024 uint64 max_sparse_data_size = kint64max; 1025 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max();
1025 if (backend_.get()) { 1026 if (backend_.get()) {
1026 uint64 max_cache_size = backend_->index()->max_size(); 1027 uint64_t max_cache_size = backend_->index()->max_size();
1027 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; 1028 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor;
1028 } 1029 }
1029 1030
1030 scoped_ptr<SimpleEntryStat> entry_stat( 1031 scoped_ptr<SimpleEntryStat> entry_stat(
1031 new SimpleEntryStat(last_used_, last_modified_, data_size_, 1032 new SimpleEntryStat(last_used_, last_modified_, data_size_,
1032 sparse_data_size_)); 1033 sparse_data_size_));
1033 1034
1034 last_used_ = last_modified_ = base::Time::Now(); 1035 last_used_ = last_modified_ = base::Time::Now();
1035 1036
1036 scoped_ptr<int> result(new int()); 1037 scoped_ptr<int> result(new int());
1037 Closure task = base::Bind(&SimpleSynchronousEntry::WriteSparseData, 1038 Closure task = base::Bind(&SimpleSynchronousEntry::WriteSparseData,
1038 base::Unretained(synchronous_entry_), 1039 base::Unretained(synchronous_entry_),
1039 SimpleSynchronousEntry::EntryOperationData( 1040 SimpleSynchronousEntry::EntryOperationData(
1040 sparse_offset, buf_len), 1041 sparse_offset, buf_len),
1041 make_scoped_refptr(buf), 1042 make_scoped_refptr(buf),
1042 max_sparse_data_size, 1043 max_sparse_data_size,
1043 entry_stat.get(), 1044 entry_stat.get(),
1044 result.get()); 1045 result.get());
1045 Closure reply = base::Bind(&SimpleEntryImpl::WriteSparseOperationComplete, 1046 Closure reply = base::Bind(&SimpleEntryImpl::WriteSparseOperationComplete,
1046 this, 1047 this,
1047 callback, 1048 callback,
1048 base::Passed(&entry_stat), 1049 base::Passed(&entry_stat),
1049 base::Passed(&result)); 1050 base::Passed(&result));
1050 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); 1051 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply);
1051 } 1052 }
1052 1053
1053 void SimpleEntryImpl::GetAvailableRangeInternal( 1054 void SimpleEntryImpl::GetAvailableRangeInternal(
1054 int64 sparse_offset, 1055 int64_t sparse_offset,
1055 int len, 1056 int len,
1056 int64* out_start, 1057 int64_t* out_start,
1057 const CompletionCallback& callback) { 1058 const CompletionCallback& callback) {
1058 DCHECK(io_thread_checker_.CalledOnValidThread()); 1059 DCHECK(io_thread_checker_.CalledOnValidThread());
1059 ScopedOperationRunner operation_runner(this); 1060 ScopedOperationRunner operation_runner(this);
1060 1061
1061 DCHECK_EQ(STATE_READY, state_); 1062 DCHECK_EQ(STATE_READY, state_);
1062 state_ = STATE_IO_PENDING; 1063 state_ = STATE_IO_PENDING;
1063 1064
1064 scoped_ptr<int> result(new int()); 1065 scoped_ptr<int> result(new int());
1065 Closure task = base::Bind(&SimpleSynchronousEntry::GetAvailableRange, 1066 Closure task = base::Bind(&SimpleSynchronousEntry::GetAvailableRange,
1066 base::Unretained(synchronous_entry_), 1067 base::Unretained(synchronous_entry_),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 base::ThreadTaskRunnerHandle::Get()->PostTask( 1160 base::ThreadTaskRunnerHandle::Get()->PostTask(
1160 FROM_HERE, base::Bind(completion_callback, *result)); 1161 FROM_HERE, base::Bind(completion_callback, *result));
1161 } 1162 }
1162 RunNextOperationIfNeeded(); 1163 RunNextOperationIfNeeded();
1163 } 1164 }
1164 1165
1165 void SimpleEntryImpl::ReadOperationComplete( 1166 void SimpleEntryImpl::ReadOperationComplete(
1166 int stream_index, 1167 int stream_index,
1167 int offset, 1168 int offset,
1168 const CompletionCallback& completion_callback, 1169 const CompletionCallback& completion_callback,
1169 scoped_ptr<uint32> read_crc32, 1170 scoped_ptr<uint32_t> read_crc32,
1170 scoped_ptr<SimpleEntryStat> entry_stat, 1171 scoped_ptr<SimpleEntryStat> entry_stat,
1171 scoped_ptr<int> result) { 1172 scoped_ptr<int> result) {
1172 DCHECK(io_thread_checker_.CalledOnValidThread()); 1173 DCHECK(io_thread_checker_.CalledOnValidThread());
1173 DCHECK(synchronous_entry_); 1174 DCHECK(synchronous_entry_);
1174 DCHECK_EQ(STATE_IO_PENDING, state_); 1175 DCHECK_EQ(STATE_IO_PENDING, state_);
1175 DCHECK(read_crc32); 1176 DCHECK(read_crc32);
1176 DCHECK(result); 1177 DCHECK(result);
1177 1178
1178 if (*result > 0 && 1179 if (*result > 0 &&
1179 crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_AT_ALL) { 1180 crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_AT_ALL) {
1180 crc_check_state_[stream_index] = CRC_CHECK_NEVER_READ_TO_END; 1181 crc_check_state_[stream_index] = CRC_CHECK_NEVER_READ_TO_END;
1181 } 1182 }
1182 1183
1183 if (*result > 0 && crc32s_end_offset_[stream_index] == offset) { 1184 if (*result > 0 && crc32s_end_offset_[stream_index] == offset) {
1184 uint32 current_crc = offset == 0 ? crc32(0, Z_NULL, 0) 1185 uint32_t current_crc =
1185 : crc32s_[stream_index]; 1186 offset == 0 ? crc32(0, Z_NULL, 0) : crc32s_[stream_index];
1186 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result); 1187 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result);
1187 crc32s_end_offset_[stream_index] += *result; 1188 crc32s_end_offset_[stream_index] += *result;
1188 if (!have_written_[stream_index] && 1189 if (!have_written_[stream_index] &&
1189 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) { 1190 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) {
1190 // We have just read a file from start to finish, and so we have 1191 // We have just read a file from start to finish, and so we have
1191 // computed a crc of the entire file. We can check it now. If a cache 1192 // computed a crc of the entire file. We can check it now. If a cache
1192 // entry has a single reader, the normal pattern is to read from start 1193 // entry has a single reader, the normal pattern is to read from start
1193 // to finish. 1194 // to finish.
1194 1195
1195 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN); 1196 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 last_used_ = entry_stat.last_used(); 1359 last_used_ = entry_stat.last_used();
1359 last_modified_ = entry_stat.last_modified(); 1360 last_modified_ = entry_stat.last_modified();
1360 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 1361 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
1361 data_size_[i] = entry_stat.data_size(i); 1362 data_size_[i] = entry_stat.data_size(i);
1362 } 1363 }
1363 sparse_data_size_ = entry_stat.sparse_data_size(); 1364 sparse_data_size_ = entry_stat.sparse_data_size();
1364 if (!doomed_ && backend_.get()) 1365 if (!doomed_ && backend_.get())
1365 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage()); 1366 backend_->index()->UpdateEntrySize(entry_hash_, GetDiskUsage());
1366 } 1367 }
1367 1368
1368 int64 SimpleEntryImpl::GetDiskUsage() const { 1369 int64_t SimpleEntryImpl::GetDiskUsage() const {
1369 int64 file_size = 0; 1370 int64_t file_size = 0;
1370 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { 1371 for (int i = 0; i < kSimpleEntryStreamCount; ++i) {
1371 file_size += 1372 file_size +=
1372 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]); 1373 simple_util::GetFileSizeFromKeyAndDataSize(key_, data_size_[i]);
1373 } 1374 }
1374 file_size += sparse_data_size_; 1375 file_size += sparse_data_size_;
1375 return file_size; 1376 return file_size;
1376 } 1377 }
1377 1378
1378 void SimpleEntryImpl::RecordReadIsParallelizable( 1379 void SimpleEntryImpl::RecordReadIsParallelizable(
1379 const SimpleEntryOperation& operation) const { 1380 const SimpleEntryOperation& operation) const {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 void SimpleEntryImpl::AdvanceCrc(net::IOBuffer* buffer, 1504 void SimpleEntryImpl::AdvanceCrc(net::IOBuffer* buffer,
1504 int offset, 1505 int offset,
1505 int length, 1506 int length,
1506 int stream_index) { 1507 int stream_index) {
1507 // It is easy to incrementally compute the CRC from [0 .. |offset + buf_len|) 1508 // It is easy to incrementally compute the CRC from [0 .. |offset + buf_len|)
1508 // if |offset == 0| or we have already computed the CRC for [0 .. offset). 1509 // if |offset == 0| or we have already computed the CRC for [0 .. offset).
1509 // We rely on most write operations being sequential, start to end to compute 1510 // We rely on most write operations being sequential, start to end to compute
1510 // the crc of the data. When we write to an entry and close without having 1511 // the crc of the data. When we write to an entry and close without having
1511 // done a sequential write, we don't check the CRC on read. 1512 // done a sequential write, we don't check the CRC on read.
1512 if (offset == 0 || crc32s_end_offset_[stream_index] == offset) { 1513 if (offset == 0 || crc32s_end_offset_[stream_index] == offset) {
1513 uint32 initial_crc = 1514 uint32_t initial_crc =
1514 (offset != 0) ? crc32s_[stream_index] : crc32(0, Z_NULL, 0); 1515 (offset != 0) ? crc32s_[stream_index] : crc32(0, Z_NULL, 0);
1515 if (length > 0) { 1516 if (length > 0) {
1516 crc32s_[stream_index] = crc32( 1517 crc32s_[stream_index] = crc32(
1517 initial_crc, reinterpret_cast<const Bytef*>(buffer->data()), length); 1518 initial_crc, reinterpret_cast<const Bytef*>(buffer->data()), length);
1518 } 1519 }
1519 crc32s_end_offset_[stream_index] = offset + length; 1520 crc32s_end_offset_[stream_index] = offset + length;
1520 } else if (offset < crc32s_end_offset_[stream_index]) { 1521 } else if (offset < crc32s_end_offset_[stream_index]) {
1521 // If a range for which the crc32 was already computed is rewritten, the 1522 // If a range for which the crc32 was already computed is rewritten, the
1522 // computation of the crc32 need to start from 0 again. 1523 // computation of the crc32 need to start from 0 again.
1523 crc32s_end_offset_[stream_index] = 0; 1524 crc32s_end_offset_[stream_index] = 0;
1524 } 1525 }
1525 } 1526 }
1526 1527
1527 } // namespace disk_cache 1528 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | net/quic/quic_time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698