| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 std::unique_ptr<base::Value> headers_param( | 52 std::unique_ptr<base::Value> headers_param( |
| 53 headers->NetLogCallback(&empty, capture_mode)); | 53 headers->NetLogCallback(&empty, capture_mode)); |
| 54 dict->Set("headers", std::move(headers_param)); | 54 dict->Set("headers", std::move(headers_param)); |
| 55 return std::move(dict); | 55 return std::move(dict); |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 BidirectionalStream::Delegate::Delegate() {} | 60 BidirectionalStream::Delegate::Delegate() {} |
| 61 | 61 |
| 62 void BidirectionalStream::Delegate::OnStreamReady() {} | |
| 63 | |
| 64 BidirectionalStream::Delegate::~Delegate() {} | 62 BidirectionalStream::Delegate::~Delegate() {} |
| 65 | 63 |
| 66 BidirectionalStream::BidirectionalStream( | 64 BidirectionalStream::BidirectionalStream( |
| 67 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, | 65 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, |
| 68 HttpNetworkSession* session, | 66 HttpNetworkSession* session, |
| 69 bool disable_auto_flush, | 67 bool send_request_headers_automatically, |
| 70 Delegate* delegate) | 68 Delegate* delegate) |
| 71 : BidirectionalStream(std::move(request_info), | 69 : BidirectionalStream(std::move(request_info), |
| 72 session, | 70 session, |
| 73 disable_auto_flush, | 71 send_request_headers_automatically, |
| 74 delegate, | 72 delegate, |
| 75 base::WrapUnique(new base::Timer(false, false))) {} | 73 base::WrapUnique(new base::Timer(false, false))) {} |
| 76 | 74 |
| 77 BidirectionalStream::BidirectionalStream( | 75 BidirectionalStream::BidirectionalStream( |
| 78 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, | 76 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, |
| 79 HttpNetworkSession* session, | 77 HttpNetworkSession* session, |
| 80 bool disable_auto_flush, | 78 bool send_request_headers_automatically, |
| 81 Delegate* delegate, | 79 Delegate* delegate, |
| 82 std::unique_ptr<base::Timer> timer) | 80 std::unique_ptr<base::Timer> timer) |
| 83 : request_info_(std::move(request_info)), | 81 : request_info_(std::move(request_info)), |
| 84 net_log_(BoundNetLog::Make(session->net_log(), | 82 net_log_(BoundNetLog::Make(session->net_log(), |
| 85 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), | 83 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), |
| 86 session_(session), | 84 session_(session), |
| 87 disable_auto_flush_(disable_auto_flush), | 85 send_request_headers_automatically_(send_request_headers_automatically), |
| 86 request_headers_sent_(false), |
| 88 delegate_(delegate), | 87 delegate_(delegate), |
| 89 timer_(std::move(timer)) { | 88 timer_(std::move(timer)) { |
| 90 DCHECK(delegate_); | 89 DCHECK(delegate_); |
| 91 DCHECK(request_info_); | 90 DCHECK(request_info_); |
| 92 | 91 |
| 93 SSLConfig server_ssl_config; | 92 SSLConfig server_ssl_config; |
| 94 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); | 93 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); |
| 95 session->GetAlpnProtos(&server_ssl_config.alpn_protos); | 94 session->GetAlpnProtos(&server_ssl_config.alpn_protos); |
| 96 session->GetNpnProtos(&server_ssl_config.npn_protos); | 95 session->GetNpnProtos(&server_ssl_config.npn_protos); |
| 97 | 96 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 124 } | 123 } |
| 125 } | 124 } |
| 126 | 125 |
| 127 BidirectionalStream::~BidirectionalStream() { | 126 BidirectionalStream::~BidirectionalStream() { |
| 128 Cancel(); | 127 Cancel(); |
| 129 if (net_log_.IsCapturing()) { | 128 if (net_log_.IsCapturing()) { |
| 130 net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE); | 129 net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE); |
| 131 } | 130 } |
| 132 } | 131 } |
| 133 | 132 |
| 133 void BidirectionalStream::SendRequestHeaders() { |
| 134 DCHECK(stream_impl_); |
| 135 DCHECK(!request_headers_sent_); |
| 136 DCHECK(!send_request_headers_automatically_); |
| 137 |
| 138 stream_impl_->SendRequestHeaders(); |
| 139 } |
| 140 |
| 134 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { | 141 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { |
| 135 DCHECK(stream_impl_); | 142 DCHECK(stream_impl_); |
| 136 | 143 |
| 137 int rv = stream_impl_->ReadData(buf, buf_len); | 144 int rv = stream_impl_->ReadData(buf, buf_len); |
| 138 if (rv > 0) { | 145 if (rv > 0) { |
| 139 net_log_.AddByteTransferEvent( | 146 net_log_.AddByteTransferEvent( |
| 140 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data()); | 147 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data()); |
| 141 } else if (rv == ERR_IO_PENDING) { | 148 } else if (rv == ERR_IO_PENDING) { |
| 142 read_buffer_ = buf; | 149 read_buffer_ = buf; |
| 143 // Bytes will be logged in OnDataRead(). | 150 // Bytes will be logged in OnDataRead(). |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return stream_impl_->GetTotalReceivedBytes(); | 202 return stream_impl_->GetTotalReceivedBytes(); |
| 196 } | 203 } |
| 197 | 204 |
| 198 int64_t BidirectionalStream::GetTotalSentBytes() const { | 205 int64_t BidirectionalStream::GetTotalSentBytes() const { |
| 199 if (!stream_impl_) | 206 if (!stream_impl_) |
| 200 return 0; | 207 return 0; |
| 201 | 208 |
| 202 return stream_impl_->GetTotalSentBytes(); | 209 return stream_impl_->GetTotalSentBytes(); |
| 203 } | 210 } |
| 204 | 211 |
| 205 void BidirectionalStream::OnStreamReady() { | 212 void BidirectionalStream::OnStreamReady(bool request_headers_sent) { |
| 206 delegate_->OnStreamReady(); | 213 request_headers_sent_ = request_headers_sent; |
| 214 delegate_->OnStreamReady(request_headers_sent); |
| 207 } | 215 } |
| 208 | 216 |
| 209 void BidirectionalStream::OnHeadersReceived( | 217 void BidirectionalStream::OnHeadersReceived( |
| 210 const SpdyHeaderBlock& response_headers) { | 218 const SpdyHeaderBlock& response_headers) { |
| 211 HttpResponseInfo response_info; | 219 HttpResponseInfo response_info; |
| 212 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { | 220 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { |
| 213 DLOG(WARNING) << "Invalid headers"; | 221 DLOG(WARNING) << "Invalid headers"; |
| 214 delegate_->OnFailed(ERR_FAILED); | 222 delegate_->OnFailed(ERR_FAILED); |
| 215 return; | 223 return; |
| 216 } | 224 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 279 } |
| 272 | 280 |
| 273 void BidirectionalStream::OnBidirectionalStreamImplReady( | 281 void BidirectionalStream::OnBidirectionalStreamImplReady( |
| 274 const SSLConfig& used_ssl_config, | 282 const SSLConfig& used_ssl_config, |
| 275 const ProxyInfo& used_proxy_info, | 283 const ProxyInfo& used_proxy_info, |
| 276 BidirectionalStreamImpl* stream) { | 284 BidirectionalStreamImpl* stream) { |
| 277 DCHECK(!stream_impl_); | 285 DCHECK(!stream_impl_); |
| 278 | 286 |
| 279 stream_request_.reset(); | 287 stream_request_.reset(); |
| 280 stream_impl_.reset(stream); | 288 stream_impl_.reset(stream); |
| 281 stream_impl_->Start(request_info_.get(), net_log_, disable_auto_flush_, this, | 289 stream_impl_->Start(request_info_.get(), net_log_, |
| 290 send_request_headers_automatically_, this, |
| 282 std::move(timer_)); | 291 std::move(timer_)); |
| 283 } | 292 } |
| 284 | 293 |
| 285 void BidirectionalStream::OnWebSocketHandshakeStreamReady( | 294 void BidirectionalStream::OnWebSocketHandshakeStreamReady( |
| 286 const SSLConfig& used_ssl_config, | 295 const SSLConfig& used_ssl_config, |
| 287 const ProxyInfo& used_proxy_info, | 296 const ProxyInfo& used_proxy_info, |
| 288 WebSocketHandshakeStreamBase* stream) { | 297 WebSocketHandshakeStreamBase* stream) { |
| 289 NOTREACHED(); | 298 NOTREACHED(); |
| 290 } | 299 } |
| 291 | 300 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 const ProxyInfo& used_proxy_info, | 341 const ProxyInfo& used_proxy_info, |
| 333 HttpStream* stream) { | 342 HttpStream* stream) { |
| 334 DCHECK(stream_request_); | 343 DCHECK(stream_request_); |
| 335 | 344 |
| 336 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); | 345 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); |
| 337 } | 346 } |
| 338 | 347 |
| 339 void BidirectionalStream::OnQuicBroken() {} | 348 void BidirectionalStream::OnQuicBroken() {} |
| 340 | 349 |
| 341 } // namespace net | 350 } // namespace net |
| OLD | NEW |