Chromium Code Reviews| Index: net/disk_cache/sparse_control.cc |
| =================================================================== |
| --- net/disk_cache/sparse_control.cc (revision 76773) |
| +++ net/disk_cache/sparse_control.cc (working copy) |
| @@ -15,6 +15,7 @@ |
| #include "net/disk_cache/backend_impl.h" |
| #include "net/disk_cache/entry_impl.h" |
| #include "net/disk_cache/file.h" |
| +#include "net/disk_cache/net_log_parameters.h" |
| using base::Time; |
| @@ -46,6 +47,22 @@ |
| signature, child_id); |
| } |
| +// Returns the NetLog event type corresponding to a SparseOperation. |
| +net::NetLog::EventType GetSparseEventType( |
| + disk_cache::SparseControl::SparseOperation operation) { |
| + switch (operation) { |
| + case disk_cache::SparseControl::kReadOperation: |
| + return net::NetLog::TYPE_SPARSE_READ; |
| + case disk_cache::SparseControl::kWriteOperation: |
| + return net::NetLog::TYPE_SPARSE_WRITE; |
| + case disk_cache::SparseControl::kGetRangeOperation: |
| + return net::NetLog::TYPE_SPARSE_GET_RANGE; |
| + default: |
| + NOTREACHED(); |
| + return net::NetLog::TYPE_CANCELLED; |
| + } |
| +} |
| + |
| // This class deletes the children of a sparse entry. |
| class ChildrenDeleter |
| : public base::RefCounted<ChildrenDeleter>, |
| @@ -138,30 +155,6 @@ |
| this, &ChildrenDeleter::DeleteChildren)); |
| } |
| -// Logs the end event for |operation|, if all events are being logged. |
| -void LogOperationEnd(const net::BoundNetLog& net_log, |
| - disk_cache::SparseControl::SparseOperation operation, |
| - int result) { |
| - if (net_log.IsLoggingAllEvents()) { |
| - net::NetLog::EventType event_type; |
| - switch (operation) { |
| - case disk_cache::SparseControl::kReadOperation: |
| - event_type = net::NetLog::TYPE_SPARSE_CONTROL_READ; |
| - break; |
| - case disk_cache::SparseControl::kWriteOperation: |
| - event_type = net::NetLog::TYPE_SPARSE_CONTROL_WRITE; |
| - break; |
| - case disk_cache::SparseControl::kGetRangeOperation: |
| - event_type = net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE; |
| - break; |
| - default: |
| - NOTREACHED(); |
| - return; |
| - } |
| - net_log.EndEventWithNetErrorCode(event_type, result); |
| - } |
| -} |
| - |
| } // namespace. |
| namespace disk_cache { |
| @@ -247,7 +240,11 @@ |
| finished_ = false; |
| abort_ = false; |
| - entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); |
| + if (entry_->net_log().IsLoggingAllEvents()) { |
| + entry_->net_log().BeginEvent( |
| + GetSparseEventType(operation_), |
| + make_scoped_refptr(new SparseOperationParameters(offset_, buf_len_))); |
| + } |
| DoChildrenIO(); |
| if (!pending_) { |
| @@ -317,6 +314,8 @@ |
| if (!buffer && !address.is_initialized()) |
| return; |
| + entry->net_log().AddEvent(net::NetLog::TYPE_SPARSE_DELETE_CHILDREN, NULL); |
| + |
| ChildrenDeleter* deleter = new ChildrenDeleter(entry->backend_, |
| entry->GetKey()); |
| // The object will self destruct when finished. |
| @@ -636,7 +635,16 @@ |
| while (DoChildIO()) continue; |
| if (finished_) { |
| - entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); |
| + if (entry_->net_log().IsLoggingAllEvents()) { |
| + if (operation_ != kGetRangeOperation) { |
|
rvargas (doing something else)
2011/03/04 21:39:16
nit: reverse this if
rvargas (doing something else)
2011/03/07 22:13:51
I guess you missed this one.
mmenke
2011/03/07 22:19:25
Yea, I did. Thanks for catching it. Done.
|
| + entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); |
| + } else { |
| + entry_->net_log().EndEvent( |
| + net::NetLog::TYPE_SPARSE_GET_RANGE, |
| + make_scoped_refptr( |
| + new GetAvailableRangeResultParameters(offset_, result_))); |
| + } |
| + } |
| if (pending_) |
| DoUserCallback(); |
| } |
| @@ -662,10 +670,10 @@ |
| case kReadOperation: |
| if (entry_->net_log().IsLoggingAllEvents()) { |
| entry_->net_log().BeginEvent( |
| - net::NetLog::TYPE_SPARSE_CONTROL_READ, |
| - make_scoped_refptr(new net::NetLogSourceParameter( |
| - "source_dependency", |
| - child_->net_log().source()))); |
| + net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, |
| + make_scoped_refptr(new SparseReadWriteParameters( |
| + child_->net_log().source(), |
| + child_len_))); |
| } |
| rv = child_->ReadDataImpl(kSparseData, child_offset_, user_buf_, |
| child_len_, callback); |
| @@ -673,19 +681,15 @@ |
| case kWriteOperation: |
| if (entry_->net_log().IsLoggingAllEvents()) { |
| entry_->net_log().BeginEvent( |
| - net::NetLog::TYPE_SPARSE_CONTROL_WRITE, |
| - make_scoped_refptr(new net::NetLogSourceParameter( |
| - "source_dependency", |
| - child_->net_log().source()))); |
| + net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, |
| + make_scoped_refptr(new SparseReadWriteParameters( |
| + child_->net_log().source(), |
| + child_len_))); |
| } |
| rv = child_->WriteDataImpl(kSparseData, child_offset_, user_buf_, |
| child_len_, callback, false); |
| break; |
| case kGetRangeOperation: |
| - if (entry_->net_log().IsLoggingAllEvents()) { |
| - entry_->net_log().BeginEvent(net::NetLog::TYPE_SPARSE_CONTROL_GET_RANGE, |
| - NULL); |
| - } |
| rv = DoGetAvailableRange(); |
| break; |
| default: |
| @@ -758,7 +762,8 @@ |
| } |
| void SparseControl::DoChildIOCompleted(int result) { |
| - LogOperationEnd(entry_->net_log(), operation_, result); |
| + if (entry_->net_log().IsLoggingAllEvents()) |
| + LogChildOperationEnd(result); |
| if (result < 0) { |
| // We fail the whole operation if we encounter an error. |
| result_ = result; |
| @@ -784,8 +789,10 @@ |
| // We'll return the current result of the operation, which may be less than |
| // the bytes to read or write, but the user cancelled the operation. |
| abort_ = false; |
| - entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); |
| - entry_->net_log().EndEvent(net::NetLog::TYPE_SPARSE_CONTROL, NULL); |
| + if (entry_->net_log().IsLoggingAllEvents()) { |
| + entry_->net_log().AddEvent(net::NetLog::TYPE_CANCELLED, NULL); |
| + entry_->net_log().EndEvent(GetSparseEventType(operation_), NULL); |
| + } |
| DoUserCallback(); |
| return DoAbortCallbacks(); |
| } |
| @@ -819,4 +826,22 @@ |
| } |
| } |
| +void SparseControl::LogChildOperationEnd(int result) { |
| + net::NetLog::EventType event_type; |
| + switch (operation_) { |
| + case disk_cache::SparseControl::kReadOperation: |
| + event_type = net::NetLog::TYPE_SPARSE_READ_CHILD_DATA; |
| + break; |
| + case disk_cache::SparseControl::kWriteOperation: |
| + event_type = net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA; |
| + break; |
| + case disk_cache::SparseControl::kGetRangeOperation: |
| + return; |
| + default: |
| + NOTREACHED(); |
| + return; |
| + } |
| + entry_->net_log().EndEventWithNetErrorCode(event_type, result); |
| +} |
| + |
| } // namespace disk_cache |