OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/blockfile/entry_impl_v3.h" | 5 #include "net/disk_cache/blockfile/entry_impl_v3.h" |
6 | 6 |
7 #include "base/hash.h" | 7 #include "base/hash.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 read_only_(read_only), | 251 read_only_(read_only), |
252 dirty_(true), | 252 dirty_(true), |
253 modified_(false) { | 253 modified_(false) { |
254 for (int i = 0; i < kNumStreams; i++) { | 254 for (int i = 0; i < kNumStreams; i++) { |
255 unreported_size_[i] = 0; | 255 unreported_size_[i] = 0; |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 #if defined(V3_NOT_JUST_YET_READY) | 259 #if defined(V3_NOT_JUST_YET_READY) |
260 | 260 |
261 bool EntryImplV3::CreateEntry(Addr node_address, const std::string& key, | 261 bool EntryImplV3::CreateEntry(Addr node_address, |
| 262 const std::string& key, |
262 uint32 hash) { | 263 uint32 hash) { |
263 Trace("Create entry In"); | 264 Trace("Create entry In"); |
264 EntryStore* entry_store = entry_.Data(); | 265 EntryStore* entry_store = entry_.Data(); |
265 RankingsNode* node = node_.Data(); | 266 RankingsNode* node = node_.Data(); |
266 memset(entry_store, 0, sizeof(EntryStore) * entry_.address().num_blocks()); | 267 memset(entry_store, 0, sizeof(EntryStore) * entry_.address().num_blocks()); |
267 memset(node, 0, sizeof(RankingsNode)); | 268 memset(node, 0, sizeof(RankingsNode)); |
268 if (!node_.LazyInit(backend_->File(node_address), node_address)) | 269 if (!node_.LazyInit(backend_->File(node_address), node_address)) |
269 return false; | 270 return false; |
270 | 271 |
271 entry_store->rankings_node = node_address.value(); | 272 entry_store->rankings_node = node_address.value(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 435 } |
435 | 436 |
436 void EntryImplV3::SetTimes(base::Time last_used, base::Time last_modified) { | 437 void EntryImplV3::SetTimes(base::Time last_used, base::Time last_modified) { |
437 node_.Data()->last_used = last_used.ToInternalValue(); | 438 node_.Data()->last_used = last_used.ToInternalValue(); |
438 node_.Data()->last_modified = last_modified.ToInternalValue(); | 439 node_.Data()->last_modified = last_modified.ToInternalValue(); |
439 node_.set_modified(); | 440 node_.set_modified(); |
440 } | 441 } |
441 | 442 |
442 void EntryImplV3::BeginLogging(net::NetLog* net_log, bool created) { | 443 void EntryImplV3::BeginLogging(net::NetLog* net_log, bool created) { |
443 DCHECK(!net_log_.net_log()); | 444 DCHECK(!net_log_.net_log()); |
444 net_log_ = net::BoundNetLog::Make( | 445 net_log_ = |
445 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); | 446 net::BoundNetLog::Make(net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); |
446 net_log_.BeginEvent( | 447 net_log_.BeginEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, |
447 net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, | 448 CreateNetLogEntryCreationCallback(this, created)); |
448 CreateNetLogEntryCreationCallback(this, created)); | |
449 } | 449 } |
450 | 450 |
451 const net::BoundNetLog& EntryImplV3::net_log() const { | 451 const net::BoundNetLog& EntryImplV3::net_log() const { |
452 return net_log_; | 452 return net_log_; |
453 } | 453 } |
454 | 454 |
455 // ------------------------------------------------------------------------ | 455 // ------------------------------------------------------------------------ |
456 | 456 |
457 void EntryImplV3::Doom() { | 457 void EntryImplV3::Doom() { |
458 if (background_queue_) | 458 if (background_queue_) |
(...skipping 24 matching lines...) Expand all Loading... |
483 if (!key_.empty()) | 483 if (!key_.empty()) |
484 return key_; | 484 return key_; |
485 | 485 |
486 Addr address(entry->Data()->long_key); | 486 Addr address(entry->Data()->long_key); |
487 DCHECK(address.is_initialized()); | 487 DCHECK(address.is_initialized()); |
488 size_t offset = 0; | 488 size_t offset = 0; |
489 if (address.is_block_file()) | 489 if (address.is_block_file()) |
490 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize; | 490 offset = address.start_block() * address.BlockSize() + kBlockHeaderSize; |
491 | 491 |
492 COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index); | 492 COMPILE_ASSERT(kNumStreams == kKeyFileIndex, invalid_key_index); |
493 File* key_file = const_cast<EntryImpl*>(this)->GetBackingFile(address, | 493 File* key_file = |
494 kKeyFileIndex); | 494 const_cast<EntryImpl*>(this)->GetBackingFile(address, kKeyFileIndex); |
495 if (!key_file) | 495 if (!key_file) |
496 return std::string(); | 496 return std::string(); |
497 | 497 |
498 ++key_len; // We store a trailing \0 on disk that we read back below. | 498 ++key_len; // We store a trailing \0 on disk that we read back below. |
499 if (!offset && key_file->GetLength() != static_cast<size_t>(key_len)) | 499 if (!offset && key_file->GetLength() != static_cast<size_t>(key_len)) |
500 return std::string(); | 500 return std::string(); |
501 | 501 |
502 if (!key_file->Read(WriteInto(&key_, key_len), key_len, offset)) | 502 if (!key_file->Read(WriteInto(&key_, key_len), key_len, offset)) |
503 key_.clear(); | 503 key_.clear(); |
504 return key_; | 504 return key_; |
(...skipping 10 matching lines...) Expand all Loading... |
515 } | 515 } |
516 | 516 |
517 int32 EntryImplV3::GetDataSize(int index) const { | 517 int32 EntryImplV3::GetDataSize(int index) const { |
518 if (index < 0 || index >= kNumStreams) | 518 if (index < 0 || index >= kNumStreams) |
519 return 0; | 519 return 0; |
520 | 520 |
521 CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_); | 521 CacheEntryBlock* entry = const_cast<CacheEntryBlock*>(&entry_); |
522 return entry->Data()->data_size[index]; | 522 return entry->Data()->data_size[index]; |
523 } | 523 } |
524 | 524 |
525 int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len, | 525 int EntryImplV3::ReadData(int index, |
| 526 int offset, |
| 527 IOBuffer* buf, |
| 528 int buf_len, |
526 const CompletionCallback& callback) { | 529 const CompletionCallback& callback) { |
527 if (callback.is_null()) | 530 if (callback.is_null()) |
528 return ReadDataImpl(index, offset, buf, buf_len, callback); | 531 return ReadDataImpl(index, offset, buf, buf_len, callback); |
529 | 532 |
530 DCHECK(node_.Data()->dirty || read_only_); | 533 DCHECK(node_.Data()->dirty || read_only_); |
531 if (index < 0 || index >= kNumStreams) | 534 if (index < 0 || index >= kNumStreams) |
532 return net::ERR_INVALID_ARGUMENT; | 535 return net::ERR_INVALID_ARGUMENT; |
533 | 536 |
534 int entry_size = entry_.Data()->data_size[index]; | 537 int entry_size = entry_.Data()->data_size[index]; |
535 if (offset >= entry_size || offset < 0 || !buf_len) | 538 if (offset >= entry_size || offset < 0 || !buf_len) |
536 return 0; | 539 return 0; |
537 | 540 |
538 if (buf_len < 0) | 541 if (buf_len < 0) |
539 return net::ERR_INVALID_ARGUMENT; | 542 return net::ERR_INVALID_ARGUMENT; |
540 | 543 |
541 if (!background_queue_) | 544 if (!background_queue_) |
542 return net::ERR_UNEXPECTED; | 545 return net::ERR_UNEXPECTED; |
543 | 546 |
544 background_queue_->ReadData(this, index, offset, buf, buf_len, callback); | 547 background_queue_->ReadData(this, index, offset, buf, buf_len, callback); |
545 return net::ERR_IO_PENDING; | 548 return net::ERR_IO_PENDING; |
546 } | 549 } |
547 | 550 |
548 int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, | 551 int EntryImpl::ReadDataImpl(int index, |
| 552 int offset, |
| 553 IOBuffer* buf, |
| 554 int buf_len, |
549 const CompletionCallback& callback) { | 555 const CompletionCallback& callback) { |
550 if (net_log_.IsLogging()) { | 556 if (net_log_.IsLogging()) { |
551 net_log_.BeginEvent( | 557 net_log_.BeginEvent( |
552 net::NetLog::TYPE_ENTRY_READ_DATA, | 558 net::NetLog::TYPE_ENTRY_READ_DATA, |
553 CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); | 559 CreateNetLogReadWriteDataCallback(index, offset, buf_len, false)); |
554 } | 560 } |
555 | 561 |
556 int result = InternalReadData(index, offset, buf, buf_len, callback); | 562 int result = InternalReadData(index, offset, buf, buf_len, callback); |
557 | 563 |
558 if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { | 564 if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { |
559 net_log_.EndEvent( | 565 net_log_.EndEvent(net::NetLog::TYPE_ENTRY_READ_DATA, |
560 net::NetLog::TYPE_ENTRY_READ_DATA, | 566 CreateNetLogReadWriteCompleteCallback(result)); |
561 CreateNetLogReadWriteCompleteCallback(result)); | |
562 } | 567 } |
563 return result; | 568 return result; |
564 } | 569 } |
565 | 570 |
566 int EntryImplV3::WriteData(int index, int offset, IOBuffer* buf, int buf_len, | 571 int EntryImplV3::WriteData(int index, |
567 const CompletionCallback& callback, bool truncate) { | 572 int offset, |
| 573 IOBuffer* buf, |
| 574 int buf_len, |
| 575 const CompletionCallback& callback, |
| 576 bool truncate) { |
568 if (callback.is_null()) | 577 if (callback.is_null()) |
569 return WriteDataImpl(index, offset, buf, buf_len, callback, truncate); | 578 return WriteDataImpl(index, offset, buf, buf_len, callback, truncate); |
570 | 579 |
571 DCHECK(node_.Data()->dirty || read_only_); | 580 DCHECK(node_.Data()->dirty || read_only_); |
572 if (index < 0 || index >= kNumStreams) | 581 if (index < 0 || index >= kNumStreams) |
573 return net::ERR_INVALID_ARGUMENT; | 582 return net::ERR_INVALID_ARGUMENT; |
574 | 583 |
575 if (offset < 0 || buf_len < 0) | 584 if (offset < 0 || buf_len < 0) |
576 return net::ERR_INVALID_ARGUMENT; | 585 return net::ERR_INVALID_ARGUMENT; |
577 | 586 |
578 if (!background_queue_) | 587 if (!background_queue_) |
579 return net::ERR_UNEXPECTED; | 588 return net::ERR_UNEXPECTED; |
580 | 589 |
581 background_queue_->WriteData(this, index, offset, buf, buf_len, truncate, | 590 background_queue_->WriteData( |
582 callback); | 591 this, index, offset, buf, buf_len, truncate, callback); |
583 return net::ERR_IO_PENDING; | 592 return net::ERR_IO_PENDING; |
584 } | 593 } |
585 | 594 |
586 int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, | 595 int EntryImpl::WriteDataImpl(int index, |
| 596 int offset, |
| 597 IOBuffer* buf, |
| 598 int buf_len, |
587 const CompletionCallback& callback, | 599 const CompletionCallback& callback, |
588 bool truncate) { | 600 bool truncate) { |
589 if (net_log_.IsLogging()) { | 601 if (net_log_.IsLogging()) { |
590 net_log_.BeginEvent( | 602 net_log_.BeginEvent( |
591 net::NetLog::TYPE_ENTRY_WRITE_DATA, | 603 net::NetLog::TYPE_ENTRY_WRITE_DATA, |
592 CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); | 604 CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate)); |
593 } | 605 } |
594 | 606 |
595 int result = InternalWriteData(index, offset, buf, buf_len, callback, | 607 int result = |
596 truncate); | 608 InternalWriteData(index, offset, buf, buf_len, callback, truncate); |
597 | 609 |
598 if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { | 610 if (result != net::ERR_IO_PENDING && net_log_.IsLogging()) { |
599 net_log_.EndEvent( | 611 net_log_.EndEvent(net::NetLog::TYPE_ENTRY_WRITE_DATA, |
600 net::NetLog::TYPE_ENTRY_WRITE_DATA, | 612 CreateNetLogReadWriteCompleteCallback(result)); |
601 CreateNetLogReadWriteCompleteCallback(result)); | |
602 } | 613 } |
603 return result; | 614 return result; |
604 } | 615 } |
605 | 616 |
606 int EntryImplV3::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, | 617 int EntryImplV3::ReadSparseData(int64 offset, |
| 618 IOBuffer* buf, |
| 619 int buf_len, |
607 const CompletionCallback& callback) { | 620 const CompletionCallback& callback) { |
608 if (callback.is_null()) | 621 if (callback.is_null()) |
609 return ReadSparseDataImpl(offset, buf, buf_len, callback); | 622 return ReadSparseDataImpl(offset, buf, buf_len, callback); |
610 | 623 |
611 if (!background_queue_) | 624 if (!background_queue_) |
612 return net::ERR_UNEXPECTED; | 625 return net::ERR_UNEXPECTED; |
613 | 626 |
614 background_queue_->ReadSparseData(this, offset, buf, buf_len, callback); | 627 background_queue_->ReadSparseData(this, offset, buf, buf_len, callback); |
615 return net::ERR_IO_PENDING; | 628 return net::ERR_IO_PENDING; |
616 } | 629 } |
617 | 630 |
618 int EntryImpl::ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, | 631 int EntryImpl::ReadSparseDataImpl(int64 offset, |
| 632 IOBuffer* buf, |
| 633 int buf_len, |
619 const CompletionCallback& callback) { | 634 const CompletionCallback& callback) { |
620 DCHECK(node_.Data()->dirty || read_only_); | 635 DCHECK(node_.Data()->dirty || read_only_); |
621 int result = InitSparseData(); | 636 int result = InitSparseData(); |
622 if (net::OK != result) | 637 if (net::OK != result) |
623 return result; | 638 return result; |
624 | 639 |
625 TimeTicks start = TimeTicks::Now(); | 640 TimeTicks start = TimeTicks::Now(); |
626 result = sparse_->StartIO(SparseControl::kReadOperation, offset, buf, buf_len, | 641 result = sparse_->StartIO( |
627 callback); | 642 SparseControl::kReadOperation, offset, buf, buf_len, callback); |
628 ReportIOTime(kSparseRead, start); | 643 ReportIOTime(kSparseRead, start); |
629 return result; | 644 return result; |
630 } | 645 } |
631 | 646 |
632 int EntryImplV3::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, | 647 int EntryImplV3::WriteSparseData(int64 offset, |
| 648 IOBuffer* buf, |
| 649 int buf_len, |
633 const CompletionCallback& callback) { | 650 const CompletionCallback& callback) { |
634 if (callback.is_null()) | 651 if (callback.is_null()) |
635 return WriteSparseDataImpl(offset, buf, buf_len, callback); | 652 return WriteSparseDataImpl(offset, buf, buf_len, callback); |
636 | 653 |
637 if (!background_queue_) | 654 if (!background_queue_) |
638 return net::ERR_UNEXPECTED; | 655 return net::ERR_UNEXPECTED; |
639 | 656 |
640 background_queue_->WriteSparseData(this, offset, buf, buf_len, callback); | 657 background_queue_->WriteSparseData(this, offset, buf, buf_len, callback); |
641 return net::ERR_IO_PENDING; | 658 return net::ERR_IO_PENDING; |
642 } | 659 } |
643 | 660 |
644 int EntryImpl::WriteSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, | 661 int EntryImpl::WriteSparseDataImpl(int64 offset, |
| 662 IOBuffer* buf, |
| 663 int buf_len, |
645 const CompletionCallback& callback) { | 664 const CompletionCallback& callback) { |
646 DCHECK(node_.Data()->dirty || read_only_); | 665 DCHECK(node_.Data()->dirty || read_only_); |
647 int result = InitSparseData(); | 666 int result = InitSparseData(); |
648 if (net::OK != result) | 667 if (net::OK != result) |
649 return result; | 668 return result; |
650 | 669 |
651 TimeTicks start = TimeTicks::Now(); | 670 TimeTicks start = TimeTicks::Now(); |
652 result = sparse_->StartIO(SparseControl::kWriteOperation, offset, buf, | 671 result = sparse_->StartIO( |
653 buf_len, callback); | 672 SparseControl::kWriteOperation, offset, buf, buf_len, callback); |
654 ReportIOTime(kSparseWrite, start); | 673 ReportIOTime(kSparseWrite, start); |
655 return result; | 674 return result; |
656 } | 675 } |
657 | 676 |
658 int EntryImplV3::GetAvailableRange(int64 offset, int len, int64* start, | 677 int EntryImplV3::GetAvailableRange(int64 offset, |
| 678 int len, |
| 679 int64* start, |
659 const CompletionCallback& callback) { | 680 const CompletionCallback& callback) { |
660 if (!background_queue_) | 681 if (!background_queue_) |
661 return net::ERR_UNEXPECTED; | 682 return net::ERR_UNEXPECTED; |
662 | 683 |
663 background_queue_->GetAvailableRange(this, offset, len, start, callback); | 684 background_queue_->GetAvailableRange(this, offset, len, start, callback); |
664 return net::ERR_IO_PENDING; | 685 return net::ERR_IO_PENDING; |
665 } | 686 } |
666 | 687 |
667 int EntryImpl::GetAvailableRangeImpl(int64 offset, int len, int64* start) { | 688 int EntryImpl::GetAvailableRangeImpl(int64 offset, int len, int64* start) { |
668 int result = InitSparseData(); | 689 int result = InitSparseData(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 node_.Data()->dirty = 0; | 783 node_.Data()->dirty = 0; |
763 node_.Store(); | 784 node_.Store(); |
764 } | 785 } |
765 } | 786 } |
766 | 787 |
767 Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this)); | 788 Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this)); |
768 net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL); | 789 net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL); |
769 backend_->OnEntryDestroyEnd(); | 790 backend_->OnEntryDestroyEnd(); |
770 } | 791 } |
771 | 792 |
772 int EntryImpl::InternalReadData(int index, int offset, | 793 int EntryImpl::InternalReadData(int index, |
773 IOBuffer* buf, int buf_len, | 794 int offset, |
| 795 IOBuffer* buf, |
| 796 int buf_len, |
774 const CompletionCallback& callback) { | 797 const CompletionCallback& callback) { |
775 DCHECK(node_.Data()->dirty || read_only_); | 798 DCHECK(node_.Data()->dirty || read_only_); |
776 DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len; | 799 DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len; |
777 if (index < 0 || index >= kNumStreams) | 800 if (index < 0 || index >= kNumStreams) |
778 return net::ERR_INVALID_ARGUMENT; | 801 return net::ERR_INVALID_ARGUMENT; |
779 | 802 |
780 int entry_size = entry_.Data()->data_size[index]; | 803 int entry_size = entry_.Data()->data_size[index]; |
781 if (offset >= entry_size || offset < 0 || !buf_len) | 804 if (offset >= entry_size || offset < 0 || !buf_len) |
782 return 0; | 805 return 0; |
783 | 806 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 File* file = GetBackingFile(address, index); | 840 File* file = GetBackingFile(address, index); |
818 if (!file) { | 841 if (!file) { |
819 DoomImpl(); | 842 DoomImpl(); |
820 LOG(ERROR) << "No file for " << std::hex << address.value(); | 843 LOG(ERROR) << "No file for " << std::hex << address.value(); |
821 return net::ERR_FILE_NOT_FOUND; | 844 return net::ERR_FILE_NOT_FOUND; |
822 } | 845 } |
823 | 846 |
824 size_t file_offset = offset; | 847 size_t file_offset = offset; |
825 if (address.is_block_file()) { | 848 if (address.is_block_file()) { |
826 DCHECK_LE(offset + buf_len, kMaxBlockSize); | 849 DCHECK_LE(offset + buf_len, kMaxBlockSize); |
827 file_offset += address.start_block() * address.BlockSize() + | 850 file_offset += |
828 kBlockHeaderSize; | 851 address.start_block() * address.BlockSize() + kBlockHeaderSize; |
829 } | 852 } |
830 | 853 |
831 SyncCallback* io_callback = NULL; | 854 SyncCallback* io_callback = NULL; |
832 if (!callback.is_null()) { | 855 if (!callback.is_null()) { |
833 io_callback = new SyncCallback(this, buf, callback, | 856 io_callback = new SyncCallback( |
834 net::NetLog::TYPE_ENTRY_READ_DATA); | 857 this, buf, callback, net::NetLog::TYPE_ENTRY_READ_DATA); |
835 } | 858 } |
836 | 859 |
837 TimeTicks start_async = TimeTicks::Now(); | 860 TimeTicks start_async = TimeTicks::Now(); |
838 | 861 |
839 bool completed; | 862 bool completed; |
840 if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) { | 863 if (!file->Read(buf->data(), buf_len, file_offset, io_callback, &completed)) { |
841 if (io_callback) | 864 if (io_callback) |
842 io_callback->Discard(); | 865 io_callback->Discard(); |
843 DoomImpl(); | 866 DoomImpl(); |
844 return net::ERR_CACHE_READ_FAILURE; | 867 return net::ERR_CACHE_READ_FAILURE; |
845 } | 868 } |
846 | 869 |
847 if (io_callback && completed) | 870 if (io_callback && completed) |
848 io_callback->Discard(); | 871 io_callback->Discard(); |
849 | 872 |
850 if (io_callback) | 873 if (io_callback) |
851 ReportIOTime(kReadAsync1, start_async); | 874 ReportIOTime(kReadAsync1, start_async); |
852 | 875 |
853 ReportIOTime(kRead, start); | 876 ReportIOTime(kRead, start); |
854 return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING; | 877 return (completed || callback.is_null()) ? buf_len : net::ERR_IO_PENDING; |
855 } | 878 } |
856 | 879 |
857 int EntryImpl::InternalWriteData(int index, int offset, | 880 int EntryImpl::InternalWriteData(int index, |
858 IOBuffer* buf, int buf_len, | 881 int offset, |
| 882 IOBuffer* buf, |
| 883 int buf_len, |
859 const CompletionCallback& callback, | 884 const CompletionCallback& callback, |
860 bool truncate) { | 885 bool truncate) { |
861 DCHECK(node_.Data()->dirty || read_only_); | 886 DCHECK(node_.Data()->dirty || read_only_); |
862 DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len; | 887 DVLOG(2) << "Write to " << index << " at " << offset << " : " << buf_len; |
863 if (index < 0 || index >= kNumStreams) | 888 if (index < 0 || index >= kNumStreams) |
864 return net::ERR_INVALID_ARGUMENT; | 889 return net::ERR_INVALID_ARGUMENT; |
865 | 890 |
866 if (offset < 0 || buf_len < 0) | 891 if (offset < 0 || buf_len < 0) |
867 return net::ERR_INVALID_ARGUMENT; | 892 return net::ERR_INVALID_ARGUMENT; |
868 | 893 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 return 0; | 940 return 0; |
916 } | 941 } |
917 | 942 |
918 File* file = GetBackingFile(address, index); | 943 File* file = GetBackingFile(address, index); |
919 if (!file) | 944 if (!file) |
920 return net::ERR_FILE_NOT_FOUND; | 945 return net::ERR_FILE_NOT_FOUND; |
921 | 946 |
922 size_t file_offset = offset; | 947 size_t file_offset = offset; |
923 if (address.is_block_file()) { | 948 if (address.is_block_file()) { |
924 DCHECK_LE(offset + buf_len, kMaxBlockSize); | 949 DCHECK_LE(offset + buf_len, kMaxBlockSize); |
925 file_offset += address.start_block() * address.BlockSize() + | 950 file_offset += |
926 kBlockHeaderSize; | 951 address.start_block() * address.BlockSize() + kBlockHeaderSize; |
927 } else if (truncate || (extending && !buf_len)) { | 952 } else if (truncate || (extending && !buf_len)) { |
928 if (!file->SetLength(offset + buf_len)) | 953 if (!file->SetLength(offset + buf_len)) |
929 return net::ERR_FAILED; | 954 return net::ERR_FAILED; |
930 } | 955 } |
931 | 956 |
932 if (!buf_len) | 957 if (!buf_len) |
933 return 0; | 958 return 0; |
934 | 959 |
935 SyncCallback* io_callback = NULL; | 960 SyncCallback* io_callback = NULL; |
936 if (!callback.is_null()) { | 961 if (!callback.is_null()) { |
937 io_callback = new SyncCallback(this, buf, callback, | 962 io_callback = new SyncCallback( |
938 net::NetLog::TYPE_ENTRY_WRITE_DATA); | 963 this, buf, callback, net::NetLog::TYPE_ENTRY_WRITE_DATA); |
939 } | 964 } |
940 | 965 |
941 TimeTicks start_async = TimeTicks::Now(); | 966 TimeTicks start_async = TimeTicks::Now(); |
942 | 967 |
943 bool completed; | 968 bool completed; |
944 if (!file->Write(buf->data(), buf_len, file_offset, io_callback, | 969 if (!file->Write( |
945 &completed)) { | 970 buf->data(), buf_len, file_offset, io_callback, &completed)) { |
946 if (io_callback) | 971 if (io_callback) |
947 io_callback->Discard(); | 972 io_callback->Discard(); |
948 return net::ERR_CACHE_WRITE_FAILURE; | 973 return net::ERR_CACHE_WRITE_FAILURE; |
949 } | 974 } |
950 | 975 |
951 if (io_callback && completed) | 976 if (io_callback && completed) |
952 io_callback->Discard(); | 977 io_callback->Discard(); |
953 | 978 |
954 if (io_callback) | 979 if (io_callback) |
955 ReportIOTime(kWriteAsync1, start_async); | 980 ReportIOTime(kWriteAsync1, start_async); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 // important that the entry doesn't keep a reference to this address, or we'll | 1024 // important that the entry doesn't keep a reference to this address, or we'll |
1000 // end up deleting the contents of |address| once again. | 1025 // end up deleting the contents of |address| once again. |
1001 void EntryImpl::DeleteData(Addr address, int index) { | 1026 void EntryImpl::DeleteData(Addr address, int index) { |
1002 DCHECK(backend_); | 1027 DCHECK(backend_); |
1003 if (!address.is_initialized()) | 1028 if (!address.is_initialized()) |
1004 return; | 1029 return; |
1005 if (address.is_separate_file()) { | 1030 if (address.is_separate_file()) { |
1006 int failure = !DeleteCacheFile(backend_->GetFileName(address)); | 1031 int failure = !DeleteCacheFile(backend_->GetFileName(address)); |
1007 CACHE_UMA(COUNTS, "DeleteFailed", 0, failure); | 1032 CACHE_UMA(COUNTS, "DeleteFailed", 0, failure); |
1008 if (failure) { | 1033 if (failure) { |
1009 LOG(ERROR) << "Failed to delete " << | 1034 LOG(ERROR) << "Failed to delete " << backend_->GetFileName(address) |
1010 backend_->GetFileName(address).value() << " from the cache."; | 1035 .value() << " from the cache."; |
1011 } | 1036 } |
1012 if (files_[index]) | 1037 if (files_[index]) |
1013 files_[index] = NULL; // Releases the object. | 1038 files_[index] = NULL; // Releases the object. |
1014 } else { | 1039 } else { |
1015 backend_->DeleteBlock(address, true); | 1040 backend_->DeleteBlock(address, true); |
1016 } | 1041 } |
1017 } | 1042 } |
1018 | 1043 |
1019 void EntryImpl::UpdateRank(bool modified) { | 1044 void EntryImpl::UpdateRank(bool modified) { |
1020 if (!backend_) | 1045 if (!backend_) |
(...skipping 20 matching lines...) Expand all Loading... |
1041 SparseControl::DeleteChildren(this); | 1066 SparseControl::DeleteChildren(this); |
1042 } | 1067 } |
1043 | 1068 |
1044 if (GetDataSize(0)) | 1069 if (GetDataSize(0)) |
1045 CACHE_UMA(COUNTS, "DeleteHeader", 0, GetDataSize(0)); | 1070 CACHE_UMA(COUNTS, "DeleteHeader", 0, GetDataSize(0)); |
1046 if (GetDataSize(1)) | 1071 if (GetDataSize(1)) |
1047 CACHE_UMA(COUNTS, "DeleteData", 0, GetDataSize(1)); | 1072 CACHE_UMA(COUNTS, "DeleteData", 0, GetDataSize(1)); |
1048 for (int index = 0; index < kNumStreams; index++) { | 1073 for (int index = 0; index < kNumStreams; index++) { |
1049 Addr address(entry_.Data()->data_addr[index]); | 1074 Addr address(entry_.Data()->data_addr[index]); |
1050 if (address.is_initialized()) { | 1075 if (address.is_initialized()) { |
1051 backend_->ModifyStorageSize(entry_.Data()->data_size[index] - | 1076 backend_->ModifyStorageSize( |
1052 unreported_size_[index], 0); | 1077 entry_.Data()->data_size[index] - unreported_size_[index], 0); |
1053 entry_.Data()->data_addr[index] = 0; | 1078 entry_.Data()->data_addr[index] = 0; |
1054 entry_.Data()->data_size[index] = 0; | 1079 entry_.Data()->data_size[index] = 0; |
1055 entry_.Store(); | 1080 entry_.Store(); |
1056 DeleteData(address, index); | 1081 DeleteData(address, index); |
1057 } | 1082 } |
1058 } | 1083 } |
1059 | 1084 |
1060 if (!everything) | 1085 if (!everything) |
1061 return; | 1086 return; |
1062 | 1087 |
(...skipping 22 matching lines...) Expand all Loading... |
1085 // buffer and / or the files needed to store the data. | 1110 // buffer and / or the files needed to store the data. |
1086 // | 1111 // |
1087 // In general, a buffer may overlap data already stored on disk, and in that | 1112 // In general, a buffer may overlap data already stored on disk, and in that |
1088 // case, the contents of the buffer are the most accurate. It may also extend | 1113 // case, the contents of the buffer are the most accurate. It may also extend |
1089 // the file, but we don't want to read from disk just to keep the buffer up to | 1114 // the file, but we don't want to read from disk just to keep the buffer up to |
1090 // date. This means that as soon as there is a chance to get confused about what | 1115 // date. This means that as soon as there is a chance to get confused about what |
1091 // is the most recent version of some part of a file, we'll flush the buffer and | 1116 // is the most recent version of some part of a file, we'll flush the buffer and |
1092 // reuse it for the new data. Keep in mind that the normal use pattern is quite | 1117 // reuse it for the new data. Keep in mind that the normal use pattern is quite |
1093 // simple (write sequentially from the beginning), so we optimize for handling | 1118 // simple (write sequentially from the beginning), so we optimize for handling |
1094 // that case. | 1119 // that case. |
1095 bool EntryImpl::PrepareTarget(int index, int offset, int buf_len, | 1120 bool EntryImpl::PrepareTarget(int index, |
| 1121 int offset, |
| 1122 int buf_len, |
1096 bool truncate) { | 1123 bool truncate) { |
1097 if (truncate) | 1124 if (truncate) |
1098 return HandleTruncation(index, offset, buf_len); | 1125 return HandleTruncation(index, offset, buf_len); |
1099 | 1126 |
1100 if (!offset && !buf_len) | 1127 if (!offset && !buf_len) |
1101 return true; | 1128 return true; |
1102 | 1129 |
1103 Addr address(entry_.Data()->data_addr[index]); | 1130 Addr address(entry_.Data()->data_addr[index]); |
1104 if (address.is_initialized()) { | 1131 if (address.is_initialized()) { |
1105 if (address.is_block_file() && !MoveToLocalBuffer(index)) | 1132 if (address.is_block_file() && !MoveToLocalBuffer(index)) |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 return; | 1370 return; |
1344 } | 1371 } |
1345 } | 1372 } |
1346 | 1373 |
1347 // Bad news: we'd have to read the info from disk so instead we'll just tell | 1374 // Bad news: we'd have to read the info from disk so instead we'll just tell |
1348 // the caller where to read from. | 1375 // the caller where to read from. |
1349 *buffer = NULL; | 1376 *buffer = NULL; |
1350 address->set_value(entry_.Data()->data_addr[index]); | 1377 address->set_value(entry_.Data()->data_addr[index]); |
1351 if (address->is_initialized()) { | 1378 if (address->is_initialized()) { |
1352 // Prevent us from deleting the block from the backing store. | 1379 // Prevent us from deleting the block from the backing store. |
1353 backend_->ModifyStorageSize(entry_.Data()->data_size[index] - | 1380 backend_->ModifyStorageSize( |
1354 unreported_size_[index], 0); | 1381 entry_.Data()->data_size[index] - unreported_size_[index], 0); |
1355 entry_.Data()->data_addr[index] = 0; | 1382 entry_.Data()->data_addr[index] = 0; |
1356 entry_.Data()->data_size[index] = 0; | 1383 entry_.Data()->data_size[index] = 0; |
1357 } | 1384 } |
1358 } | 1385 } |
1359 | 1386 |
1360 #endif // defined(V3_NOT_JUST_YET_READY). | 1387 #endif // defined(V3_NOT_JUST_YET_READY). |
1361 | 1388 |
1362 void EntryImplV3::ReportIOTime(Operation op, const base::TimeTicks& start) { | 1389 void EntryImplV3::ReportIOTime(Operation op, const base::TimeTicks& start) { |
1363 if (!backend_) | 1390 if (!backend_) |
1364 return; | 1391 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 } | 1440 } |
1414 | 1441 |
1415 Time EntryImplV3::GetLastModified() const { | 1442 Time EntryImplV3::GetLastModified() const { |
1416 return Time(); | 1443 return Time(); |
1417 } | 1444 } |
1418 | 1445 |
1419 int32 EntryImplV3::GetDataSize(int index) const { | 1446 int32 EntryImplV3::GetDataSize(int index) const { |
1420 return 0; | 1447 return 0; |
1421 } | 1448 } |
1422 | 1449 |
1423 int EntryImplV3::ReadData(int index, int offset, IOBuffer* buf, int buf_len, | 1450 int EntryImplV3::ReadData(int index, |
| 1451 int offset, |
| 1452 IOBuffer* buf, |
| 1453 int buf_len, |
1424 const CompletionCallback& callback) { | 1454 const CompletionCallback& callback) { |
1425 return net::ERR_FAILED; | 1455 return net::ERR_FAILED; |
1426 } | 1456 } |
1427 | 1457 |
1428 int EntryImplV3::WriteData(int index, int offset, IOBuffer* buf, int buf_len, | 1458 int EntryImplV3::WriteData(int index, |
1429 const CompletionCallback& callback, bool truncate) { | 1459 int offset, |
| 1460 IOBuffer* buf, |
| 1461 int buf_len, |
| 1462 const CompletionCallback& callback, |
| 1463 bool truncate) { |
1430 return net::ERR_FAILED; | 1464 return net::ERR_FAILED; |
1431 } | 1465 } |
1432 | 1466 |
1433 int EntryImplV3::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, | 1467 int EntryImplV3::ReadSparseData(int64 offset, |
| 1468 IOBuffer* buf, |
| 1469 int buf_len, |
1434 const CompletionCallback& callback) { | 1470 const CompletionCallback& callback) { |
1435 return net::ERR_FAILED; | 1471 return net::ERR_FAILED; |
1436 } | 1472 } |
1437 | 1473 |
1438 int EntryImplV3::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, | 1474 int EntryImplV3::WriteSparseData(int64 offset, |
| 1475 IOBuffer* buf, |
| 1476 int buf_len, |
1439 const CompletionCallback& callback) { | 1477 const CompletionCallback& callback) { |
1440 return net::ERR_FAILED; | 1478 return net::ERR_FAILED; |
1441 } | 1479 } |
1442 | 1480 |
1443 int EntryImplV3::GetAvailableRange(int64 offset, int len, int64* start, | 1481 int EntryImplV3::GetAvailableRange(int64 offset, |
| 1482 int len, |
| 1483 int64* start, |
1444 const CompletionCallback& callback) { | 1484 const CompletionCallback& callback) { |
1445 return net::ERR_FAILED; | 1485 return net::ERR_FAILED; |
1446 } | 1486 } |
1447 | 1487 |
1448 bool EntryImplV3::CouldBeSparse() const { | 1488 bool EntryImplV3::CouldBeSparse() const { |
1449 return false; | 1489 return false; |
1450 } | 1490 } |
1451 | 1491 |
1452 void EntryImplV3::CancelSparseIO() { | 1492 void EntryImplV3::CancelSparseIO() { |
1453 NOTIMPLEMENTED(); | 1493 NOTIMPLEMENTED(); |
1454 } | 1494 } |
1455 | 1495 |
1456 int EntryImplV3::ReadyForSparseIO(const CompletionCallback& callback) { | 1496 int EntryImplV3::ReadyForSparseIO(const CompletionCallback& callback) { |
1457 return net::ERR_FAILED; | 1497 return net::ERR_FAILED; |
1458 } | 1498 } |
1459 | 1499 |
1460 EntryImplV3::~EntryImplV3() { | 1500 EntryImplV3::~EntryImplV3() { |
1461 NOTIMPLEMENTED(); | 1501 NOTIMPLEMENTED(); |
1462 } | 1502 } |
1463 | 1503 |
1464 } // namespace disk_cache | 1504 } // namespace disk_cache |
OLD | NEW |