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.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/thread_task_runner_handle.h" | |
| 12 #include "net/base/load_flags.h" | |
| 13 #include "net/base/net_errors.h" | |
| 14 #include "net/http/http_network_session.h" | |
| 15 #include "net/http/http_stream.h" | |
| 16 #include "net/log/net_log.h" | |
| 17 #include "net/ssl/ssl_cert_request_info.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace net { | |
| 21 | |
| 22 BidirectionalStream::RequestInfo::RequestInfo() {} | |
| 23 | |
| 24 BidirectionalStream::RequestInfo::~RequestInfo() {} | |
| 25 | |
| 26 BidirectionalStream::BidirectionalStream(const RequestInfo& request_info, | |
| 27 RequestPriority priority, | |
| 28 HttpNetworkSession* session, | |
| 29 Delegate* delegate) | |
| 30 : request_info_(request_info), | |
| 31 priority_(priority), | |
| 32 net_log_(BoundNetLog::Make(session->net_log(), | |
| 33 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), | |
| 34 delegate_(delegate) { | |
| 35 DCHECK(delegate_); | |
| 36 SSLConfig server_ssl_config; | |
| 37 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); | |
| 38 session->GetAlpnProtos(&server_ssl_config.alpn_protos); | |
| 39 session->GetNpnProtos(&server_ssl_config.npn_protos); | |
| 40 | |
| 41 if (!request_info.url.SchemeIs("https")) { | |
| 42 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 43 FROM_HERE, base::Bind(&Delegate::OnFailed, base::Unretained(delegate_), | |
| 44 ERR_DISALLOWED_URL_SCHEME)); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 HttpRequestInfo http_request_info; | |
| 49 http_request_info.url = request_info.url; | |
| 50 http_request_info.method = request_info.method; | |
| 51 http_request_info.extra_headers = request_info.extra_headers; | |
| 52 stream_request_.reset( | |
| 53 session->http_stream_factory()->RequestBidirectionalStreamJob( | |
| 54 http_request_info, priority_, server_ssl_config, server_ssl_config, | |
| 55 this, net_log_)); | |
| 56 } | |
| 57 | |
| 58 BidirectionalStream::~BidirectionalStream() { | |
| 59 Cancel(); | |
| 60 } | |
| 61 | |
| 62 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { | |
| 63 DCHECK(stream_job_); | |
| 64 | |
| 65 return stream_job_->ReadData(buf, buf_len); | |
| 66 } | |
| 67 | |
| 68 void BidirectionalStream::SendData(IOBuffer* data, | |
| 69 int length, | |
| 70 bool end_stream) { | |
| 71 DCHECK(stream_job_); | |
| 72 | |
| 73 stream_job_->SendData(data, length, end_stream); | |
| 74 } | |
| 75 | |
| 76 void BidirectionalStream::Cancel() { | |
| 77 if (stream_request_) | |
| 78 stream_request_.reset(); | |
| 79 if (stream_job_) | |
| 80 stream_job_->Cancel(); | |
| 81 } | |
| 82 | |
| 83 NextProto BidirectionalStream::GetProtocol() const { | |
| 84 DCHECK(stream_job_); | |
| 85 | |
| 86 return stream_job_->GetProtocol(); | |
| 87 } | |
| 88 | |
| 89 int64_t BidirectionalStream::GetTotalReceivedBytes() const { | |
| 90 DCHECK(stream_job_); | |
|
mef
2015/12/11 20:54:26
Would it make sense to return 0 if there is no str
xunjieli
2015/12/11 23:48:39
Done.
| |
| 91 | |
| 92 return stream_job_->GetTotalReceivedBytes(); | |
| 93 } | |
| 94 | |
| 95 int64_t BidirectionalStream::GetTotalSentBytes() const { | |
| 96 DCHECK(stream_job_); | |
| 97 | |
| 98 return stream_job_->GetTotalSentBytes(); | |
| 99 } | |
| 100 | |
| 101 void BidirectionalStream::OnHeadersSent() { | |
| 102 delegate_->OnHeadersSent(); | |
| 103 } | |
| 104 | |
| 105 void BidirectionalStream::OnHeadersReceived( | |
| 106 const SpdyHeaderBlock& response_headers) { | |
| 107 delegate_->OnHeadersReceived(response_headers); | |
| 108 } | |
| 109 | |
| 110 void BidirectionalStream::OnDataRead(int bytes_read) { | |
| 111 delegate_->OnDataRead(bytes_read); | |
| 112 } | |
| 113 | |
| 114 void BidirectionalStream::OnDataSent() { | |
| 115 delegate_->OnDataSent(); | |
| 116 } | |
| 117 | |
| 118 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { | |
| 119 delegate_->OnTrailersReceived(trailers); | |
| 120 } | |
| 121 | |
| 122 void BidirectionalStream::OnFailed(int status) { | |
| 123 delegate_->OnFailed(status); | |
| 124 } | |
| 125 | |
| 126 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, | |
| 127 const ProxyInfo& used_proxy_info, | |
| 128 HttpStream* stream) { | |
| 129 NOTREACHED(); | |
| 130 } | |
| 131 | |
| 132 void BidirectionalStream::OnBidirectionalStreamJobReady( | |
| 133 const SSLConfig& used_ssl_config, | |
| 134 const ProxyInfo& used_proxy_info, | |
| 135 BidirectionalStreamJob* stream) { | |
| 136 DCHECK(!stream_job_); | |
| 137 | |
| 138 stream_job_.reset(stream); | |
| 139 stream_request_.reset(); | |
| 140 HttpRequestInfo http_request_info; | |
| 141 http_request_info.url = request_info_.url; | |
| 142 http_request_info.method = request_info_.method; | |
| 143 http_request_info.extra_headers = request_info_.extra_headers; | |
| 144 | |
| 145 stream_job_->Start(http_request_info, priority_, net_log_, this); | |
| 146 } | |
| 147 | |
| 148 void BidirectionalStream::OnWebSocketHandshakeStreamReady( | |
| 149 const SSLConfig& used_ssl_config, | |
| 150 const ProxyInfo& used_proxy_info, | |
| 151 WebSocketHandshakeStreamBase* stream) { | |
| 152 NOTREACHED(); | |
| 153 } | |
| 154 | |
| 155 void BidirectionalStream::OnStreamFailed(int result, | |
| 156 const SSLConfig& used_ssl_config, | |
| 157 SSLFailureState ssl_failure_state) { | |
| 158 DCHECK_LT(result, 0); | |
| 159 DCHECK_NE(result, ERR_IO_PENDING); | |
| 160 DCHECK(stream_request_); | |
| 161 | |
| 162 delegate_->OnFailed(static_cast<Error>(result)); | |
| 163 } | |
| 164 | |
| 165 void BidirectionalStream::OnCertificateError(int result, | |
| 166 const SSLConfig& used_ssl_config, | |
| 167 const SSLInfo& ssl_info) { | |
| 168 DCHECK_LT(result, 0); | |
| 169 DCHECK_NE(result, ERR_IO_PENDING); | |
| 170 DCHECK(stream_request_); | |
| 171 | |
| 172 delegate_->OnFailed(static_cast<Error>(result)); | |
| 173 } | |
| 174 | |
| 175 void BidirectionalStream::OnNeedsProxyAuth( | |
| 176 const HttpResponseInfo& proxy_response, | |
| 177 const SSLConfig& used_ssl_config, | |
| 178 const ProxyInfo& used_proxy_info, | |
| 179 HttpAuthController* auth_controller) { | |
| 180 DCHECK(stream_request_); | |
| 181 | |
| 182 delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED); | |
| 183 } | |
| 184 | |
| 185 void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, | |
| 186 SSLCertRequestInfo* cert_info) { | |
| 187 DCHECK(stream_request_); | |
| 188 | |
| 189 delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | |
| 190 } | |
| 191 | |
| 192 void BidirectionalStream::OnHttpsProxyTunnelResponse( | |
| 193 const HttpResponseInfo& response_info, | |
| 194 const SSLConfig& used_ssl_config, | |
| 195 const ProxyInfo& used_proxy_info, | |
| 196 HttpStream* stream) { | |
| 197 NOTREACHED(); | |
|
mmenke
2015/12/11 16:42:53
Why can't this be reached?
xunjieli
2015/12/11 23:48:40
Not sure how to handle this. HttpNetworkTransactio
| |
| 198 } | |
| 199 | |
| 200 void BidirectionalStream::OnQuicBroken() {} | |
| 201 | |
| 202 } // namespace net | |
| OLD | NEW |