Chromium Code Reviews| Index: net/http/bidirectional_stream.cc |
| diff --git a/net/http/bidirectional_stream.cc b/net/http/bidirectional_stream.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fb5eaf18032cab6fce17e21ffbd5cbf69d60d53e |
| --- /dev/null |
| +++ b/net/http/bidirectional_stream.cc |
| @@ -0,0 +1,208 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "net/http/bidirectional_stream.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "net/base/load_flags.h" |
| +#include "net/base/net_errors.h" |
| +#include "net/http/http_network_session.h" |
| +#include "net/http/http_stream.h" |
| +#include "net/log/net_log.h" |
| +#include "net/ssl/ssl_cert_request_info.h" |
| +#include "url/gurl.h" |
| + |
| +namespace net { |
| + |
| +BidirectionalStream::RequestInfo::RequestInfo() {} |
| + |
| +BidirectionalStream::RequestInfo::~RequestInfo() {} |
| + |
| +BidirectionalStream::BidirectionalStream(const RequestInfo& request_info, |
| + RequestPriority priority, |
| + HttpNetworkSession* session, |
| + Delegate* delegate) |
| + : request_info_(request_info), |
| + priority_(priority), |
| + net_log_(BoundNetLog::Make(session->net_log(), |
| + NetLog::SOURCE_BIDIRECTIONAL_STREAM)), |
| + delegate_(delegate) { |
| + SSLConfig server_ssl_config; |
| + session->ssl_config_service()->GetSSLConfig(&server_ssl_config); |
| + session->GetAlpnProtos(&server_ssl_config.alpn_protos); |
| + session->GetNpnProtos(&server_ssl_config.npn_protos); |
|
mmenke
2015/12/08 22:58:34
Hrm...This seems weird - the ssl_config_service on
xunjieli
2015/12/10 23:25:50
Yea. I had to find out about this in the hard way.
|
| + |
| + if (!request_info.url.SchemeIs("https")) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&Delegate::OnFailed, base::Unretained(delegate_), |
|
mmenke
2015/12/08 22:58:34
include base/bind, base/location.
xunjieli
2015/12/10 23:25:50
Done.
|
| + ERR_DISALLOWED_URL_SCHEME)); |
| + return; |
| + } |
| + |
| + HttpRequestInfo http_request_info; |
| + http_request_info.url = request_info.url; |
| + http_request_info.method = request_info.method; |
| + http_request_info.extra_headers = request_info.extra_headers; |
| + stream_request_.reset( |
| + session->http_stream_factory()->RequestBidirectionalStreamJob( |
| + http_request_info, priority_, server_ssl_config, server_ssl_config, |
| + this, net_log_)); |
|
mmenke
2015/12/08 22:58:34
Should double-check this can't fail and invoke the
xunjieli
2015/12/10 23:25:50
How do we invoke the callback synchronously? Shoul
mmenke
2015/12/11 16:42:53
Sorry, I mean should double check that no HttpStre
xunjieli
2015/12/11 23:48:39
Done.
|
| +} |
| + |
| +BidirectionalStream::~BidirectionalStream() { |
| + Cancel(); |
| +} |
| + |
| +int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { |
| + DCHECK(stream_job_); |
| + |
| + return stream_job_->ReadData(buf, buf_len); |
| +} |
| + |
| +void BidirectionalStream::SendData(IOBuffer* data, |
| + int length, |
| + bool end_stream) { |
| + DCHECK(stream_job_); |
| + |
| + stream_job_->SendData(data, length, end_stream); |
| +} |
| + |
| +void BidirectionalStream::Cancel() { |
| + if (stream_request_) |
| + stream_request_.reset(); |
| + if (stream_job_) |
| + stream_job_->Cancel(); |
| +} |
| + |
| +NextProto BidirectionalStream::GetProtocol() const { |
| + DCHECK(stream_job_); |
| + |
| + return stream_job_->GetProtocol(); |
| +} |
| + |
| +int64_t BidirectionalStream::GetTotalReceivedBytes() const { |
| + DCHECK(stream_job_); |
| + |
| + return stream_job_->GetTotalReceivedBytes(); |
| +} |
| + |
| +int64_t BidirectionalStream::GetTotalSentBytes() const { |
| + DCHECK(stream_job_); |
| + |
| + return stream_job_->GetTotalSentBytes(); |
| +} |
| + |
| +void BidirectionalStream::OnRequestHeadersSent() { |
| + DCHECK(delegate_); |
|
mmenke
2015/12/08 22:58:34
Get rid of this, and move it into the constructor?
xunjieli
2015/12/10 23:25:50
Done. Good idea!
|
| + |
| + delegate_->OnRequestHeadersSent(); |
| +} |
| + |
| +void BidirectionalStream::OnHeaders(const SpdyHeaderBlock& response_headers) { |
| + DCHECK(delegate_); |
| + |
| + delegate_->OnHeaders(response_headers); |
| +} |
| + |
| +void BidirectionalStream::OnReadCompleted(int bytes_read) { |
| + DCHECK(delegate_); |
| + |
| + delegate_->OnReadCompleted(bytes_read); |
| +} |
| + |
| +void BidirectionalStream::OnDataSent() { |
| + DCHECK(delegate_); |
| + |
| + delegate_->OnDataSent(); |
| +} |
| + |
| +void BidirectionalStream::OnTrailers(const SpdyHeaderBlock& trailers) { |
| + DCHECK(delegate_); |
| + |
| + delegate_->OnTrailers(trailers); |
| +} |
| + |
| +void BidirectionalStream::OnFailed(int status) { |
| + DCHECK(delegate_); |
| + |
| + delegate_->OnFailed(status); |
| +} |
| + |
| +void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + HttpStream* stream) { |
| + NOTREACHED(); |
| +} |
| + |
| +void BidirectionalStream::OnBidirectionalStreamJobReady( |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + BidirectionalStreamJob* stream) { |
| + DCHECK(!stream_job_); |
| + |
| + stream_job_.reset(stream); |
| + stream_request_.reset(); |
| + HttpRequestInfo http_request_info; |
| + http_request_info.url = request_info_.url; |
| + http_request_info.method = request_info_.method; |
| + http_request_info.extra_headers = request_info_.extra_headers; |
| + |
| + stream_job_->Start(http_request_info, priority_, net_log_, this); |
| +} |
| + |
| +void BidirectionalStream::OnWebSocketHandshakeStreamReady( |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + WebSocketHandshakeStreamBase* stream) { |
| + NOTREACHED(); |
| +} |
| + |
| +void BidirectionalStream::OnStreamFailed(int result, |
| + const SSLConfig& used_ssl_config, |
| + SSLFailureState ssl_failure_state) { |
| + DCHECK_LT(result, 0); |
| + DCHECK_NE(result, ERR_IO_PENDING); |
| + DCHECK(stream_request_); |
| + |
| + delegate_->OnFailed(static_cast<Error>(result)); |
| +} |
| + |
| +void BidirectionalStream::OnCertificateError(int result, |
| + const SSLConfig& used_ssl_config, |
| + const SSLInfo& ssl_info) { |
| + DCHECK_LT(result, 0); |
| + DCHECK_NE(result, ERR_IO_PENDING); |
| + DCHECK(stream_request_); |
| + |
| + delegate_->OnFailed(static_cast<Error>(result)); |
| +} |
| + |
| +void BidirectionalStream::OnNeedsProxyAuth( |
| + const HttpResponseInfo& proxy_response, |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + HttpAuthController* auth_controller) { |
| + DCHECK(stream_request_); |
| + |
| + delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED); |
| +} |
| + |
| +void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, |
| + SSLCertRequestInfo* cert_info) { |
| + DCHECK(stream_request_); |
| + |
| + delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
| +} |
| + |
| +void BidirectionalStream::OnHttpsProxyTunnelResponse( |
| + const HttpResponseInfo& response_info, |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + HttpStream* stream) { |
| + NOTREACHED(); |
| +} |
| + |
| +} // namespace net |