| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 NOTREACHED(); | 156 NOTREACHED(); |
| 157 return net::NetLog::TYPE_CANCELLED; | 157 return net::NetLog::TYPE_CANCELLED; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Logs the end event for |operation| on a child entry. Range operations log | 161 // Logs the end event for |operation| on a child entry. Range operations log |
| 162 // no events for each child they search through. | 162 // no events for each child they search through. |
| 163 void LogChildOperationEnd(const net::BoundNetLog& net_log, | 163 void LogChildOperationEnd(const net::BoundNetLog& net_log, |
| 164 disk_cache::SparseControl::SparseOperation operation, | 164 disk_cache::SparseControl::SparseOperation operation, |
| 165 int result) { | 165 int result) { |
| 166 if (net_log.GetCaptureMode().enabled()) { | 166 if (net_log.HasObservers()) { |
| 167 net::NetLog::EventType event_type; | 167 net::NetLog::EventType event_type; |
| 168 switch (operation) { | 168 switch (operation) { |
| 169 case disk_cache::SparseControl::kReadOperation: | 169 case disk_cache::SparseControl::kReadOperation: |
| 170 event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA; | 170 event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA; |
| 171 break; | 171 break; |
| 172 case disk_cache::SparseControl::kWriteOperation: | 172 case disk_cache::SparseControl::kWriteOperation: |
| 173 event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA; | 173 event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA; |
| 174 break; | 174 break; |
| 175 case disk_cache::SparseControl::kGetRangeOperation: | 175 case disk_cache::SparseControl::kGetRangeOperation: |
| 176 return; | 176 return; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 offset_ = offset; | 247 offset_ = offset; |
| 248 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL; | 248 user_buf_ = buf ? new net::DrainableIOBuffer(buf, buf_len) : NULL; |
| 249 buf_len_ = buf_len; | 249 buf_len_ = buf_len; |
| 250 user_callback_ = callback; | 250 user_callback_ = callback; |
| 251 | 251 |
| 252 result_ = 0; | 252 result_ = 0; |
| 253 pending_ = false; | 253 pending_ = false; |
| 254 finished_ = false; | 254 finished_ = false; |
| 255 abort_ = false; | 255 abort_ = false; |
| 256 | 256 |
| 257 if (entry_->net_log().GetCaptureMode().enabled()) { | 257 if (entry_->net_log().HasObservers()) { |
| 258 entry_->net_log().BeginEvent( | 258 entry_->net_log().BeginEvent( |
| 259 GetSparseEventType(operation_), | 259 GetSparseEventType(operation_), |
| 260 CreateNetLogSparseOperationCallback(offset_, buf_len_)); | 260 CreateNetLogSparseOperationCallback(offset_, buf_len_)); |
| 261 } | 261 } |
| 262 DoChildrenIO(); | 262 DoChildrenIO(); |
| 263 | 263 |
| 264 if (!pending_) { | 264 if (!pending_) { |
| 265 // Everything was done synchronously. | 265 // Everything was done synchronously. |
| 266 operation_ = kNoOperation; | 266 operation_ = kNoOperation; |
| 267 user_buf_ = NULL; | 267 user_buf_ = NULL; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 finished_ = false; | 556 finished_ = false; |
| 557 CompletionCallback callback; | 557 CompletionCallback callback; |
| 558 if (!user_callback_.is_null()) { | 558 if (!user_callback_.is_null()) { |
| 559 callback = | 559 callback = |
| 560 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this)); | 560 base::Bind(&SparseControl::OnChildIOCompleted, base::Unretained(this)); |
| 561 } | 561 } |
| 562 | 562 |
| 563 int rv = 0; | 563 int rv = 0; |
| 564 switch (operation_) { | 564 switch (operation_) { |
| 565 case kReadOperation: | 565 case kReadOperation: |
| 566 if (entry_->net_log().GetCaptureMode().enabled()) { | 566 if (entry_->net_log().HasObservers()) { |
| 567 entry_->net_log().BeginEvent( | 567 entry_->net_log().BeginEvent( |
| 568 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, | 568 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, |
| 569 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 569 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
| 570 child_len_)); | 570 child_len_)); |
| 571 } | 571 } |
| 572 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_.get(), | 572 rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_.get(), |
| 573 child_len_, callback); | 573 child_len_, callback); |
| 574 break; | 574 break; |
| 575 case kWriteOperation: | 575 case kWriteOperation: |
| 576 if (entry_->net_log().GetCaptureMode().enabled()) { | 576 if (entry_->net_log().HasObservers()) { |
| 577 entry_->net_log().BeginEvent( | 577 entry_->net_log().BeginEvent( |
| 578 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, | 578 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, |
| 579 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), | 579 CreateNetLogSparseReadWriteCallback(child_->net_log().source(), |
| 580 child_len_)); | 580 child_len_)); |
| 581 } | 581 } |
| 582 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_.get(), | 582 rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_.get(), |
| 583 child_len_, callback, false); | 583 child_len_, callback, false); |
| 584 break; | 584 break; |
| 585 case kGetRangeOperation: | 585 case kGetRangeOperation: |
| 586 rv = DoGetAvailableRange(); | 586 rv = DoGetAvailableRange(); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 839 } |
| 840 | 840 |
| 841 void SparseControl::OnChildIOCompleted(int result) { | 841 void SparseControl::OnChildIOCompleted(int result) { |
| 842 DCHECK_NE(net::ERR_IO_PENDING, result); | 842 DCHECK_NE(net::ERR_IO_PENDING, result); |
| 843 DoChildIOCompleted(result); | 843 DoChildIOCompleted(result); |
| 844 | 844 |
| 845 if (abort_) { | 845 if (abort_) { |
| 846 // We'll return the current result of the operation, which may be less than | 846 // We'll return the current result of the operation, which may be less than |
| 847 // the bytes to read or write, but the user cancelled the operation. | 847 // the bytes to read or write, but the user cancelled the operation. |
| 848 abort_ = false; | 848 abort_ = false; |
| 849 if (entry_->net_log().GetCaptureMode().enabled()) { | 849 if (entry_->net_log().HasObservers()) { |
| 850 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); | 850 entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED); |
| 851 entry_->net_log().EndEvent(GetSparseEventType(operation_)); | 851 entry_->net_log().EndEvent(GetSparseEventType(operation_)); |
| 852 } | 852 } |
| 853 // We have an indirect reference to this object for every callback so if | 853 // We have an indirect reference to this object for every callback so if |
| 854 // there is only one callback, we may delete this object before reaching | 854 // there is only one callback, we may delete this object before reaching |
| 855 // DoAbortCallbacks. | 855 // DoAbortCallbacks. |
| 856 bool has_abort_callbacks = !abort_callbacks_.empty(); | 856 bool has_abort_callbacks = !abort_callbacks_.empty(); |
| 857 DoUserCallback(); | 857 DoUserCallback(); |
| 858 if (has_abort_callbacks) | 858 if (has_abort_callbacks) |
| 859 DoAbortCallbacks(); | 859 DoAbortCallbacks(); |
| 860 return; | 860 return; |
| 861 } | 861 } |
| 862 | 862 |
| 863 // We are running a callback from the message loop. It's time to restart what | 863 // We are running a callback from the message loop. It's time to restart what |
| 864 // we were doing before. | 864 // we were doing before. |
| 865 DoChildrenIO(); | 865 DoChildrenIO(); |
| 866 } | 866 } |
| 867 | 867 |
| 868 } // namespace disk_cache | 868 } // namespace disk_cache |
| OLD | NEW |