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/sparse_control.h" | 5 #include "net/disk_cache/blockfile/sparse_control.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 NOTREACHED(); | 154 NOTREACHED(); |
155 return net::NetLog::TYPE_CANCELLED; | 155 return net::NetLog::TYPE_CANCELLED; |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 // Logs the end event for |operation| on a child entry. Range operations log | 159 // Logs the end event for |operation| on a child entry. Range operations log |
160 // no events for each child they search through. | 160 // no events for each child they search through. |
161 void LogChildOperationEnd(const net::BoundNetLog& net_log, | 161 void LogChildOperationEnd(const net::BoundNetLog& net_log, |
162 disk_cache::SparseControl::SparseOperation operation, | 162 disk_cache::SparseControl::SparseOperation operation, |
163 int result) { | 163 int result) { |
164 if (net_log.IsLogging()) { | 164 if (net_log.GetCaptureMode().enabled()) { |
165 net::NetLog::EventType event_type; | 165 net::NetLog::EventType event_type; |
166 switch (operation) { | 166 switch (operation) { |
167 case disk_cache::SparseControl::kReadOperation: | 167 case disk_cache::SparseControl::kReadOperation: |
168 event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA; | 168 event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA; |
169 break; | 169 break; |
170 case disk_cache::SparseControl::kWriteOperation: | 170 case disk_cache::SparseControl::kWriteOperation: |
171 event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA; | 171 event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA; |
172 break; | 172 break; |
173 case disk_cache::SparseControl::kGetRangeOperation: | 173 case disk_cache::SparseControl::kGetRangeOperation: |
174 return; | 174 return; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 offset_ = offset; | 268 offset_ = offset; |
269 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL; | 269 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL; |
270 buf_len_ = buf_len; | 270 buf_len_ = buf_len; |
271 user_callback_ = callback; | 271 user_callback_ = callback; |
272 | 272 |
273 result_ = 0; | 273 result_ = 0; |
274 pending_ = false; | 274 pending_ = false; |
275 finished_ = false; | 275 finished_ = false; |
276 abort_ = false; | 276 abort_ = false; |
277 | 277 |
278 if (entry_->net_log().IsLogging()) { | 278 if (entry_->net_log().GetCaptureMode().enabled()) { |
279 entry_->net_log().BeginEvent( | 279 entry_->net_log().BeginEvent( |
280 GetSparseEventType(operation_), | 280 GetSparseEventType(operation_), |
281 CreateNetLogSparseOperationCallback(offset_, buf_len_)); | 281 CreateNetLogSparseOperationCallback(offset_, buf_len_)); |
282 } | 282 } |
283 DoChildrenIO(); | 283 DoChildrenIO(); |
284 | 284 |
285 if (!pending_) { | 285 if (!pending_) { |
286 // Everything was done synchronously. | 286 // Everything was done synchronously. |
287 operation_ = kNoOperation; | 287 operation_ = kNoOperation; |
288 user_buf_ = NULL; | 288 user_buf_ = NULL; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 DLOG(ERROR) << "Failed to save child data"; | 672 DLOG(ERROR) << "Failed to save child data"; |
673 SetChildBit(true); | 673 SetChildBit(true); |
674 } | 674 } |
675 | 675 |
676 void SparseControl::DoChildrenIO() { | 676 void SparseControl::DoChildrenIO() { |
677 while (DoChildIO()) continue; | 677 while (DoChildIO()) continue; |
678 | 678 |
679 // Range operations are finished synchronously, often without setting | 679 // Range operations are finished synchronously, often without setting |
680 // |finished_| to true. | 680 // |finished_| to true. |
681 if (kGetRangeOperation == operation_ && | 681 if (kGetRangeOperation == operation_ && |
682 entry_->net_log().IsLogging()) { | 682 entry_->net_log().GetCaptureMode().enabled()) { |
683 entry_->net_log().EndEvent( | 683 entry_->net_log().EndEvent( |
684 net::NetLog::TYPE_SPARSE_GET_RANGE, | 684 net::NetLog::TYPE_SPARSE_GET_RANGE, |
685 CreateNetLogGetAvailableRangeResultCallback(offset_, result_)); | 685 CreateNetLogGetAvailableRangeResultCallback(offset_, result_)); |
686 } | 686 } |
687 if (finished_) { | 687 if (finished_) { |
688 if (kGetRangeOperation != operation_ && | 688 if (kGetRangeOperation != operation_ && |
689 entry_->net_log().IsLogging()) { | 689 entry_->net_log().GetCaptureMode().enabled()) { |
690 entry_->net_log().EndEvent(GetSparseEventType(operation_)); | 690 entry_->net_log().EndEvent(GetSparseEventType(operation_)); |
691 } | 691 } |
692 if (pending_) | 692 if (pending_) |
693 DoUserCallback(); // Don't touch this object after this point. | 693 DoUserCallback(); // Don't touch this object after this point. |
694 } | 694 } |
695 } | 695 } |
696 | 696 |
697 bool SparseControl::DoChildIO() { | 697 bool SparseControl::DoChildIO() { |
698 finished_ = true; | 698 finished_ = true; |
699 if (!buf_len_ || result_ < 0) | 699 if (!buf_len_ || result_ < 0) |
700 return false; | 700 return false; |
701 | 701 |
702 if (!OpenChild()) | 702 if (!OpenChild()) |
703 return false; | 703 return false; |
704 | 704 |
705 if (!VerifyRange()) | 705 if (!VerifyRange()) |
706 return false; | 706 return false; |
707 | 707 |
708 // We have more work to do. Let's not trigger a callback to the caller. | 708 // We have more work to do. Let's not trigger a callback to the caller. |
709 finished_ = false; | 709 finished_ = false; |
710 CompletionCallback callback; | 710 CompletionCallback callback; |
711 if (!user_callback_.is_null()) { | 711 if (!user_callback_.is_null()) { |
712 callback = | 712 callback = |
713 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this)); | 713 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this)); |
714 } | 714 } |
715 | 715 |
716 int rv = 0; | 716 int rv = 0; |
717 switch (operation_) { | 717 switch (operation_) { |
718 case kReadOperation: | 718 case kReadOperation: |
719 if (entry_->net_log().IsLogging()) { | 719 if (entry_->net_log().GetCaptureMode().enabled()) { |
720 entry_->net_log().BeginEvent( | 720 entry_->net_log().BeginEvent( |
721 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, | 721 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, |
722 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 722 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
723 child_len_)); | 723 child_len_)); |
724 } | 724 } |
725 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_.get(), | 725 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_.get(), |
726 child_len_, callback); | 726 child_len_, callback); |
727 break; | 727 break; |
728 case kWriteOperation: | 728 case kWriteOperation: |
729 if (entry_->net_log().IsLogging()) { | 729 if (entry_->net_log().GetCaptureMode().enabled()) { |
730 entry_->net_log().BeginEvent( | 730 entry_->net_log().BeginEvent( |
731 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, | 731 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, |
732 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 732 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
733 child_len_)); | 733 child_len_)); |
734 } | 734 } |
735 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_.get(), | 735 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_.get(), |
736 child_len_, callback, false); | 736 child_len_, callback, false); |
737 break; | 737 break; |
738 case kGetRangeOperation: | 738 case kGetRangeOperation: |
739 rv = DoGetAvailableRange(); | 739 rv = DoGetAvailableRange(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 } | 849 } |
850 | 850 |
851 void SparseControl::OnChildIOCompleted(int result) { | 851 void SparseControl::OnChildIOCompleted(int result) { |
852 DCHECK_NE(net::ERR_IO_PENDING, result); | 852 DCHECK_NE(net::ERR_IO_PENDING, result); |
853 DoChildIOCompleted(result); | 853 DoChildIOCompleted(result); |
854 | 854 |
855 if (abort_) { | 855 if (abort_) { |
856 // We'll return the current result of the operation, which may be less than | 856 // We'll return the current result of the operation, which may be less than |
857 // the bytes to read or write, but the user cancelled the operation. | 857 // the bytes to read or write, but the user cancelled the operation. |
858 abort_ = false; | 858 abort_ = false; |
859 if (entry_->net_log().IsLogging()) { | 859 if (entry_->net_log().GetCaptureMode().enabled()) { |
860 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); | 860 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); |
861 entry_->net_log().EndEvent(GetSparseEventType(operation_)); | 861 entry_->net_log().EndEvent(GetSparseEventType(operation_)); |
862 } | 862 } |
863 // We have an indirect reference to this object for every callback so if | 863 // We have an indirect reference to this object for every callback so if |
864 // there is only one callback, we may delete this object before reaching | 864 // there is only one callback, we may delete this object before reaching |
865 // DoAbortCallbacks. | 865 // DoAbortCallbacks. |
866 bool has_abort_callbacks = !abort_callbacks_.empty(); | 866 bool has_abort_callbacks = !abort_callbacks_.empty(); |
867 DoUserCallback(); | 867 DoUserCallback(); |
868 if (has_abort_callbacks) | 868 if (has_abort_callbacks) |
869 DoAbortCallbacks(); | 869 DoAbortCallbacks(); |
(...skipping 24 matching lines...) Expand all Loading... |
894 CompletionCallback cb = abort_callbacks_[i]; | 894 CompletionCallback cb = abort_callbacks_[i]; |
895 if (i == abort_callbacks_.size() - 1) | 895 if (i == abort_callbacks_.size() - 1) |
896 abort_callbacks_.clear(); | 896 abort_callbacks_.clear(); |
897 | 897 |
898 entry_->Release(); // Don't touch object after this line. | 898 entry_->Release(); // Don't touch object after this line. |
899 cb.Run(net::OK); | 899 cb.Run(net::OK); |
900 } | 900 } |
901 } | 901 } |
902 | 902 |
903 } // namespace disk_cache | 903 } // namespace disk_cache |
OLD | NEW |