Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: net/http/bidirectional_stream.cc

Issue 1883883002: Log sent and received bytes in net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/bidirectional_stream.h ('k') | net/http/bidirectional_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/http/bidirectional_stream.h" 5 #include "net/http/bidirectional_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 29 matching lines...) Expand all
40 BidirectionalStream::BidirectionalStream( 40 BidirectionalStream::BidirectionalStream(
41 scoped_ptr<BidirectionalStreamRequestInfo> request_info, 41 scoped_ptr<BidirectionalStreamRequestInfo> request_info,
42 HttpNetworkSession* session, 42 HttpNetworkSession* session,
43 Delegate* delegate, 43 Delegate* delegate,
44 scoped_ptr<base::Timer> timer) 44 scoped_ptr<base::Timer> timer)
45 : request_info_(std::move(request_info)), 45 : request_info_(std::move(request_info)),
46 net_log_(BoundNetLog::Make(session->net_log(), 46 net_log_(BoundNetLog::Make(session->net_log(),
47 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), 47 NetLog::SOURCE_BIDIRECTIONAL_STREAM)),
48 session_(session), 48 session_(session),
49 delegate_(delegate), 49 delegate_(delegate),
50 timer_(std::move(timer)) { 50 timer_(std::move(timer)),
51 write_buffer_len_(0) {
51 DCHECK(delegate_); 52 DCHECK(delegate_);
52 DCHECK(request_info_); 53 DCHECK(request_info_);
53 54
54 SSLConfig server_ssl_config; 55 SSLConfig server_ssl_config;
55 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); 56 session->ssl_config_service()->GetSSLConfig(&server_ssl_config);
56 session->GetAlpnProtos(&server_ssl_config.alpn_protos); 57 session->GetAlpnProtos(&server_ssl_config.alpn_protos);
57 session->GetNpnProtos(&server_ssl_config.npn_protos); 58 session->GetNpnProtos(&server_ssl_config.npn_protos);
58 59
59 if (!request_info_->url.SchemeIs(url::kHttpsScheme)) { 60 if (!request_info_->url.SchemeIs(url::kHttpsScheme)) {
60 base::ThreadTaskRunnerHandle::Get()->PostTask( 61 base::ThreadTaskRunnerHandle::Get()->PostTask(
(...skipping 18 matching lines...) Expand all
79 DCHECK(!stream_impl_); 80 DCHECK(!stream_impl_);
80 } 81 }
81 82
82 BidirectionalStream::~BidirectionalStream() { 83 BidirectionalStream::~BidirectionalStream() {
83 Cancel(); 84 Cancel();
84 } 85 }
85 86
86 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { 87 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) {
87 DCHECK(stream_impl_); 88 DCHECK(stream_impl_);
88 89
89 return stream_impl_->ReadData(buf, buf_len); 90 int rv = stream_impl_->ReadData(buf, buf_len);
91 if (rv > 0) {
92 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv,
93 buf->data());
94 } else if (rv == ERR_IO_PENDING) {
95 read_buffer_ = buf;
96 // Bytes will be logged in OnDataRead().
97 }
98 return rv;
90 } 99 }
91 100
92 void BidirectionalStream::SendData(IOBuffer* data, 101 void BidirectionalStream::SendData(IOBuffer* data,
93 int length, 102 int length,
94 bool end_stream) { 103 bool end_stream) {
95 DCHECK(stream_impl_); 104 DCHECK(stream_impl_);
96 105
97 stream_impl_->SendData(data, length, end_stream); 106 stream_impl_->SendData(data, length, end_stream);
107 write_buffer_ = data;
108 write_buffer_len_ = length;
98 } 109 }
99 110
100 void BidirectionalStream::Cancel() { 111 void BidirectionalStream::Cancel() {
101 stream_request_.reset(); 112 stream_request_.reset();
102 if (stream_impl_) { 113 if (stream_impl_) {
103 stream_impl_->Cancel(); 114 stream_impl_->Cancel();
104 stream_impl_.reset(); 115 stream_impl_.reset();
105 } 116 }
106 } 117 }
107 118
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 return; 150 return;
140 } 151 }
141 152
142 session_->http_stream_factory()->ProcessAlternativeServices( 153 session_->http_stream_factory()->ProcessAlternativeServices(
143 session_, response_info.headers.get(), 154 session_, response_info.headers.get(),
144 HostPortPair::FromURL(request_info_->url)); 155 HostPortPair::FromURL(request_info_->url));
145 delegate_->OnHeadersReceived(response_headers); 156 delegate_->OnHeadersReceived(response_headers);
146 } 157 }
147 158
148 void BidirectionalStream::OnDataRead(int bytes_read) { 159 void BidirectionalStream::OnDataRead(int bytes_read) {
160 DCHECK(read_buffer_);
161
162 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.
163 read_buffer_->data());
164 read_buffer_ = nullptr;
149 delegate_->OnDataRead(bytes_read); 165 delegate_->OnDataRead(bytes_read);
150 } 166 }
151 167
152 void BidirectionalStream::OnDataSent() { 168 void BidirectionalStream::OnDataSent() {
169 DCHECK(write_buffer_);
170
171 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT,
172 write_buffer_len_, write_buffer_->data());
173 write_buffer_ = nullptr;
174 write_buffer_len_ = 0;
153 delegate_->OnDataSent(); 175 delegate_->OnDataSent();
154 } 176 }
155 177
156 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { 178 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) {
157 delegate_->OnTrailersReceived(trailers); 179 delegate_->OnTrailersReceived(trailers);
158 } 180 }
159 181
160 void BidirectionalStream::OnFailed(int status) { 182 void BidirectionalStream::OnFailed(int status) {
161 delegate_->OnFailed(status); 183 delegate_->OnFailed(status);
162 } 184 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 const ProxyInfo& used_proxy_info, 250 const ProxyInfo& used_proxy_info,
229 HttpStream* stream) { 251 HttpStream* stream) {
230 DCHECK(stream_request_); 252 DCHECK(stream_request_);
231 253
232 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); 254 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
233 } 255 }
234 256
235 void BidirectionalStream::OnQuicBroken() {} 257 void BidirectionalStream::OnQuicBroken() {}
236 258
237 } // namespace net 259 } // namespace net
OLDNEW
« no previous file with comments | « net/http/bidirectional_stream.h ('k') | net/http/bidirectional_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698