| 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 11 matching lines...) Expand all Loading... |
| 22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/disk_cache/net_log_parameters.h" | 25 #include "net/disk_cache/net_log_parameters.h" |
| 26 #include "net/disk_cache/simple/simple_backend_impl.h" | 26 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 27 #include "net/disk_cache/simple/simple_histogram_macros.h" | 27 #include "net/disk_cache/simple/simple_histogram_macros.h" |
| 28 #include "net/disk_cache/simple/simple_index.h" | 28 #include "net/disk_cache/simple/simple_index.h" |
| 29 #include "net/disk_cache/simple/simple_net_log_parameters.h" | 29 #include "net/disk_cache/simple/simple_net_log_parameters.h" |
| 30 #include "net/disk_cache/simple/simple_synchronous_entry.h" | 30 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
| 31 #include "net/disk_cache/simple/simple_util.h" | 31 #include "net/disk_cache/simple/simple_util.h" |
| 32 #include "net/log/net_log_source_type.h" |
| 32 #include "third_party/zlib/zlib.h" | 33 #include "third_party/zlib/zlib.h" |
| 33 | 34 |
| 34 namespace disk_cache { | 35 namespace disk_cache { |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 // An entry can store sparse data taking up to 1 / kMaxSparseDataSizeDivisor of | 38 // An entry can store sparse data taking up to 1 / kMaxSparseDataSizeDivisor of |
| 38 // the cache. | 39 // the cache. |
| 39 const int64_t kMaxSparseDataSizeDivisor = 10; | 40 const int64_t kMaxSparseDataSizeDivisor = 10; |
| 40 | 41 |
| 41 // Used in histograms, please only add entries at the end. | 42 // Used in histograms, please only add entries at the end. |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 entry_hash_(entry_hash), | 178 entry_hash_(entry_hash), |
| 178 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS), | 179 use_optimistic_operations_(operations_mode == OPTIMISTIC_OPERATIONS), |
| 179 last_used_(Time::Now()), | 180 last_used_(Time::Now()), |
| 180 last_modified_(last_used_), | 181 last_modified_(last_used_), |
| 181 sparse_data_size_(0), | 182 sparse_data_size_(0), |
| 182 open_count_(0), | 183 open_count_(0), |
| 183 doomed_(false), | 184 doomed_(false), |
| 184 state_(STATE_UNINITIALIZED), | 185 state_(STATE_UNINITIALIZED), |
| 185 synchronous_entry_(NULL), | 186 synchronous_entry_(NULL), |
| 186 net_log_(net::BoundNetLog::Make(net_log, | 187 net_log_(net::BoundNetLog::Make(net_log, |
| 187 net::NetLog::SOURCE_DISK_CACHE_ENTRY)), | 188 net::NetLogSourceType::DISK_CACHE_ENTRY)), |
| 188 stream_0_data_(new net::GrowableIOBuffer()) { | 189 stream_0_data_(new net::GrowableIOBuffer()) { |
| 189 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_), | 190 static_assert(arraysize(data_size_) == arraysize(crc32s_end_offset_), |
| 190 "arrays should be the same size"); | 191 "arrays should be the same size"); |
| 191 static_assert(arraysize(data_size_) == arraysize(crc32s_), | 192 static_assert(arraysize(data_size_) == arraysize(crc32s_), |
| 192 "arrays should be the same size"); | 193 "arrays should be the same size"); |
| 193 static_assert(arraysize(data_size_) == arraysize(have_written_), | 194 static_assert(arraysize(data_size_) == arraysize(have_written_), |
| 194 "arrays should be the same size"); | 195 "arrays should be the same size"); |
| 195 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), | 196 static_assert(arraysize(data_size_) == arraysize(crc_check_state_), |
| 196 "arrays should be the same size"); | 197 "arrays should be the same size"); |
| 197 MakeUninitialized(); | 198 MakeUninitialized(); |
| 198 net_log_.BeginEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY, | 199 net_log_.BeginEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY, |
| 199 CreateNetLogSimpleEntryConstructionCallback(this)); | 200 CreateNetLogSimpleEntryConstructionCallback(this)); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void SimpleEntryImpl::SetActiveEntryProxy( | 203 void SimpleEntryImpl::SetActiveEntryProxy( |
| 203 std::unique_ptr<ActiveEntryProxy> active_entry_proxy) { | 204 std::unique_ptr<ActiveEntryProxy> active_entry_proxy) { |
| 204 DCHECK(!active_entry_proxy_); | 205 DCHECK(!active_entry_proxy_); |
| 205 active_entry_proxy_.reset(active_entry_proxy.release()); | 206 active_entry_proxy_.reset(active_entry_proxy.release()); |
| 206 } | 207 } |
| 207 | 208 |
| 208 int SimpleEntryImpl::OpenEntry(Entry** out_entry, | 209 int SimpleEntryImpl::OpenEntry(Entry** out_entry, |
| 209 const CompletionCallback& callback) { | 210 const CompletionCallback& callback) { |
| 210 DCHECK(backend_.get()); | 211 DCHECK(backend_.get()); |
| 211 | 212 |
| 212 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_CALL); | 213 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_CALL); |
| 213 | 214 |
| 214 bool have_index = backend_->index()->initialized(); | 215 bool have_index = backend_->index()->initialized(); |
| 215 // This enumeration is used in histograms, add entries only at end. | 216 // This enumeration is used in histograms, add entries only at end. |
| 216 enum OpenEntryIndexEnum { | 217 enum OpenEntryIndexEnum { |
| 217 INDEX_NOEXIST = 0, | 218 INDEX_NOEXIST = 0, |
| 218 INDEX_MISS = 1, | 219 INDEX_MISS = 1, |
| 219 INDEX_HIT = 2, | 220 INDEX_HIT = 2, |
| 220 INDEX_MAX = 3, | 221 INDEX_MAX = 3, |
| 221 }; | 222 }; |
| 222 OpenEntryIndexEnum open_entry_index_enum = INDEX_NOEXIST; | 223 OpenEntryIndexEnum open_entry_index_enum = INDEX_NOEXIST; |
| 223 if (have_index) { | 224 if (have_index) { |
| 224 if (backend_->index()->Has(entry_hash_)) | 225 if (backend_->index()->Has(entry_hash_)) |
| 225 open_entry_index_enum = INDEX_HIT; | 226 open_entry_index_enum = INDEX_HIT; |
| 226 else | 227 else |
| 227 open_entry_index_enum = INDEX_MISS; | 228 open_entry_index_enum = INDEX_MISS; |
| 228 } | 229 } |
| 229 SIMPLE_CACHE_UMA(ENUMERATION, | 230 SIMPLE_CACHE_UMA(ENUMERATION, |
| 230 "OpenEntryIndexState", cache_type_, | 231 "OpenEntryIndexState", cache_type_, |
| 231 open_entry_index_enum, INDEX_MAX); | 232 open_entry_index_enum, INDEX_MAX); |
| 232 | 233 |
| 233 // If entry is not known to the index, initiate fast failover to the network. | 234 // If entry is not known to the index, initiate fast failover to the network. |
| 234 if (open_entry_index_enum == INDEX_MISS) { | 235 if (open_entry_index_enum == INDEX_MISS) { |
| 235 net_log_.AddEventWithNetErrorCode( | 236 net_log_.AddEventWithNetErrorCode( |
| 236 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, | 237 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END, net::ERR_FAILED); |
| 237 net::ERR_FAILED); | |
| 238 return net::ERR_FAILED; | 238 return net::ERR_FAILED; |
| 239 } | 239 } |
| 240 | 240 |
| 241 pending_operations_.push(SimpleEntryOperation::OpenOperation( | 241 pending_operations_.push(SimpleEntryOperation::OpenOperation( |
| 242 this, have_index, callback, out_entry)); | 242 this, have_index, callback, out_entry)); |
| 243 RunNextOperationIfNeeded(); | 243 RunNextOperationIfNeeded(); |
| 244 return net::ERR_IO_PENDING; | 244 return net::ERR_IO_PENDING; |
| 245 } | 245 } |
| 246 | 246 |
| 247 int SimpleEntryImpl::CreateEntry(Entry** out_entry, | 247 int SimpleEntryImpl::CreateEntry(Entry** out_entry, |
| 248 const CompletionCallback& callback) { | 248 const CompletionCallback& callback) { |
| 249 DCHECK(backend_.get()); | 249 DCHECK(backend_.get()); |
| 250 DCHECK_EQ(entry_hash_, simple_util::GetEntryHashKey(key_)); | 250 DCHECK_EQ(entry_hash_, simple_util::GetEntryHashKey(key_)); |
| 251 | 251 |
| 252 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_CALL); | 252 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_CALL); |
| 253 | 253 |
| 254 bool have_index = backend_->index()->initialized(); | 254 bool have_index = backend_->index()->initialized(); |
| 255 int ret_value = net::ERR_FAILED; | 255 int ret_value = net::ERR_FAILED; |
| 256 if (use_optimistic_operations_ && | 256 if (use_optimistic_operations_ && |
| 257 state_ == STATE_UNINITIALIZED && pending_operations_.size() == 0) { | 257 state_ == STATE_UNINITIALIZED && pending_operations_.size() == 0) { |
| 258 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_OPTIMISTIC); | 258 net_log_.AddEvent( |
| 259 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_OPTIMISTIC); |
| 259 | 260 |
| 260 ReturnEntryToCaller(out_entry); | 261 ReturnEntryToCaller(out_entry); |
| 261 pending_operations_.push(SimpleEntryOperation::CreateOperation( | 262 pending_operations_.push(SimpleEntryOperation::CreateOperation( |
| 262 this, have_index, CompletionCallback(), static_cast<Entry**>(NULL))); | 263 this, have_index, CompletionCallback(), static_cast<Entry**>(NULL))); |
| 263 ret_value = net::OK; | 264 ret_value = net::OK; |
| 264 } else { | 265 } else { |
| 265 pending_operations_.push(SimpleEntryOperation::CreateOperation( | 266 pending_operations_.push(SimpleEntryOperation::CreateOperation( |
| 266 this, have_index, callback, out_entry)); | 267 this, have_index, callback, out_entry)); |
| 267 ret_value = net::ERR_IO_PENDING; | 268 ret_value = net::ERR_IO_PENDING; |
| 268 } | 269 } |
| 269 | 270 |
| 270 // We insert the entry in the index before creating the entry files in the | 271 // We insert the entry in the index before creating the entry files in the |
| 271 // SimpleSynchronousEntry, because this way the worst scenario is when we | 272 // SimpleSynchronousEntry, because this way the worst scenario is when we |
| 272 // have the entry in the index but we don't have the created files yet, this | 273 // have the entry in the index but we don't have the created files yet, this |
| 273 // way we never leak files. CreationOperationComplete will remove the entry | 274 // way we never leak files. CreationOperationComplete will remove the entry |
| 274 // from the index if the creation fails. | 275 // from the index if the creation fails. |
| 275 backend_->index()->Insert(entry_hash_); | 276 backend_->index()->Insert(entry_hash_); |
| 276 | 277 |
| 277 RunNextOperationIfNeeded(); | 278 RunNextOperationIfNeeded(); |
| 278 return ret_value; | 279 return ret_value; |
| 279 } | 280 } |
| 280 | 281 |
| 281 int SimpleEntryImpl::DoomEntry(const CompletionCallback& callback) { | 282 int SimpleEntryImpl::DoomEntry(const CompletionCallback& callback) { |
| 282 if (doomed_) | 283 if (doomed_) |
| 283 return net::OK; | 284 return net::OK; |
| 284 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_CALL); | 285 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_DOOM_CALL); |
| 285 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_BEGIN); | 286 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_DOOM_BEGIN); |
| 286 | 287 |
| 287 MarkAsDoomed(); | 288 MarkAsDoomed(); |
| 288 if (backend_.get()) | 289 if (backend_.get()) |
| 289 backend_->OnDoomStart(entry_hash_); | 290 backend_->OnDoomStart(entry_hash_); |
| 290 pending_operations_.push(SimpleEntryOperation::DoomOperation(this, callback)); | 291 pending_operations_.push(SimpleEntryOperation::DoomOperation(this, callback)); |
| 291 RunNextOperationIfNeeded(); | 292 RunNextOperationIfNeeded(); |
| 292 return net::ERR_IO_PENDING; | 293 return net::ERR_IO_PENDING; |
| 293 } | 294 } |
| 294 | 295 |
| 295 void SimpleEntryImpl::SetKey(const std::string& key) { | 296 void SimpleEntryImpl::SetKey(const std::string& key) { |
| 296 key_ = key; | 297 key_ = key; |
| 297 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_SET_KEY, | 298 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_SET_KEY, |
| 298 net::NetLog::StringCallback("key", &key)); | 299 net::NetLog::StringCallback("key", &key)); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void SimpleEntryImpl::Doom() { | 302 void SimpleEntryImpl::Doom() { |
| 302 DoomEntry(CompletionCallback()); | 303 DoomEntry(CompletionCallback()); |
| 303 } | 304 } |
| 304 | 305 |
| 305 void SimpleEntryImpl::Close() { | 306 void SimpleEntryImpl::Close() { |
| 306 DCHECK(io_thread_checker_.CalledOnValidThread()); | 307 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 307 DCHECK_LT(0, open_count_); | 308 DCHECK_LT(0, open_count_); |
| 308 | 309 |
| 309 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_CALL); | 310 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_CALL); |
| 310 | 311 |
| 311 if (--open_count_ > 0) { | 312 if (--open_count_ > 0) { |
| 312 DCHECK(!HasOneRef()); | 313 DCHECK(!HasOneRef()); |
| 313 Release(); // Balanced in ReturnEntryToCaller(). | 314 Release(); // Balanced in ReturnEntryToCaller(). |
| 314 return; | 315 return; |
| 315 } | 316 } |
| 316 | 317 |
| 317 pending_operations_.push(SimpleEntryOperation::CloseOperation(this)); | 318 pending_operations_.push(SimpleEntryOperation::CloseOperation(this)); |
| 318 DCHECK(!HasOneRef()); | 319 DCHECK(!HasOneRef()); |
| 319 Release(); // Balanced in ReturnEntryToCaller(). | 320 Release(); // Balanced in ReturnEntryToCaller(). |
| (...skipping 22 matching lines...) Expand all Loading... |
| 342 } | 343 } |
| 343 | 344 |
| 344 int SimpleEntryImpl::ReadData(int stream_index, | 345 int SimpleEntryImpl::ReadData(int stream_index, |
| 345 int offset, | 346 int offset, |
| 346 net::IOBuffer* buf, | 347 net::IOBuffer* buf, |
| 347 int buf_len, | 348 int buf_len, |
| 348 const CompletionCallback& callback) { | 349 const CompletionCallback& callback) { |
| 349 DCHECK(io_thread_checker_.CalledOnValidThread()); | 350 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 350 | 351 |
| 351 if (net_log_.IsCapturing()) { | 352 if (net_log_.IsCapturing()) { |
| 352 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_CALL, | 353 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_CALL, |
| 353 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, | 354 CreateNetLogReadWriteDataCallback(stream_index, offset, |
| 354 false)); | 355 buf_len, false)); |
| 355 } | 356 } |
| 356 | 357 |
| 357 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || | 358 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || |
| 358 buf_len < 0) { | 359 buf_len < 0) { |
| 359 if (net_log_.IsCapturing()) { | 360 if (net_log_.IsCapturing()) { |
| 360 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, | 361 net_log_.AddEvent( |
| 362 net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END, |
| 361 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); | 363 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); |
| 362 } | 364 } |
| 363 | 365 |
| 364 RecordReadResult(cache_type_, READ_RESULT_INVALID_ARGUMENT); | 366 RecordReadResult(cache_type_, READ_RESULT_INVALID_ARGUMENT); |
| 365 return net::ERR_INVALID_ARGUMENT; | 367 return net::ERR_INVALID_ARGUMENT; |
| 366 } | 368 } |
| 367 if (pending_operations_.empty() && (offset >= GetDataSize(stream_index) || | 369 if (pending_operations_.empty() && (offset >= GetDataSize(stream_index) || |
| 368 offset < 0 || !buf_len)) { | 370 offset < 0 || !buf_len)) { |
| 369 if (net_log_.IsCapturing()) { | 371 if (net_log_.IsCapturing()) { |
| 370 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, | 372 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END, |
| 371 CreateNetLogReadWriteCompleteCallback(0)); | 373 CreateNetLogReadWriteCompleteCallback(0)); |
| 372 } | 374 } |
| 373 | 375 |
| 374 RecordReadResult(cache_type_, READ_RESULT_NONBLOCK_EMPTY_RETURN); | 376 RecordReadResult(cache_type_, READ_RESULT_NONBLOCK_EMPTY_RETURN); |
| 375 return 0; | 377 return 0; |
| 376 } | 378 } |
| 377 | 379 |
| 378 // TODO(clamy): return immediatly when reading from stream 0. | 380 // TODO(clamy): return immediatly when reading from stream 0. |
| 379 | 381 |
| 380 // TODO(felipeg): Optimization: Add support for truly parallel read | 382 // TODO(felipeg): Optimization: Add support for truly parallel read |
| 381 // operations. | 383 // operations. |
| 382 bool alone_in_queue = | 384 bool alone_in_queue = |
| 383 pending_operations_.size() == 0 && state_ == STATE_READY; | 385 pending_operations_.size() == 0 && state_ == STATE_READY; |
| 384 pending_operations_.push(SimpleEntryOperation::ReadOperation( | 386 pending_operations_.push(SimpleEntryOperation::ReadOperation( |
| 385 this, stream_index, offset, buf_len, buf, callback, alone_in_queue)); | 387 this, stream_index, offset, buf_len, buf, callback, alone_in_queue)); |
| 386 RunNextOperationIfNeeded(); | 388 RunNextOperationIfNeeded(); |
| 387 return net::ERR_IO_PENDING; | 389 return net::ERR_IO_PENDING; |
| 388 } | 390 } |
| 389 | 391 |
| 390 int SimpleEntryImpl::WriteData(int stream_index, | 392 int SimpleEntryImpl::WriteData(int stream_index, |
| 391 int offset, | 393 int offset, |
| 392 net::IOBuffer* buf, | 394 net::IOBuffer* buf, |
| 393 int buf_len, | 395 int buf_len, |
| 394 const CompletionCallback& callback, | 396 const CompletionCallback& callback, |
| 395 bool truncate) { | 397 bool truncate) { |
| 396 DCHECK(io_thread_checker_.CalledOnValidThread()); | 398 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 397 | 399 |
| 398 if (net_log_.IsCapturing()) { | 400 if (net_log_.IsCapturing()) { |
| 399 net_log_.AddEvent( | 401 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_CALL, |
| 400 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_CALL, | 402 CreateNetLogReadWriteDataCallback(stream_index, offset, |
| 401 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, | 403 buf_len, truncate)); |
| 402 truncate)); | |
| 403 } | 404 } |
| 404 | 405 |
| 405 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || | 406 if (stream_index < 0 || stream_index >= kSimpleEntryStreamCount || |
| 406 offset < 0 || buf_len < 0) { | 407 offset < 0 || buf_len < 0) { |
| 407 if (net_log_.IsCapturing()) { | 408 if (net_log_.IsCapturing()) { |
| 408 net_log_.AddEvent( | 409 net_log_.AddEvent( |
| 409 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, | 410 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END, |
| 410 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); | 411 CreateNetLogReadWriteCompleteCallback(net::ERR_INVALID_ARGUMENT)); |
| 411 } | 412 } |
| 412 RecordWriteResult(cache_type_, WRITE_RESULT_INVALID_ARGUMENT); | 413 RecordWriteResult(cache_type_, WRITE_RESULT_INVALID_ARGUMENT); |
| 413 return net::ERR_INVALID_ARGUMENT; | 414 return net::ERR_INVALID_ARGUMENT; |
| 414 } | 415 } |
| 415 if (backend_.get() && offset + buf_len > backend_->GetMaxFileSize()) { | 416 if (backend_.get() && offset + buf_len > backend_->GetMaxFileSize()) { |
| 416 if (net_log_.IsCapturing()) { | 417 if (net_log_.IsCapturing()) { |
| 417 net_log_.AddEvent( | 418 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END, |
| 418 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, | 419 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); |
| 419 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); | |
| 420 } | 420 } |
| 421 RecordWriteResult(cache_type_, WRITE_RESULT_OVER_MAX_SIZE); | 421 RecordWriteResult(cache_type_, WRITE_RESULT_OVER_MAX_SIZE); |
| 422 return net::ERR_FAILED; | 422 return net::ERR_FAILED; |
| 423 } | 423 } |
| 424 ScopedOperationRunner operation_runner(this); | 424 ScopedOperationRunner operation_runner(this); |
| 425 | 425 |
| 426 // Stream 0 data is kept in memory, so can be written immediatly if there are | 426 // Stream 0 data is kept in memory, so can be written immediatly if there are |
| 427 // no IO operations pending. | 427 // no IO operations pending. |
| 428 if (stream_index == 0 && state_ == STATE_READY && | 428 if (stream_index == 0 && state_ == STATE_READY && |
| 429 pending_operations_.size() == 0) | 429 pending_operations_.size() == 0) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 450 // here to avoid paying the price of the RefCountedThreadSafe atomic | 450 // here to avoid paying the price of the RefCountedThreadSafe atomic |
| 451 // operations. | 451 // operations. |
| 452 if (buf) { | 452 if (buf) { |
| 453 op_buf = new IOBuffer(buf_len); | 453 op_buf = new IOBuffer(buf_len); |
| 454 memcpy(op_buf->data(), buf->data(), buf_len); | 454 memcpy(op_buf->data(), buf->data(), buf_len); |
| 455 } | 455 } |
| 456 op_callback = CompletionCallback(); | 456 op_callback = CompletionCallback(); |
| 457 ret_value = buf_len; | 457 ret_value = buf_len; |
| 458 if (net_log_.IsCapturing()) { | 458 if (net_log_.IsCapturing()) { |
| 459 net_log_.AddEvent( | 459 net_log_.AddEvent( |
| 460 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_OPTIMISTIC, | 460 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_OPTIMISTIC, |
| 461 CreateNetLogReadWriteCompleteCallback(buf_len)); | 461 CreateNetLogReadWriteCompleteCallback(buf_len)); |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 pending_operations_.push(SimpleEntryOperation::WriteOperation(this, | 465 pending_operations_.push(SimpleEntryOperation::WriteOperation(this, |
| 466 stream_index, | 466 stream_index, |
| 467 offset, | 467 offset, |
| 468 buf_len, | 468 buf_len, |
| 469 op_buf.get(), | 469 op_buf.get(), |
| 470 truncate, | 470 truncate, |
| 471 optimistic, | 471 optimistic, |
| 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()) { | 482 if (net_log_.IsCapturing()) { |
| 483 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_CALL, | 483 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_CALL, |
| 484 CreateNetLogSparseOperationCallback(offset, buf_len)); | 484 CreateNetLogSparseOperationCallback(offset, buf_len)); |
| 485 } | 485 } |
| 486 | 486 |
| 487 ScopedOperationRunner operation_runner(this); | 487 ScopedOperationRunner operation_runner(this); |
| 488 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation( | 488 pending_operations_.push(SimpleEntryOperation::ReadSparseOperation( |
| 489 this, offset, buf_len, buf, callback)); | 489 this, offset, buf_len, buf, callback)); |
| 490 return net::ERR_IO_PENDING; | 490 return net::ERR_IO_PENDING; |
| 491 } | 491 } |
| 492 | 492 |
| 493 int SimpleEntryImpl::WriteSparseData(int64_t offset, | 493 int SimpleEntryImpl::WriteSparseData(int64_t offset, |
| 494 net::IOBuffer* buf, | 494 net::IOBuffer* buf, |
| 495 int buf_len, | 495 int buf_len, |
| 496 const CompletionCallback& callback) { | 496 const CompletionCallback& callback) { |
| 497 DCHECK(io_thread_checker_.CalledOnValidThread()); | 497 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 498 | 498 |
| 499 if (net_log_.IsCapturing()) { | 499 if (net_log_.IsCapturing()) { |
| 500 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_CALL, | 500 net_log_.AddEvent( |
| 501 CreateNetLogSparseOperationCallback(offset, buf_len)); | 501 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_SPARSE_CALL, |
| 502 CreateNetLogSparseOperationCallback(offset, buf_len)); |
| 502 } | 503 } |
| 503 | 504 |
| 504 ScopedOperationRunner operation_runner(this); | 505 ScopedOperationRunner operation_runner(this); |
| 505 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation( | 506 pending_operations_.push(SimpleEntryOperation::WriteSparseOperation( |
| 506 this, offset, buf_len, buf, callback)); | 507 this, offset, buf_len, buf, callback)); |
| 507 return net::ERR_IO_PENDING; | 508 return net::ERR_IO_PENDING; |
| 508 } | 509 } |
| 509 | 510 |
| 510 int SimpleEntryImpl::GetAvailableRange(int64_t offset, | 511 int SimpleEntryImpl::GetAvailableRange(int64_t offset, |
| 511 int len, | 512 int len, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 538 // entry, so there's no need to coordinate which object is performing sparse | 539 // entry, so there's no need to coordinate which object is performing sparse |
| 539 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. | 540 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. |
| 540 return net::OK; | 541 return net::OK; |
| 541 } | 542 } |
| 542 | 543 |
| 543 SimpleEntryImpl::~SimpleEntryImpl() { | 544 SimpleEntryImpl::~SimpleEntryImpl() { |
| 544 DCHECK(io_thread_checker_.CalledOnValidThread()); | 545 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 545 DCHECK_EQ(0U, pending_operations_.size()); | 546 DCHECK_EQ(0U, pending_operations_.size()); |
| 546 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); | 547 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); |
| 547 DCHECK(!synchronous_entry_); | 548 DCHECK(!synchronous_entry_); |
| 548 net_log_.EndEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY); | 549 net_log_.EndEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY); |
| 549 } | 550 } |
| 550 | 551 |
| 551 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback, | 552 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback, |
| 552 int result) { | 553 int result) { |
| 553 if (callback.is_null()) | 554 if (callback.is_null()) |
| 554 return; | 555 return; |
| 555 // Note that the callback is posted rather than directly invoked to avoid | 556 // Note that the callback is posted rather than directly invoked to avoid |
| 556 // reentrancy issues. | 557 // reentrancy issues. |
| 557 base::ThreadTaskRunnerHandle::Get()->PostTask( | 558 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 558 FROM_HERE, | 559 FROM_HERE, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 executing_operation_->ReleaseReferences(); | 665 executing_operation_->ReleaseReferences(); |
| 665 // |this| may have been deleted. | 666 // |this| may have been deleted. |
| 666 } | 667 } |
| 667 } | 668 } |
| 668 | 669 |
| 669 void SimpleEntryImpl::OpenEntryInternal(bool have_index, | 670 void SimpleEntryImpl::OpenEntryInternal(bool have_index, |
| 670 const CompletionCallback& callback, | 671 const CompletionCallback& callback, |
| 671 Entry** out_entry) { | 672 Entry** out_entry) { |
| 672 ScopedOperationRunner operation_runner(this); | 673 ScopedOperationRunner operation_runner(this); |
| 673 | 674 |
| 674 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_BEGIN); | 675 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_BEGIN); |
| 675 | 676 |
| 676 if (state_ == STATE_READY) { | 677 if (state_ == STATE_READY) { |
| 677 ReturnEntryToCaller(out_entry); | 678 ReturnEntryToCaller(out_entry); |
| 678 PostClientCallback(callback, net::OK); | 679 PostClientCallback(callback, net::OK); |
| 679 net_log_.AddEvent( | 680 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END, |
| 680 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, | 681 CreateNetLogSimpleEntryCreationCallback(this, net::OK)); |
| 681 CreateNetLogSimpleEntryCreationCallback(this, net::OK)); | |
| 682 return; | 682 return; |
| 683 } | 683 } |
| 684 if (state_ == STATE_FAILURE) { | 684 if (state_ == STATE_FAILURE) { |
| 685 PostClientCallback(callback, net::ERR_FAILED); | 685 PostClientCallback(callback, net::ERR_FAILED); |
| 686 net_log_.AddEvent( | 686 net_log_.AddEvent( |
| 687 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END, | 687 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END, |
| 688 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); | 688 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); |
| 689 return; | 689 return; |
| 690 } | 690 } |
| 691 | 691 |
| 692 DCHECK_EQ(STATE_UNINITIALIZED, state_); | 692 DCHECK_EQ(STATE_UNINITIALIZED, state_); |
| 693 DCHECK(!synchronous_entry_); | 693 DCHECK(!synchronous_entry_); |
| 694 state_ = STATE_IO_PENDING; | 694 state_ = STATE_IO_PENDING; |
| 695 const base::TimeTicks start_time = base::TimeTicks::Now(); | 695 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 696 std::unique_ptr<SimpleEntryCreationResults> results( | 696 std::unique_ptr<SimpleEntryCreationResults> results( |
| 697 new SimpleEntryCreationResults(SimpleEntryStat( | 697 new SimpleEntryCreationResults(SimpleEntryStat( |
| 698 last_used_, last_modified_, data_size_, sparse_data_size_))); | 698 last_used_, last_modified_, data_size_, sparse_data_size_))); |
| 699 Closure task = | 699 Closure task = |
| 700 base::Bind(&SimpleSynchronousEntry::OpenEntry, cache_type_, path_, key_, | 700 base::Bind(&SimpleSynchronousEntry::OpenEntry, cache_type_, path_, key_, |
| 701 entry_hash_, have_index, results.get()); | 701 entry_hash_, have_index, results.get()); |
| 702 Closure reply = | 702 Closure reply = |
| 703 base::Bind(&SimpleEntryImpl::CreationOperationComplete, this, callback, | 703 base::Bind(&SimpleEntryImpl::CreationOperationComplete, this, callback, |
| 704 start_time, base::Passed(&results), out_entry, | 704 start_time, base::Passed(&results), out_entry, |
| 705 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_OPEN_END); | 705 net::NetLogEventType::SIMPLE_CACHE_ENTRY_OPEN_END); |
| 706 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); | 706 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); |
| 707 } | 707 } |
| 708 | 708 |
| 709 void SimpleEntryImpl::CreateEntryInternal(bool have_index, | 709 void SimpleEntryImpl::CreateEntryInternal(bool have_index, |
| 710 const CompletionCallback& callback, | 710 const CompletionCallback& callback, |
| 711 Entry** out_entry) { | 711 Entry** out_entry) { |
| 712 ScopedOperationRunner operation_runner(this); | 712 ScopedOperationRunner operation_runner(this); |
| 713 | 713 |
| 714 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_BEGIN); | 714 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_BEGIN); |
| 715 | 715 |
| 716 if (state_ != STATE_UNINITIALIZED) { | 716 if (state_ != STATE_UNINITIALIZED) { |
| 717 // There is already an active normal entry. | 717 // There is already an active normal entry. |
| 718 net_log_.AddEvent( | 718 net_log_.AddEvent( |
| 719 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_END, | 719 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_END, |
| 720 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); | 720 CreateNetLogSimpleEntryCreationCallback(this, net::ERR_FAILED)); |
| 721 PostClientCallback(callback, net::ERR_FAILED); | 721 PostClientCallback(callback, net::ERR_FAILED); |
| 722 return; | 722 return; |
| 723 } | 723 } |
| 724 DCHECK_EQ(STATE_UNINITIALIZED, state_); | 724 DCHECK_EQ(STATE_UNINITIALIZED, state_); |
| 725 DCHECK(!synchronous_entry_); | 725 DCHECK(!synchronous_entry_); |
| 726 | 726 |
| 727 state_ = STATE_IO_PENDING; | 727 state_ = STATE_IO_PENDING; |
| 728 | 728 |
| 729 // Since we don't know the correct values for |last_used_| and | 729 // Since we don't know the correct values for |last_used_| and |
| 730 // |last_modified_| yet, we make this approximation. | 730 // |last_modified_| yet, we make this approximation. |
| 731 last_used_ = last_modified_ = base::Time::Now(); | 731 last_used_ = last_modified_ = base::Time::Now(); |
| 732 | 732 |
| 733 // If creation succeeds, we should mark all streams to be saved on close. | 733 // If creation succeeds, we should mark all streams to be saved on close. |
| 734 for (int i = 0; i < kSimpleEntryStreamCount; ++i) | 734 for (int i = 0; i < kSimpleEntryStreamCount; ++i) |
| 735 have_written_[i] = true; | 735 have_written_[i] = true; |
| 736 | 736 |
| 737 const base::TimeTicks start_time = base::TimeTicks::Now(); | 737 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 738 std::unique_ptr<SimpleEntryCreationResults> results( | 738 std::unique_ptr<SimpleEntryCreationResults> results( |
| 739 new SimpleEntryCreationResults(SimpleEntryStat( | 739 new SimpleEntryCreationResults(SimpleEntryStat( |
| 740 last_used_, last_modified_, data_size_, sparse_data_size_))); | 740 last_used_, last_modified_, data_size_, sparse_data_size_))); |
| 741 Closure task = base::Bind(&SimpleSynchronousEntry::CreateEntry, | 741 Closure task = base::Bind(&SimpleSynchronousEntry::CreateEntry, |
| 742 cache_type_, | 742 cache_type_, |
| 743 path_, | 743 path_, |
| 744 key_, | 744 key_, |
| 745 entry_hash_, | 745 entry_hash_, |
| 746 have_index, | 746 have_index, |
| 747 results.get()); | 747 results.get()); |
| 748 Closure reply = base::Bind(&SimpleEntryImpl::CreationOperationComplete, | 748 Closure reply = |
| 749 this, | 749 base::Bind(&SimpleEntryImpl::CreationOperationComplete, this, callback, |
| 750 callback, | 750 start_time, base::Passed(&results), out_entry, |
| 751 start_time, | 751 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CREATE_END); |
| 752 base::Passed(&results), | |
| 753 out_entry, | |
| 754 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CREATE_END); | |
| 755 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); | 752 worker_pool_->PostTaskAndReply(FROM_HERE, task, reply); |
| 756 } | 753 } |
| 757 | 754 |
| 758 void SimpleEntryImpl::CloseInternal() { | 755 void SimpleEntryImpl::CloseInternal() { |
| 759 DCHECK(io_thread_checker_.CalledOnValidThread()); | 756 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 760 typedef SimpleSynchronousEntry::CRCRecord CRCRecord; | 757 typedef SimpleSynchronousEntry::CRCRecord CRCRecord; |
| 761 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write( | 758 std::unique_ptr<std::vector<CRCRecord>> crc32s_to_write( |
| 762 new std::vector<CRCRecord>()); | 759 new std::vector<CRCRecord>()); |
| 763 | 760 |
| 764 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_BEGIN); | 761 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_BEGIN); |
| 765 | 762 |
| 766 if (state_ == STATE_READY) { | 763 if (state_ == STATE_READY) { |
| 767 DCHECK(synchronous_entry_); | 764 DCHECK(synchronous_entry_); |
| 768 state_ = STATE_IO_PENDING; | 765 state_ = STATE_IO_PENDING; |
| 769 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { | 766 for (int i = 0; i < kSimpleEntryStreamCount; ++i) { |
| 770 if (have_written_[i]) { | 767 if (have_written_[i]) { |
| 771 if (GetDataSize(i) == crc32s_end_offset_[i]) { | 768 if (GetDataSize(i) == crc32s_end_offset_[i]) { |
| 772 int32_t 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]; |
| 773 crc32s_to_write->push_back(CRCRecord(i, true, crc)); | 770 crc32s_to_write->push_back(CRCRecord(i, true, crc)); |
| 774 } else { | 771 } else { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 804 | 801 |
| 805 void SimpleEntryImpl::ReadDataInternal(int stream_index, | 802 void SimpleEntryImpl::ReadDataInternal(int stream_index, |
| 806 int offset, | 803 int offset, |
| 807 net::IOBuffer* buf, | 804 net::IOBuffer* buf, |
| 808 int buf_len, | 805 int buf_len, |
| 809 const CompletionCallback& callback) { | 806 const CompletionCallback& callback) { |
| 810 DCHECK(io_thread_checker_.CalledOnValidThread()); | 807 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 811 ScopedOperationRunner operation_runner(this); | 808 ScopedOperationRunner operation_runner(this); |
| 812 | 809 |
| 813 if (net_log_.IsCapturing()) { | 810 if (net_log_.IsCapturing()) { |
| 814 net_log_.AddEvent( | 811 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_BEGIN, |
| 815 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_BEGIN, | 812 CreateNetLogReadWriteDataCallback(stream_index, offset, |
| 816 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, | 813 buf_len, false)); |
| 817 false)); | |
| 818 } | 814 } |
| 819 | 815 |
| 820 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { | 816 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { |
| 821 if (!callback.is_null()) { | 817 if (!callback.is_null()) { |
| 822 RecordReadResult(cache_type_, READ_RESULT_BAD_STATE); | 818 RecordReadResult(cache_type_, READ_RESULT_BAD_STATE); |
| 823 // Note that the API states that client-provided callbacks for entry-level | 819 // Note that the API states that client-provided callbacks for entry-level |
| 824 // (i.e. non-backend) operations (e.g. read, write) are invoked even if | 820 // (i.e. non-backend) operations (e.g. read, write) are invoked even if |
| 825 // the backend was already destroyed. | 821 // the backend was already destroyed. |
| 826 base::ThreadTaskRunnerHandle::Get()->PostTask( | 822 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 827 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); | 823 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); |
| 828 } | 824 } |
| 829 if (net_log_.IsCapturing()) { | 825 if (net_log_.IsCapturing()) { |
| 830 net_log_.AddEvent( | 826 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END, |
| 831 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, | 827 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); |
| 832 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); | |
| 833 } | 828 } |
| 834 return; | 829 return; |
| 835 } | 830 } |
| 836 DCHECK_EQ(STATE_READY, state_); | 831 DCHECK_EQ(STATE_READY, state_); |
| 837 if (offset >= GetDataSize(stream_index) || offset < 0 || !buf_len) { | 832 if (offset >= GetDataSize(stream_index) || offset < 0 || !buf_len) { |
| 838 RecordReadResult(cache_type_, READ_RESULT_FAST_EMPTY_RETURN); | 833 RecordReadResult(cache_type_, READ_RESULT_FAST_EMPTY_RETURN); |
| 839 // If there is nothing to read, we bail out before setting state_ to | 834 // If there is nothing to read, we bail out before setting state_ to |
| 840 // STATE_IO_PENDING. | 835 // STATE_IO_PENDING. |
| 841 if (!callback.is_null()) | 836 if (!callback.is_null()) |
| 842 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 837 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 void SimpleEntryImpl::WriteDataInternal(int stream_index, | 877 void SimpleEntryImpl::WriteDataInternal(int stream_index, |
| 883 int offset, | 878 int offset, |
| 884 net::IOBuffer* buf, | 879 net::IOBuffer* buf, |
| 885 int buf_len, | 880 int buf_len, |
| 886 const CompletionCallback& callback, | 881 const CompletionCallback& callback, |
| 887 bool truncate) { | 882 bool truncate) { |
| 888 DCHECK(io_thread_checker_.CalledOnValidThread()); | 883 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 889 ScopedOperationRunner operation_runner(this); | 884 ScopedOperationRunner operation_runner(this); |
| 890 | 885 |
| 891 if (net_log_.IsCapturing()) { | 886 if (net_log_.IsCapturing()) { |
| 892 net_log_.AddEvent( | 887 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_BEGIN, |
| 893 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_BEGIN, | 888 CreateNetLogReadWriteDataCallback(stream_index, offset, |
| 894 CreateNetLogReadWriteDataCallback(stream_index, offset, buf_len, | 889 buf_len, truncate)); |
| 895 truncate)); | |
| 896 } | 890 } |
| 897 | 891 |
| 898 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { | 892 if (state_ == STATE_FAILURE || state_ == STATE_UNINITIALIZED) { |
| 899 RecordWriteResult(cache_type_, WRITE_RESULT_BAD_STATE); | 893 RecordWriteResult(cache_type_, WRITE_RESULT_BAD_STATE); |
| 900 if (net_log_.IsCapturing()) { | 894 if (net_log_.IsCapturing()) { |
| 901 net_log_.AddEvent( | 895 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END, |
| 902 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, | 896 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); |
| 903 CreateNetLogReadWriteCompleteCallback(net::ERR_FAILED)); | |
| 904 } | 897 } |
| 905 if (!callback.is_null()) { | 898 if (!callback.is_null()) { |
| 906 base::ThreadTaskRunnerHandle::Get()->PostTask( | 899 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 907 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); | 900 FROM_HERE, base::Bind(callback, net::ERR_FAILED)); |
| 908 } | 901 } |
| 909 // |this| may be destroyed after return here. | 902 // |this| may be destroyed after return here. |
| 910 return; | 903 return; |
| 911 } | 904 } |
| 912 | 905 |
| 913 DCHECK_EQ(STATE_READY, state_); | 906 DCHECK_EQ(STATE_READY, state_); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 void SimpleEntryImpl::ReadSparseDataInternal( | 971 void SimpleEntryImpl::ReadSparseDataInternal( |
| 979 int64_t sparse_offset, | 972 int64_t sparse_offset, |
| 980 net::IOBuffer* buf, | 973 net::IOBuffer* buf, |
| 981 int buf_len, | 974 int buf_len, |
| 982 const CompletionCallback& callback) { | 975 const CompletionCallback& callback) { |
| 983 DCHECK(io_thread_checker_.CalledOnValidThread()); | 976 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 984 ScopedOperationRunner operation_runner(this); | 977 ScopedOperationRunner operation_runner(this); |
| 985 | 978 |
| 986 if (net_log_.IsCapturing()) { | 979 if (net_log_.IsCapturing()) { |
| 987 net_log_.AddEvent( | 980 net_log_.AddEvent( |
| 988 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN, | 981 net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_BEGIN, |
| 989 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); | 982 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); |
| 990 } | 983 } |
| 991 | 984 |
| 992 DCHECK_EQ(STATE_READY, state_); | 985 DCHECK_EQ(STATE_READY, state_); |
| 993 state_ = STATE_IO_PENDING; | 986 state_ = STATE_IO_PENDING; |
| 994 | 987 |
| 995 std::unique_ptr<int> result(new int()); | 988 std::unique_ptr<int> result(new int()); |
| 996 std::unique_ptr<base::Time> last_used(new base::Time()); | 989 std::unique_ptr<base::Time> last_used(new base::Time()); |
| 997 Closure task = base::Bind( | 990 Closure task = base::Bind( |
| 998 &SimpleSynchronousEntry::ReadSparseData, | 991 &SimpleSynchronousEntry::ReadSparseData, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1010 void SimpleEntryImpl::WriteSparseDataInternal( | 1003 void SimpleEntryImpl::WriteSparseDataInternal( |
| 1011 int64_t sparse_offset, | 1004 int64_t sparse_offset, |
| 1012 net::IOBuffer* buf, | 1005 net::IOBuffer* buf, |
| 1013 int buf_len, | 1006 int buf_len, |
| 1014 const CompletionCallback& callback) { | 1007 const CompletionCallback& callback) { |
| 1015 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1008 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1016 ScopedOperationRunner operation_runner(this); | 1009 ScopedOperationRunner operation_runner(this); |
| 1017 | 1010 |
| 1018 if (net_log_.IsCapturing()) { | 1011 if (net_log_.IsCapturing()) { |
| 1019 net_log_.AddEvent( | 1012 net_log_.AddEvent( |
| 1020 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_BEGIN, | 1013 net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_SPARSE_BEGIN, |
| 1021 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); | 1014 CreateNetLogSparseOperationCallback(sparse_offset, buf_len)); |
| 1022 } | 1015 } |
| 1023 | 1016 |
| 1024 DCHECK_EQ(STATE_READY, state_); | 1017 DCHECK_EQ(STATE_READY, state_); |
| 1025 state_ = STATE_IO_PENDING; | 1018 state_ = STATE_IO_PENDING; |
| 1026 | 1019 |
| 1027 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max(); | 1020 uint64_t max_sparse_data_size = std::numeric_limits<int64_t>::max(); |
| 1028 if (backend_.get()) { | 1021 if (backend_.get()) { |
| 1029 uint64_t max_cache_size = backend_->index()->max_size(); | 1022 uint64_t max_cache_size = backend_->index()->max_size(); |
| 1030 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; | 1023 max_sparse_data_size = max_cache_size / kMaxSparseDataSizeDivisor; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 base::Bind( | 1096 base::Bind( |
| 1104 &SimpleEntryImpl::DoomOperationComplete, this, callback, state_)); | 1097 &SimpleEntryImpl::DoomOperationComplete, this, callback, state_)); |
| 1105 state_ = STATE_IO_PENDING; | 1098 state_ = STATE_IO_PENDING; |
| 1106 } | 1099 } |
| 1107 | 1100 |
| 1108 void SimpleEntryImpl::CreationOperationComplete( | 1101 void SimpleEntryImpl::CreationOperationComplete( |
| 1109 const CompletionCallback& completion_callback, | 1102 const CompletionCallback& completion_callback, |
| 1110 const base::TimeTicks& start_time, | 1103 const base::TimeTicks& start_time, |
| 1111 std::unique_ptr<SimpleEntryCreationResults> in_results, | 1104 std::unique_ptr<SimpleEntryCreationResults> in_results, |
| 1112 Entry** out_entry, | 1105 Entry** out_entry, |
| 1113 net::NetLog::EventType end_event_type) { | 1106 net::NetLogEventType end_event_type) { |
| 1114 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1107 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1115 DCHECK_EQ(state_, STATE_IO_PENDING); | 1108 DCHECK_EQ(state_, STATE_IO_PENDING); |
| 1116 DCHECK(in_results); | 1109 DCHECK(in_results); |
| 1117 ScopedOperationRunner operation_runner(this); | 1110 ScopedOperationRunner operation_runner(this); |
| 1118 SIMPLE_CACHE_UMA(BOOLEAN, | 1111 SIMPLE_CACHE_UMA(BOOLEAN, |
| 1119 "EntryCreationResult", cache_type_, | 1112 "EntryCreationResult", cache_type_, |
| 1120 in_results->result == net::OK); | 1113 in_results->result == net::OK); |
| 1121 if (in_results->result != net::OK) { | 1114 if (in_results->result != net::OK) { |
| 1122 if (in_results->result != net::ERR_FILE_EXISTS) | 1115 if (in_results->result != net::ERR_FILE_EXISTS) |
| 1123 MarkAsDoomed(); | 1116 MarkAsDoomed(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 offset == 0 ? crc32(0, Z_NULL, 0) : crc32s_[stream_index]; | 1200 offset == 0 ? crc32(0, Z_NULL, 0) : crc32s_[stream_index]; |
| 1208 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result); | 1201 crc32s_[stream_index] = crc32_combine(current_crc, *read_crc32, *result); |
| 1209 crc32s_end_offset_[stream_index] += *result; | 1202 crc32s_end_offset_[stream_index] += *result; |
| 1210 if (!have_written_[stream_index] && | 1203 if (!have_written_[stream_index] && |
| 1211 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) { | 1204 GetDataSize(stream_index) == crc32s_end_offset_[stream_index]) { |
| 1212 // We have just read a file from start to finish, and so we have | 1205 // We have just read a file from start to finish, and so we have |
| 1213 // computed a crc of the entire file. We can check it now. If a cache | 1206 // computed a crc of the entire file. We can check it now. If a cache |
| 1214 // entry has a single reader, the normal pattern is to read from start | 1207 // entry has a single reader, the normal pattern is to read from start |
| 1215 // to finish. | 1208 // to finish. |
| 1216 | 1209 |
| 1217 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN); | 1210 net_log_.AddEvent( |
| 1211 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CHECKSUM_BEGIN); |
| 1218 | 1212 |
| 1219 std::unique_ptr<int> new_result(new int()); | 1213 std::unique_ptr<int> new_result(new int()); |
| 1220 Closure task = base::Bind(&SimpleSynchronousEntry::CheckEOFRecord, | 1214 Closure task = base::Bind(&SimpleSynchronousEntry::CheckEOFRecord, |
| 1221 base::Unretained(synchronous_entry_), | 1215 base::Unretained(synchronous_entry_), |
| 1222 stream_index, | 1216 stream_index, |
| 1223 *entry_stat, | 1217 *entry_stat, |
| 1224 crc32s_[stream_index], | 1218 crc32s_[stream_index], |
| 1225 new_result.get()); | 1219 new_result.get()); |
| 1226 Closure reply = base::Bind(&SimpleEntryImpl::ChecksumOperationComplete, | 1220 Closure reply = base::Bind(&SimpleEntryImpl::ChecksumOperationComplete, |
| 1227 this, *result, stream_index, | 1221 this, *result, stream_index, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1240 if (*result < 0) { | 1234 if (*result < 0) { |
| 1241 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE); | 1235 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE); |
| 1242 } else { | 1236 } else { |
| 1243 RecordReadResult(cache_type_, READ_RESULT_SUCCESS); | 1237 RecordReadResult(cache_type_, READ_RESULT_SUCCESS); |
| 1244 if (crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_TO_END && | 1238 if (crc_check_state_[stream_index] == CRC_CHECK_NEVER_READ_TO_END && |
| 1245 offset + *result == GetDataSize(stream_index)) { | 1239 offset + *result == GetDataSize(stream_index)) { |
| 1246 crc_check_state_[stream_index] = CRC_CHECK_NOT_DONE; | 1240 crc_check_state_[stream_index] = CRC_CHECK_NOT_DONE; |
| 1247 } | 1241 } |
| 1248 } | 1242 } |
| 1249 if (net_log_.IsCapturing()) { | 1243 if (net_log_.IsCapturing()) { |
| 1250 net_log_.AddEvent( | 1244 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END, |
| 1251 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, | 1245 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1252 CreateNetLogReadWriteCompleteCallback(*result)); | |
| 1253 } | 1246 } |
| 1254 | 1247 |
| 1255 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1248 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1256 } | 1249 } |
| 1257 | 1250 |
| 1258 void SimpleEntryImpl::WriteOperationComplete( | 1251 void SimpleEntryImpl::WriteOperationComplete( |
| 1259 int stream_index, | 1252 int stream_index, |
| 1260 const CompletionCallback& completion_callback, | 1253 const CompletionCallback& completion_callback, |
| 1261 std::unique_ptr<SimpleEntryStat> entry_stat, | 1254 std::unique_ptr<SimpleEntryStat> entry_stat, |
| 1262 std::unique_ptr<int> result) { | 1255 std::unique_ptr<int> result) { |
| 1263 if (*result >= 0) | 1256 if (*result >= 0) |
| 1264 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); | 1257 RecordWriteResult(cache_type_, WRITE_RESULT_SUCCESS); |
| 1265 else | 1258 else |
| 1266 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); | 1259 RecordWriteResult(cache_type_, WRITE_RESULT_SYNC_WRITE_FAILURE); |
| 1267 if (net_log_.IsCapturing()) { | 1260 if (net_log_.IsCapturing()) { |
| 1268 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_END, | 1261 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_END, |
| 1269 CreateNetLogReadWriteCompleteCallback(*result)); | 1262 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1270 } | 1263 } |
| 1271 | 1264 |
| 1272 if (*result < 0) { | 1265 if (*result < 0) { |
| 1273 crc32s_end_offset_[stream_index] = 0; | 1266 crc32s_end_offset_[stream_index] = 0; |
| 1274 } | 1267 } |
| 1275 | 1268 |
| 1276 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1269 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1277 } | 1270 } |
| 1278 | 1271 |
| 1279 void SimpleEntryImpl::ReadSparseOperationComplete( | 1272 void SimpleEntryImpl::ReadSparseOperationComplete( |
| 1280 const CompletionCallback& completion_callback, | 1273 const CompletionCallback& completion_callback, |
| 1281 std::unique_ptr<base::Time> last_used, | 1274 std::unique_ptr<base::Time> last_used, |
| 1282 std::unique_ptr<int> result) { | 1275 std::unique_ptr<int> result) { |
| 1283 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1276 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1284 DCHECK(synchronous_entry_); | 1277 DCHECK(synchronous_entry_); |
| 1285 DCHECK(result); | 1278 DCHECK(result); |
| 1286 | 1279 |
| 1287 if (net_log_.IsCapturing()) { | 1280 if (net_log_.IsCapturing()) { |
| 1288 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_SPARSE_END, | 1281 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_SPARSE_END, |
| 1289 CreateNetLogReadWriteCompleteCallback(*result)); | 1282 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1290 } | 1283 } |
| 1291 | 1284 |
| 1292 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_, | 1285 SimpleEntryStat entry_stat(*last_used, last_modified_, data_size_, |
| 1293 sparse_data_size_); | 1286 sparse_data_size_); |
| 1294 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); | 1287 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); |
| 1295 } | 1288 } |
| 1296 | 1289 |
| 1297 void SimpleEntryImpl::WriteSparseOperationComplete( | 1290 void SimpleEntryImpl::WriteSparseOperationComplete( |
| 1298 const CompletionCallback& completion_callback, | 1291 const CompletionCallback& completion_callback, |
| 1299 std::unique_ptr<SimpleEntryStat> entry_stat, | 1292 std::unique_ptr<SimpleEntryStat> entry_stat, |
| 1300 std::unique_ptr<int> result) { | 1293 std::unique_ptr<int> result) { |
| 1301 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1294 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1302 DCHECK(synchronous_entry_); | 1295 DCHECK(synchronous_entry_); |
| 1303 DCHECK(result); | 1296 DCHECK(result); |
| 1304 | 1297 |
| 1305 if (net_log_.IsCapturing()) { | 1298 if (net_log_.IsCapturing()) { |
| 1306 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_WRITE_SPARSE_END, | 1299 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_WRITE_SPARSE_END, |
| 1307 CreateNetLogReadWriteCompleteCallback(*result)); | 1300 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1308 } | 1301 } |
| 1309 | 1302 |
| 1310 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); | 1303 EntryOperationComplete(completion_callback, *entry_stat, std::move(result)); |
| 1311 } | 1304 } |
| 1312 | 1305 |
| 1313 void SimpleEntryImpl::GetAvailableRangeOperationComplete( | 1306 void SimpleEntryImpl::GetAvailableRangeOperationComplete( |
| 1314 const CompletionCallback& completion_callback, | 1307 const CompletionCallback& completion_callback, |
| 1315 std::unique_ptr<int> result) { | 1308 std::unique_ptr<int> result) { |
| 1316 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1309 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1317 DCHECK(synchronous_entry_); | 1310 DCHECK(synchronous_entry_); |
| 1318 DCHECK(result); | 1311 DCHECK(result); |
| 1319 | 1312 |
| 1320 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, | 1313 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, |
| 1321 sparse_data_size_); | 1314 sparse_data_size_); |
| 1322 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); | 1315 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); |
| 1323 } | 1316 } |
| 1324 | 1317 |
| 1325 void SimpleEntryImpl::DoomOperationComplete( | 1318 void SimpleEntryImpl::DoomOperationComplete( |
| 1326 const CompletionCallback& callback, | 1319 const CompletionCallback& callback, |
| 1327 State state_to_restore, | 1320 State state_to_restore, |
| 1328 int result) { | 1321 int result) { |
| 1329 state_ = state_to_restore; | 1322 state_ = state_to_restore; |
| 1330 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_DOOM_END); | 1323 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_DOOM_END); |
| 1331 PostClientCallback(callback, result); | 1324 PostClientCallback(callback, result); |
| 1332 RunNextOperationIfNeeded(); | 1325 RunNextOperationIfNeeded(); |
| 1333 if (backend_) | 1326 if (backend_) |
| 1334 backend_->OnDoomComplete(entry_hash_); | 1327 backend_->OnDoomComplete(entry_hash_); |
| 1335 } | 1328 } |
| 1336 | 1329 |
| 1337 void SimpleEntryImpl::ChecksumOperationComplete( | 1330 void SimpleEntryImpl::ChecksumOperationComplete( |
| 1338 int orig_result, | 1331 int orig_result, |
| 1339 int stream_index, | 1332 int stream_index, |
| 1340 const CompletionCallback& completion_callback, | 1333 const CompletionCallback& completion_callback, |
| 1341 std::unique_ptr<int> result) { | 1334 std::unique_ptr<int> result) { |
| 1342 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1335 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1343 DCHECK(synchronous_entry_); | 1336 DCHECK(synchronous_entry_); |
| 1344 DCHECK_EQ(STATE_IO_PENDING, state_); | 1337 DCHECK_EQ(STATE_IO_PENDING, state_); |
| 1345 DCHECK(result); | 1338 DCHECK(result); |
| 1346 | 1339 |
| 1347 if (net_log_.IsCapturing()) { | 1340 if (net_log_.IsCapturing()) { |
| 1348 net_log_.AddEventWithNetErrorCode( | 1341 net_log_.AddEventWithNetErrorCode( |
| 1349 net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CHECKSUM_END, | 1342 net::NetLogEventType::SIMPLE_CACHE_ENTRY_CHECKSUM_END, *result); |
| 1350 *result); | |
| 1351 } | 1343 } |
| 1352 | 1344 |
| 1353 if (*result == net::OK) { | 1345 if (*result == net::OK) { |
| 1354 *result = orig_result; | 1346 *result = orig_result; |
| 1355 if (orig_result >= 0) | 1347 if (orig_result >= 0) |
| 1356 RecordReadResult(cache_type_, READ_RESULT_SUCCESS); | 1348 RecordReadResult(cache_type_, READ_RESULT_SUCCESS); |
| 1357 else | 1349 else |
| 1358 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE); | 1350 RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE); |
| 1359 } else { | 1351 } else { |
| 1360 RecordReadResult(cache_type_, READ_RESULT_SYNC_CHECKSUM_FAILURE); | 1352 RecordReadResult(cache_type_, READ_RESULT_SYNC_CHECKSUM_FAILURE); |
| 1361 } | 1353 } |
| 1362 if (net_log_.IsCapturing()) { | 1354 if (net_log_.IsCapturing()) { |
| 1363 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_READ_END, | 1355 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_READ_END, |
| 1364 CreateNetLogReadWriteCompleteCallback(*result)); | 1356 CreateNetLogReadWriteCompleteCallback(*result)); |
| 1365 } | 1357 } |
| 1366 | 1358 |
| 1367 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, | 1359 SimpleEntryStat entry_stat(last_used_, last_modified_, data_size_, |
| 1368 sparse_data_size_); | 1360 sparse_data_size_); |
| 1369 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); | 1361 EntryOperationComplete(completion_callback, entry_stat, std::move(result)); |
| 1370 } | 1362 } |
| 1371 | 1363 |
| 1372 void SimpleEntryImpl::CloseOperationComplete() { | 1364 void SimpleEntryImpl::CloseOperationComplete() { |
| 1373 DCHECK(!synchronous_entry_); | 1365 DCHECK(!synchronous_entry_); |
| 1374 DCHECK_EQ(0, open_count_); | 1366 DCHECK_EQ(0, open_count_); |
| 1375 DCHECK(STATE_IO_PENDING == state_ || STATE_FAILURE == state_ || | 1367 DCHECK(STATE_IO_PENDING == state_ || STATE_FAILURE == state_ || |
| 1376 STATE_UNINITIALIZED == state_); | 1368 STATE_UNINITIALIZED == state_); |
| 1377 net_log_.AddEvent(net::NetLog::TYPE_SIMPLE_CACHE_ENTRY_CLOSE_END); | 1369 net_log_.AddEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY_CLOSE_END); |
| 1378 AdjustOpenEntryCountBy(cache_type_, -1); | 1370 AdjustOpenEntryCountBy(cache_type_, -1); |
| 1379 MakeUninitialized(); | 1371 MakeUninitialized(); |
| 1380 RunNextOperationIfNeeded(); | 1372 RunNextOperationIfNeeded(); |
| 1381 } | 1373 } |
| 1382 | 1374 |
| 1383 void SimpleEntryImpl::UpdateDataFromEntryStat( | 1375 void SimpleEntryImpl::UpdateDataFromEntryStat( |
| 1384 const SimpleEntryStat& entry_stat) { | 1376 const SimpleEntryStat& entry_stat) { |
| 1385 DCHECK(io_thread_checker_.CalledOnValidThread()); | 1377 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 1386 DCHECK(synchronous_entry_); | 1378 DCHECK(synchronous_entry_); |
| 1387 DCHECK_EQ(STATE_READY, state_); | 1379 DCHECK_EQ(STATE_READY, state_); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 } | 1543 } |
| 1552 crc32s_end_offset_[stream_index] = offset + length; | 1544 crc32s_end_offset_[stream_index] = offset + length; |
| 1553 } else if (offset < crc32s_end_offset_[stream_index]) { | 1545 } else if (offset < crc32s_end_offset_[stream_index]) { |
| 1554 // If a range for which the crc32 was already computed is rewritten, the | 1546 // If a range for which the crc32 was already computed is rewritten, the |
| 1555 // computation of the crc32 need to start from 0 again. | 1547 // computation of the crc32 need to start from 0 again. |
| 1556 crc32s_end_offset_[stream_index] = 0; | 1548 crc32s_end_offset_[stream_index] = 0; |
| 1557 } | 1549 } |
| 1558 } | 1550 } |
| 1559 | 1551 |
| 1560 } // namespace disk_cache | 1552 } // namespace disk_cache |
| OLD | NEW |