Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/http/bidirectional_stream_helper.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/thread_task_runner_handle.h" | |
| 10 #include "net/base/load_flags.h" | |
| 11 #include "net/base/net_errors.h" | |
| 12 #include "net/http/http_network_session.h" | |
| 13 #include "net/http/http_request_info.h" | |
| 14 #include "net/http/http_stream.h" | |
| 15 #include "net/log/net_log.h" | |
| 16 #include "net/ssl/ssl_cert_request_info.h" | |
| 17 #include "url/gurl.h" | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 BidirectionalStreamHelper::BidirectionalStreamHelper( | |
| 22 const HttpRequestInfo& request_info, | |
| 23 RequestPriority priority, | |
| 24 HttpNetworkSession* session, | |
| 25 Delegate* delegate) | |
| 26 : request_info_(request_info), | |
| 27 priority_(priority), | |
| 28 net_log_(BoundNetLog::Make(session->net_log(), | |
| 29 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), | |
| 30 delegate_(delegate) { | |
| 31 DCHECK(!request_info.upload_data_stream); | |
| 32 DCHECK_EQ(LOAD_NORMAL, request_info.load_flags); | |
| 33 | |
| 34 SSLConfig server_ssl_config; | |
| 35 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); | |
| 36 | |
| 37 if (!request_info.url.SchemeIs("https")) { | |
| 38 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 39 FROM_HERE, | |
| 40 base::Bind(&Delegate::OnStreamFailed, base::Unretained(delegate_), | |
| 41 ERR_DISALLOWED_URL_SCHEME)); | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 stream_request_.reset( | |
| 46 session->http_stream_factory()->RequestBidirectionalStream( | |
| 47 request_info_, priority_, server_ssl_config, server_ssl_config, this, | |
| 48 net_log_)); | |
| 49 } | |
| 50 | |
| 51 BidirectionalStreamHelper::~BidirectionalStreamHelper() {} | |
| 52 | |
| 53 void BidirectionalStreamHelper::Start(BidirectionalStream::Delegate* delegate) { | |
|
mmenke
2015/11/03 20:32:13
Destroy the stream_request? Not so concerned abou
xunjieli
2015/11/05 23:17:13
Done.
| |
| 54 DCHECK(stream_); | |
| 55 | |
| 56 stream_->Start(request_info_, priority_, net_log_, delegate); | |
| 57 } | |
| 58 | |
| 59 int BidirectionalStreamHelper::ReadData(IOBuffer* buf, int buf_len) { | |
| 60 DCHECK(stream_); | |
| 61 | |
| 62 return stream_->ReadData(buf, buf_len); | |
| 63 } | |
| 64 | |
| 65 void BidirectionalStreamHelper::SendData(IOBuffer* data, | |
| 66 int length, | |
| 67 bool end_stream) { | |
| 68 DCHECK(stream_); | |
| 69 | |
| 70 stream_->SendData(data, length, end_stream); | |
| 71 } | |
| 72 | |
| 73 void BidirectionalStreamHelper::Cancel() { | |
|
mmenke
2015/11/03 20:32:13
If we're still requesting a stream, should cancel
xunjieli
2015/11/05 23:17:13
Done.
| |
| 74 DCHECK(stream_); | |
| 75 | |
| 76 stream_->Cancel(); | |
| 77 } | |
| 78 | |
| 79 void BidirectionalStreamHelper::OnStreamReady(const SSLConfig& used_ssl_config, | |
| 80 const ProxyInfo& used_proxy_info, | |
| 81 HttpStream* stream) { | |
| 82 NOTREACHED(); | |
| 83 } | |
| 84 | |
| 85 void BidirectionalStreamHelper::OnBidirectionalStreamReady( | |
| 86 const SSLConfig& used_ssl_config, | |
| 87 const ProxyInfo& used_proxy_info, | |
| 88 BidirectionalStream* stream) { | |
| 89 DCHECK(!stream_); | |
| 90 | |
| 91 stream_.reset(stream); | |
| 92 delegate_->OnStreamReady(); | |
| 93 } | |
| 94 | |
| 95 void BidirectionalStreamHelper::OnWebSocketHandshakeStreamReady( | |
| 96 const SSLConfig& used_ssl_config, | |
| 97 const ProxyInfo& used_proxy_info, | |
| 98 WebSocketHandshakeStreamBase* stream) { | |
| 99 NOTREACHED(); | |
| 100 } | |
| 101 | |
| 102 void BidirectionalStreamHelper::OnStreamFailed( | |
| 103 int result, | |
| 104 const SSLConfig& used_ssl_config, | |
| 105 SSLFailureState ssl_failure_state) { | |
| 106 DCHECK_LT(result, 0); | |
| 107 DCHECK_NE(result, ERR_IO_PENDING); | |
| 108 DCHECK(stream_request_); | |
| 109 | |
| 110 delegate_->OnStreamFailed(result); | |
| 111 } | |
| 112 | |
| 113 void BidirectionalStreamHelper::OnCertificateError( | |
| 114 int result, | |
| 115 const SSLConfig& used_ssl_config, | |
| 116 const SSLInfo& ssl_info) { | |
| 117 DCHECK_LT(result, 0); | |
| 118 DCHECK_NE(result, ERR_IO_PENDING); | |
| 119 DCHECK(stream_request_); | |
| 120 | |
| 121 delegate_->OnStreamFailed(result); | |
| 122 } | |
| 123 | |
| 124 void BidirectionalStreamHelper::OnNeedsProxyAuth( | |
| 125 const HttpResponseInfo& proxy_response, | |
| 126 const SSLConfig& used_ssl_config, | |
| 127 const ProxyInfo& used_proxy_info, | |
| 128 HttpAuthController* auth_controller) { | |
| 129 DCHECK(stream_request_); | |
| 130 | |
| 131 delegate_->OnStreamFailed(ERR_PROXY_AUTH_REQUESTED); | |
| 132 } | |
| 133 | |
| 134 void BidirectionalStreamHelper::OnNeedsClientAuth( | |
| 135 const SSLConfig& used_ssl_config, | |
| 136 SSLCertRequestInfo* cert_info) { | |
| 137 DCHECK(stream_request_); | |
| 138 | |
| 139 delegate_->OnStreamFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
| 140 } | |
| 141 | |
| 142 void BidirectionalStreamHelper::OnHttpsProxyTunnelResponse( | |
| 143 const HttpResponseInfo& response_info, | |
| 144 const SSLConfig& used_ssl_config, | |
| 145 const ProxyInfo& used_proxy_info, | |
| 146 HttpStream* stream) { | |
| 147 NOTREACHED(); | |
| 148 } | |
| 149 | |
| 150 } // namespace net | |
| OLD | NEW |