| OLD | NEW |
| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 NetLogSourceType::BIDIRECTIONAL_STREAM)), | 85 NetLogSourceType::BIDIRECTIONAL_STREAM)), |
| 86 session_(session), | 86 session_(session), |
| 87 send_request_headers_automatically_(send_request_headers_automatically), | 87 send_request_headers_automatically_(send_request_headers_automatically), |
| 88 request_headers_sent_(false), | 88 request_headers_sent_(false), |
| 89 delegate_(delegate), | 89 delegate_(delegate), |
| 90 timer_(std::move(timer)), | 90 timer_(std::move(timer)), |
| 91 weak_factory_(this) { | 91 weak_factory_(this) { |
| 92 DCHECK(delegate_); | 92 DCHECK(delegate_); |
| 93 DCHECK(request_info_); | 93 DCHECK(request_info_); |
| 94 | 94 |
| 95 // Start time should be measured before connect. |
| 96 load_timing_info_.request_start_time = base::Time::Now(); |
| 97 load_timing_info_.request_start = base::TimeTicks::Now(); |
| 98 |
| 95 if (net_log_.IsCapturing()) { | 99 if (net_log_.IsCapturing()) { |
| 96 net_log_.BeginEvent( | 100 net_log_.BeginEvent( |
| 97 NetLogEventType::BIDIRECTIONAL_STREAM_ALIVE, | 101 NetLogEventType::BIDIRECTIONAL_STREAM_ALIVE, |
| 98 base::Bind(&NetLogCallback, &request_info_->url, &request_info_->method, | 102 base::Bind(&NetLogCallback, &request_info_->url, &request_info_->method, |
| 99 base::Unretained(&request_info_->extra_headers))); | 103 base::Unretained(&request_info_->extra_headers))); |
| 100 } | 104 } |
| 101 | 105 |
| 102 SSLConfig server_ssl_config; | 106 SSLConfig server_ssl_config; |
| 103 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); | 107 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); |
| 104 session->GetAlpnProtos(&server_ssl_config.alpn_protos); | 108 session->GetAlpnProtos(&server_ssl_config.alpn_protos); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return stream_impl_->GetTotalReceivedBytes(); | 213 return stream_impl_->GetTotalReceivedBytes(); |
| 210 } | 214 } |
| 211 | 215 |
| 212 int64_t BidirectionalStream::GetTotalSentBytes() const { | 216 int64_t BidirectionalStream::GetTotalSentBytes() const { |
| 213 if (!stream_impl_) | 217 if (!stream_impl_) |
| 214 return 0; | 218 return 0; |
| 215 | 219 |
| 216 return stream_impl_->GetTotalSentBytes(); | 220 return stream_impl_->GetTotalSentBytes(); |
| 217 } | 221 } |
| 218 | 222 |
| 223 void BidirectionalStream::GetLoadTimingInfo( |
| 224 LoadTimingInfo* load_timing_info) const { |
| 225 *load_timing_info = load_timing_info_; |
| 226 } |
| 227 |
| 219 void BidirectionalStream::OnStreamReady(bool request_headers_sent) { | 228 void BidirectionalStream::OnStreamReady(bool request_headers_sent) { |
| 220 request_headers_sent_ = request_headers_sent; | 229 request_headers_sent_ = request_headers_sent; |
| 221 if (net_log_.IsCapturing()) { | 230 if (net_log_.IsCapturing()) { |
| 222 net_log_.AddEvent( | 231 net_log_.AddEvent( |
| 223 NetLogEventType::BIDIRECTIONAL_STREAM_READY, | 232 NetLogEventType::BIDIRECTIONAL_STREAM_READY, |
| 224 NetLog::BoolCallback("request_headers_sent", request_headers_sent)); | 233 NetLog::BoolCallback("request_headers_sent", request_headers_sent)); |
| 225 } | 234 } |
| 226 send_start_time_ = base::TimeTicks::Now(); | 235 load_timing_info_.send_start = base::TimeTicks::Now(); |
| 227 send_end_time_ = send_start_time_; | 236 load_timing_info_.send_end = load_timing_info_.send_start; |
| 228 delegate_->OnStreamReady(request_headers_sent); | 237 delegate_->OnStreamReady(request_headers_sent); |
| 229 } | 238 } |
| 230 | 239 |
| 231 void BidirectionalStream::OnHeadersReceived( | 240 void BidirectionalStream::OnHeadersReceived( |
| 232 const SpdyHeaderBlock& response_headers) { | 241 const SpdyHeaderBlock& response_headers) { |
| 233 HttpResponseInfo response_info; | 242 HttpResponseInfo response_info; |
| 234 if (!SpdyHeadersToHttpResponse(response_headers, &response_info)) { | 243 if (!SpdyHeadersToHttpResponse(response_headers, &response_info)) { |
| 235 DLOG(WARNING) << "Invalid headers"; | 244 DLOG(WARNING) << "Invalid headers"; |
| 236 NotifyFailed(ERR_FAILED); | 245 NotifyFailed(ERR_FAILED); |
| 237 return; | 246 return; |
| 238 } | 247 } |
| 239 if (net_log_.IsCapturing()) { | 248 if (net_log_.IsCapturing()) { |
| 240 net_log_.AddEvent(NetLogEventType::BIDIRECTIONAL_STREAM_RECV_HEADERS, | 249 net_log_.AddEvent(NetLogEventType::BIDIRECTIONAL_STREAM_RECV_HEADERS, |
| 241 base::Bind(&NetLogHeadersCallback, &response_headers)); | 250 base::Bind(&NetLogHeadersCallback, &response_headers)); |
| 242 } | 251 } |
| 243 read_start_time_ = base::TimeTicks::Now(); | 252 // Impl should only provide |connect_timing| and |socket_reused| info, |
| 244 read_end_time_ = read_start_time_; | 253 // so use a copy to get these information only. |
| 254 LoadTimingInfo impl_load_timing_info; |
| 255 bool has_load_timing = |
| 256 stream_impl_->GetLoadTimingInfo(&impl_load_timing_info); |
| 257 if (has_load_timing) { |
| 258 load_timing_info_.connect_timing = impl_load_timing_info.connect_timing; |
| 259 load_timing_info_.socket_reused = impl_load_timing_info.socket_reused; |
| 260 } |
| 261 load_timing_info_.receive_headers_end = base::TimeTicks::Now(); |
| 262 read_end_time_ = load_timing_info_.receive_headers_end; |
| 245 session_->http_stream_factory()->ProcessAlternativeServices( | 263 session_->http_stream_factory()->ProcessAlternativeServices( |
| 246 session_, response_info.headers.get(), | 264 session_, response_info.headers.get(), |
| 247 url::SchemeHostPort(request_info_->url)); | 265 url::SchemeHostPort(request_info_->url)); |
| 248 delegate_->OnHeadersReceived(response_headers); | 266 delegate_->OnHeadersReceived(response_headers); |
| 249 } | 267 } |
| 250 | 268 |
| 251 void BidirectionalStream::OnDataRead(int bytes_read) { | 269 void BidirectionalStream::OnDataRead(int bytes_read) { |
| 252 DCHECK(read_buffer_); | 270 DCHECK(read_buffer_); |
| 253 | 271 |
| 254 if (net_log_.IsCapturing()) { | 272 if (net_log_.IsCapturing()) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 275 for (size_t i = 0; i < write_buffer_list_.size(); ++i) { | 293 for (size_t i = 0; i < write_buffer_list_.size(); ++i) { |
| 276 net_log_.AddByteTransferEvent( | 294 net_log_.AddByteTransferEvent( |
| 277 NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT, | 295 NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT, |
| 278 write_buffer_len_list_[i], write_buffer_list_[i]->data()); | 296 write_buffer_len_list_[i], write_buffer_list_[i]->data()); |
| 279 } | 297 } |
| 280 if (write_buffer_list_.size() > 1) { | 298 if (write_buffer_list_.size() > 1) { |
| 281 net_log_.EndEvent( | 299 net_log_.EndEvent( |
| 282 NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT_COALESCED); | 300 NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT_COALESCED); |
| 283 } | 301 } |
| 284 } | 302 } |
| 285 send_end_time_ = base::TimeTicks::Now(); | 303 load_timing_info_.send_end = base::TimeTicks::Now(); |
| 286 write_buffer_list_.clear(); | 304 write_buffer_list_.clear(); |
| 287 write_buffer_len_list_.clear(); | 305 write_buffer_len_list_.clear(); |
| 288 delegate_->OnDataSent(); | 306 delegate_->OnDataSent(); |
| 289 } | 307 } |
| 290 | 308 |
| 291 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { | 309 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { |
| 292 if (net_log_.IsCapturing()) { | 310 if (net_log_.IsCapturing()) { |
| 293 net_log_.AddEvent(NetLogEventType::BIDIRECTIONAL_STREAM_RECV_TRAILERS, | 311 net_log_.AddEvent(NetLogEventType::BIDIRECTIONAL_STREAM_RECV_TRAILERS, |
| 294 base::Bind(&NetLogHeadersCallback, &trailers)); | 312 base::Bind(&NetLogHeadersCallback, &trailers)); |
| 295 } | 313 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 310 HttpStream* stream) { | 328 HttpStream* stream) { |
| 311 NOTREACHED(); | 329 NOTREACHED(); |
| 312 } | 330 } |
| 313 | 331 |
| 314 void BidirectionalStream::OnBidirectionalStreamImplReady( | 332 void BidirectionalStream::OnBidirectionalStreamImplReady( |
| 315 const SSLConfig& used_ssl_config, | 333 const SSLConfig& used_ssl_config, |
| 316 const ProxyInfo& used_proxy_info, | 334 const ProxyInfo& used_proxy_info, |
| 317 BidirectionalStreamImpl* stream) { | 335 BidirectionalStreamImpl* stream) { |
| 318 DCHECK(!stream_impl_); | 336 DCHECK(!stream_impl_); |
| 319 | 337 |
| 320 start_time_ = base::TimeTicks::Now(); | |
| 321 stream_request_.reset(); | 338 stream_request_.reset(); |
| 322 stream_impl_.reset(stream); | 339 stream_impl_.reset(stream); |
| 323 stream_impl_->Start(request_info_.get(), net_log_, | 340 stream_impl_->Start(request_info_.get(), net_log_, |
| 324 send_request_headers_automatically_, this, | 341 send_request_headers_automatically_, this, |
| 325 std::move(timer_)); | 342 std::move(timer_)); |
| 326 } | 343 } |
| 327 | 344 |
| 328 void BidirectionalStream::OnWebSocketHandshakeStreamReady( | 345 void BidirectionalStream::OnWebSocketHandshakeStreamReady( |
| 329 const SSLConfig& used_ssl_config, | 346 const SSLConfig& used_ssl_config, |
| 330 const ProxyInfo& used_proxy_info, | 347 const ProxyInfo& used_proxy_info, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 397 |
| 381 void BidirectionalStream::OnQuicBroken() {} | 398 void BidirectionalStream::OnQuicBroken() {} |
| 382 | 399 |
| 383 void BidirectionalStream::NotifyFailed(int error) { | 400 void BidirectionalStream::NotifyFailed(int error) { |
| 384 delegate_->OnFailed(error); | 401 delegate_->OnFailed(error); |
| 385 } | 402 } |
| 386 | 403 |
| 387 void BidirectionalStream::UpdateHistograms() { | 404 void BidirectionalStream::UpdateHistograms() { |
| 388 // If the request failed before response is started, treat the metrics as | 405 // If the request failed before response is started, treat the metrics as |
| 389 // bogus and skip logging. | 406 // bogus and skip logging. |
| 390 if (start_time_.is_null() || read_start_time_.is_null() || | 407 if (load_timing_info_.request_start.is_null() || |
| 391 read_end_time_.is_null() || send_start_time_.is_null() || | 408 load_timing_info_.receive_headers_end.is_null() || |
| 392 send_end_time_.is_null()) { | 409 read_end_time_.is_null() || load_timing_info_.send_start.is_null() || |
| 410 load_timing_info_.send_end.is_null()) { |
| 393 return; | 411 return; |
| 394 } | 412 } |
| 395 if (GetProtocol() == kProtoHTTP2) { | 413 if (GetProtocol() == kProtoHTTP2) { |
| 396 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadStart.HTTP2", | 414 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadStart.HTTP2", |
| 397 read_start_time_ - start_time_); | 415 load_timing_info_.receive_headers_end - |
| 416 load_timing_info_.request_start); |
| 398 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadEnd.HTTP2", | 417 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadEnd.HTTP2", |
| 399 read_end_time_ - start_time_); | 418 read_end_time_ - load_timing_info_.request_start); |
| 400 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToSendStart.HTTP2", | 419 UMA_HISTOGRAM_TIMES( |
| 401 send_start_time_ - start_time_); | 420 "Net.BidirectionalStream.TimeToSendStart.HTTP2", |
| 402 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToSendEnd.HTTP2", | 421 load_timing_info_.send_start - load_timing_info_.request_start); |
| 403 send_end_time_ - start_time_); | 422 UMA_HISTOGRAM_TIMES( |
| 423 "Net.BidirectionalStream.TimeToSendEnd.HTTP2", |
| 424 load_timing_info_.send_end - load_timing_info_.request_start); |
| 404 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.ReceivedBytes.HTTP2", | 425 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.ReceivedBytes.HTTP2", |
| 405 stream_impl_->GetTotalReceivedBytes()); | 426 stream_impl_->GetTotalReceivedBytes()); |
| 406 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.SentBytes.HTTP2", | 427 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.SentBytes.HTTP2", |
| 407 stream_impl_->GetTotalSentBytes()); | 428 stream_impl_->GetTotalSentBytes()); |
| 408 } else if (GetProtocol() == kProtoQUIC1SPDY3) { | 429 } else if (GetProtocol() == kProtoQUIC1SPDY3) { |
| 409 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadStart.QUIC", | 430 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadStart.QUIC", |
| 410 read_start_time_ - start_time_); | 431 load_timing_info_.receive_headers_end - |
| 432 load_timing_info_.request_start); |
| 411 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadEnd.QUIC", | 433 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToReadEnd.QUIC", |
| 412 read_end_time_ - start_time_); | 434 read_end_time_ - load_timing_info_.request_start); |
| 413 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToSendStart.QUIC", | 435 UMA_HISTOGRAM_TIMES( |
| 414 send_start_time_ - start_time_); | 436 "Net.BidirectionalStream.TimeToSendStart.QUIC", |
| 415 UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.TimeToSendEnd.QUIC", | 437 load_timing_info_.send_start - load_timing_info_.request_start); |
| 416 send_end_time_ - start_time_); | 438 UMA_HISTOGRAM_TIMES( |
| 439 "Net.BidirectionalStream.TimeToSendEnd.QUIC", |
| 440 load_timing_info_.send_end - load_timing_info_.request_start); |
| 417 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.ReceivedBytes.QUIC", | 441 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.ReceivedBytes.QUIC", |
| 418 stream_impl_->GetTotalReceivedBytes()); | 442 stream_impl_->GetTotalReceivedBytes()); |
| 419 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.SentBytes.QUIC", | 443 UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.SentBytes.QUIC", |
| 420 stream_impl_->GetTotalSentBytes()); | 444 stream_impl_->GetTotalSentBytes()); |
| 421 } | 445 } |
| 422 } | 446 } |
| 423 | 447 |
| 424 } // namespace net | 448 } // namespace net |
| OLD | NEW |