Chromium Code Reviews| Index: net/http/bidirectional_stream.cc |
| diff --git a/net/http/bidirectional_stream.cc b/net/http/bidirectional_stream.cc |
| index 5c04ca3c2e5b5dff861a5e16a80ebfc05707b695..891d3160215edca6d5d715a7d61a794b8fb39e59 100644 |
| --- a/net/http/bidirectional_stream.cc |
| +++ b/net/http/bidirectional_stream.cc |
| @@ -47,7 +47,8 @@ BidirectionalStream::BidirectionalStream( |
| NetLog::SOURCE_BIDIRECTIONAL_STREAM)), |
| session_(session), |
| delegate_(delegate), |
| - timer_(std::move(timer)) { |
| + timer_(std::move(timer)), |
| + write_buffer_len_(0) { |
| DCHECK(delegate_); |
| DCHECK(request_info_); |
| @@ -86,7 +87,15 @@ BidirectionalStream::~BidirectionalStream() { |
| int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { |
| DCHECK(stream_impl_); |
| - return stream_impl_->ReadData(buf, buf_len); |
| + int rv = stream_impl_->ReadData(buf, buf_len); |
| + if (rv > 0) { |
| + net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, |
| + buf->data()); |
| + } else if (rv == ERR_IO_PENDING) { |
| + read_buffer_ = buf; |
| + // Bytes will be logged in OnDataRead(). |
| + } |
| + return rv; |
| } |
| void BidirectionalStream::SendData(IOBuffer* data, |
| @@ -95,6 +104,8 @@ void BidirectionalStream::SendData(IOBuffer* data, |
| DCHECK(stream_impl_); |
| stream_impl_->SendData(data, length, end_stream); |
| + write_buffer_ = data; |
| + write_buffer_len_ = length; |
| } |
| void BidirectionalStream::Cancel() { |
| @@ -146,10 +157,21 @@ void BidirectionalStream::OnHeadersReceived( |
| } |
| void BidirectionalStream::OnDataRead(int bytes_read) { |
| + DCHECK(read_buffer_); |
| + |
| + net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, bytes_read, |
|
mmenke
2016/04/13 18:03:50
TYPE_SOCKET_BYTES_SENT is used for bytes sent at t
xunjieli
2016/04/13 18:16:03
Done.
|
| + read_buffer_->data()); |
| + read_buffer_ = nullptr; |
| delegate_->OnDataRead(bytes_read); |
| } |
| void BidirectionalStream::OnDataSent() { |
| + DCHECK(write_buffer_); |
| + |
| + net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, |
| + write_buffer_len_, write_buffer_->data()); |
| + write_buffer_ = nullptr; |
| + write_buffer_len_ = 0; |
| delegate_->OnDataSent(); |
| } |