| 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), |
| 88 delegate_(delegate), | 86 delegate_(delegate), |
| 89 timer_(std::move(timer)) { | 87 timer_(std::move(timer)) { |
| 90 DCHECK(delegate_); | 88 DCHECK(delegate_); |
| 91 DCHECK(request_info_); | 89 DCHECK(request_info_); |
| 92 | 90 |
| 93 SSLConfig server_ssl_config; | 91 SSLConfig server_ssl_config; |
| 94 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); | 92 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); |
| 95 session->GetAlpnProtos(&server_ssl_config.alpn_protos); | 93 session->GetAlpnProtos(&server_ssl_config.alpn_protos); |
| 96 session->GetNpnProtos(&server_ssl_config.npn_protos); | 94 session->GetNpnProtos(&server_ssl_config.npn_protos); |
| 97 | 95 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 124 } | 122 } |
| 125 } | 123 } |
| 126 | 124 |
| 127 BidirectionalStream::~BidirectionalStream() { | 125 BidirectionalStream::~BidirectionalStream() { |
| 128 Cancel(); | 126 Cancel(); |
| 129 if (net_log_.IsCapturing()) { | 127 if (net_log_.IsCapturing()) { |
| 130 net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE); | 128 net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE); |
| 131 } | 129 } |
| 132 } | 130 } |
| 133 | 131 |
| 132 void BidirectionalStream::SendRequestHeaders() { |
| 133 DCHECK(stream_impl_); |
| 134 stream_impl_->SendRequestHeaders(); |
| 135 } |
| 136 |
| 134 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { | 137 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { |
| 135 DCHECK(stream_impl_); | 138 DCHECK(stream_impl_); |
| 136 | 139 |
| 137 int rv = stream_impl_->ReadData(buf, buf_len); | 140 int rv = stream_impl_->ReadData(buf, buf_len); |
| 138 if (rv > 0) { | 141 if (rv > 0) { |
| 139 net_log_.AddByteTransferEvent( | 142 net_log_.AddByteTransferEvent( |
| 140 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data()); | 143 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data()); |
| 141 } else if (rv == ERR_IO_PENDING) { | 144 } else if (rv == ERR_IO_PENDING) { |
| 142 read_buffer_ = buf; | 145 read_buffer_ = buf; |
| 143 // Bytes will be logged in OnDataRead(). | 146 // Bytes will be logged in OnDataRead(). |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return stream_impl_->GetTotalReceivedBytes(); | 198 return stream_impl_->GetTotalReceivedBytes(); |
| 196 } | 199 } |
| 197 | 200 |
| 198 int64_t BidirectionalStream::GetTotalSentBytes() const { | 201 int64_t BidirectionalStream::GetTotalSentBytes() const { |
| 199 if (!stream_impl_) | 202 if (!stream_impl_) |
| 200 return 0; | 203 return 0; |
| 201 | 204 |
| 202 return stream_impl_->GetTotalSentBytes(); | 205 return stream_impl_->GetTotalSentBytes(); |
| 203 } | 206 } |
| 204 | 207 |
| 205 void BidirectionalStream::OnStreamReady() { | 208 void BidirectionalStream::OnStreamReady(bool request_headers_sent) { |
| 206 delegate_->OnStreamReady(); | 209 delegate_->OnStreamReady(request_headers_sent); |
| 207 } | 210 } |
| 208 | 211 |
| 209 void BidirectionalStream::OnHeadersReceived( | 212 void BidirectionalStream::OnHeadersReceived( |
| 210 const SpdyHeaderBlock& response_headers) { | 213 const SpdyHeaderBlock& response_headers) { |
| 211 HttpResponseInfo response_info; | 214 HttpResponseInfo response_info; |
| 212 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { | 215 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { |
| 213 DLOG(WARNING) << "Invalid headers"; | 216 DLOG(WARNING) << "Invalid headers"; |
| 214 delegate_->OnFailed(ERR_FAILED); | 217 delegate_->OnFailed(ERR_FAILED); |
| 215 return; | 218 return; |
| 216 } | 219 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 274 } |
| 272 | 275 |
| 273 void BidirectionalStream::OnBidirectionalStreamImplReady( | 276 void BidirectionalStream::OnBidirectionalStreamImplReady( |
| 274 const SSLConfig& used_ssl_config, | 277 const SSLConfig& used_ssl_config, |
| 275 const ProxyInfo& used_proxy_info, | 278 const ProxyInfo& used_proxy_info, |
| 276 BidirectionalStreamImpl* stream) { | 279 BidirectionalStreamImpl* stream) { |
| 277 DCHECK(!stream_impl_); | 280 DCHECK(!stream_impl_); |
| 278 | 281 |
| 279 stream_request_.reset(); | 282 stream_request_.reset(); |
| 280 stream_impl_.reset(stream); | 283 stream_impl_.reset(stream); |
| 281 stream_impl_->Start(request_info_.get(), net_log_, disable_auto_flush_, this, | 284 stream_impl_->Start(request_info_.get(), net_log_, |
| 285 send_request_headers_automatically_, this, |
| 282 std::move(timer_)); | 286 std::move(timer_)); |
| 283 } | 287 } |
| 284 | 288 |
| 285 void BidirectionalStream::OnWebSocketHandshakeStreamReady( | 289 void BidirectionalStream::OnWebSocketHandshakeStreamReady( |
| 286 const SSLConfig& used_ssl_config, | 290 const SSLConfig& used_ssl_config, |
| 287 const ProxyInfo& used_proxy_info, | 291 const ProxyInfo& used_proxy_info, |
| 288 WebSocketHandshakeStreamBase* stream) { | 292 WebSocketHandshakeStreamBase* stream) { |
| 289 NOTREACHED(); | 293 NOTREACHED(); |
| 290 } | 294 } |
| 291 | 295 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 const ProxyInfo& used_proxy_info, | 336 const ProxyInfo& used_proxy_info, |
| 333 HttpStream* stream) { | 337 HttpStream* stream) { |
| 334 DCHECK(stream_request_); | 338 DCHECK(stream_request_); |
| 335 | 339 |
| 336 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); | 340 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); |
| 337 } | 341 } |
| 338 | 342 |
| 339 void BidirectionalStream::OnQuicBroken() {} | 343 void BidirectionalStream::OnQuicBroken() {} |
| 340 | 344 |
| 341 } // namespace net | 345 } // namespace net |
| OLD | NEW |