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

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: Address comments 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(
93 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, 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(
163 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, bytes_read,
164 read_buffer_->data());
165 read_buffer_ = nullptr;
149 delegate_->OnDataRead(bytes_read); 166 delegate_->OnDataRead(bytes_read);
150 } 167 }
151 168
152 void BidirectionalStream::OnDataSent() { 169 void BidirectionalStream::OnDataSent() {
170 DCHECK(write_buffer_);
171
172 net_log_.AddByteTransferEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT,
173 write_buffer_len_, write_buffer_->data());
174 write_buffer_ = nullptr;
175 write_buffer_len_ = 0;
153 delegate_->OnDataSent(); 176 delegate_->OnDataSent();
154 } 177 }
155 178
156 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { 179 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) {
157 delegate_->OnTrailersReceived(trailers); 180 delegate_->OnTrailersReceived(trailers);
158 } 181 }
159 182
160 void BidirectionalStream::OnFailed(int status) { 183 void BidirectionalStream::OnFailed(int status) {
161 delegate_->OnFailed(status); 184 delegate_->OnFailed(status);
162 } 185 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 const ProxyInfo& used_proxy_info, 251 const ProxyInfo& used_proxy_info,
229 HttpStream* stream) { 252 HttpStream* stream) {
230 DCHECK(stream_request_); 253 DCHECK(stream_request_);
231 254
232 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); 255 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
233 } 256 }
234 257
235 void BidirectionalStream::OnQuicBroken() {} 258 void BidirectionalStream::OnQuicBroken() {}
236 259
237 } // namespace net 260 } // 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