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