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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 bool send_request_headers_automatically, | 78 bool send_request_headers_automatically, |
79 Delegate* delegate, | 79 Delegate* delegate, |
80 std::unique_ptr<base::Timer> timer) | 80 std::unique_ptr<base::Timer> timer) |
81 : request_info_(std::move(request_info)), | 81 : request_info_(std::move(request_info)), |
82 net_log_(BoundNetLog::Make(session->net_log(), | 82 net_log_(BoundNetLog::Make(session->net_log(), |
83 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), | 83 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), |
84 session_(session), | 84 session_(session), |
85 send_request_headers_automatically_(send_request_headers_automatically), | 85 send_request_headers_automatically_(send_request_headers_automatically), |
86 request_headers_sent_(false), | 86 request_headers_sent_(false), |
87 delegate_(delegate), | 87 delegate_(delegate), |
88 timer_(std::move(timer)) { | 88 timer_(std::move(timer)), |
| 89 weak_factory_(this) { |
89 DCHECK(delegate_); | 90 DCHECK(delegate_); |
90 DCHECK(request_info_); | 91 DCHECK(request_info_); |
91 | 92 |
92 if (net_log_.IsCapturing()) { | 93 if (net_log_.IsCapturing()) { |
93 net_log_.BeginEvent( | 94 net_log_.BeginEvent( |
94 NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE, | 95 NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE, |
95 base::Bind(&NetLogCallback, &request_info_->url, &request_info_->method, | 96 base::Bind(&NetLogCallback, &request_info_->url, &request_info_->method, |
96 base::Unretained(&request_info_->extra_headers))); | 97 base::Unretained(&request_info_->extra_headers))); |
97 } | 98 } |
98 | 99 |
99 SSLConfig server_ssl_config; | 100 SSLConfig server_ssl_config; |
100 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); | 101 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); |
101 session->GetAlpnProtos(&server_ssl_config.alpn_protos); | 102 session->GetAlpnProtos(&server_ssl_config.alpn_protos); |
102 session->GetNpnProtos(&server_ssl_config.npn_protos); | 103 session->GetNpnProtos(&server_ssl_config.npn_protos); |
103 | 104 |
104 if (!request_info_->url.SchemeIs(url::kHttpsScheme)) { | 105 if (!request_info_->url.SchemeIs(url::kHttpsScheme)) { |
105 base::ThreadTaskRunnerHandle::Get()->PostTask( | 106 base::ThreadTaskRunnerHandle::Get()->PostTask( |
106 FROM_HERE, | 107 FROM_HERE, |
107 base::Bind(&BidirectionalStream::Delegate::OnFailed, | 108 base::Bind(&BidirectionalStream::NotifyFailed, |
108 base::Unretained(delegate_), ERR_DISALLOWED_URL_SCHEME)); | 109 weak_factory_.GetWeakPtr(), ERR_DISALLOWED_URL_SCHEME)); |
109 return; | 110 return; |
110 } | 111 } |
111 | 112 |
112 HttpRequestInfo http_request_info; | 113 HttpRequestInfo http_request_info; |
113 http_request_info.url = request_info_->url; | 114 http_request_info.url = request_info_->url; |
114 http_request_info.method = request_info_->method; | 115 http_request_info.method = request_info_->method; |
115 http_request_info.extra_headers = request_info_->extra_headers; | 116 http_request_info.extra_headers = request_info_->extra_headers; |
116 stream_request_.reset( | 117 stream_request_.reset( |
117 session->http_stream_factory()->RequestBidirectionalStreamImpl( | 118 session->http_stream_factory()->RequestBidirectionalStreamImpl( |
118 http_request_info, request_info_->priority, server_ssl_config, | 119 http_request_info, request_info_->priority, server_ssl_config, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 void BidirectionalStream::OnStreamReady(bool request_headers_sent) { | 214 void BidirectionalStream::OnStreamReady(bool request_headers_sent) { |
214 request_headers_sent_ = request_headers_sent; | 215 request_headers_sent_ = request_headers_sent; |
215 delegate_->OnStreamReady(request_headers_sent); | 216 delegate_->OnStreamReady(request_headers_sent); |
216 } | 217 } |
217 | 218 |
218 void BidirectionalStream::OnHeadersReceived( | 219 void BidirectionalStream::OnHeadersReceived( |
219 const SpdyHeaderBlock& response_headers) { | 220 const SpdyHeaderBlock& response_headers) { |
220 HttpResponseInfo response_info; | 221 HttpResponseInfo response_info; |
221 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { | 222 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { |
222 DLOG(WARNING) << "Invalid headers"; | 223 DLOG(WARNING) << "Invalid headers"; |
223 delegate_->OnFailed(ERR_FAILED); | 224 NotifyFailed(ERR_FAILED); |
224 return; | 225 return; |
225 } | 226 } |
226 if (net_log_.IsCapturing()) { | 227 if (net_log_.IsCapturing()) { |
227 net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_HEADERS, | 228 net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_HEADERS, |
228 base::Bind(&NetLogHeadersCallback, &response_headers)); | 229 base::Bind(&NetLogHeadersCallback, &response_headers)); |
229 } | 230 } |
230 session_->http_stream_factory()->ProcessAlternativeServices( | 231 session_->http_stream_factory()->ProcessAlternativeServices( |
231 session_, response_info.headers.get(), | 232 session_, response_info.headers.get(), |
232 url::SchemeHostPort(request_info_->url)); | 233 url::SchemeHostPort(request_info_->url)); |
233 delegate_->OnHeadersReceived(response_headers); | 234 delegate_->OnHeadersReceived(response_headers); |
(...skipping 29 matching lines...) Expand all Loading... |
263 | 264 |
264 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { | 265 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { |
265 if (net_log_.IsCapturing()) { | 266 if (net_log_.IsCapturing()) { |
266 net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_TRAILERS, | 267 net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_TRAILERS, |
267 base::Bind(&NetLogHeadersCallback, &trailers)); | 268 base::Bind(&NetLogHeadersCallback, &trailers)); |
268 } | 269 } |
269 delegate_->OnTrailersReceived(trailers); | 270 delegate_->OnTrailersReceived(trailers); |
270 } | 271 } |
271 | 272 |
272 void BidirectionalStream::OnFailed(int status) { | 273 void BidirectionalStream::OnFailed(int status) { |
273 delegate_->OnFailed(status); | 274 NotifyFailed(status); |
274 } | 275 } |
275 | 276 |
276 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, | 277 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, |
277 const ProxyInfo& used_proxy_info, | 278 const ProxyInfo& used_proxy_info, |
278 HttpStream* stream) { | 279 HttpStream* stream) { |
279 NOTREACHED(); | 280 NOTREACHED(); |
280 } | 281 } |
281 | 282 |
282 void BidirectionalStream::OnBidirectionalStreamImplReady( | 283 void BidirectionalStream::OnBidirectionalStreamImplReady( |
283 const SSLConfig& used_ssl_config, | 284 const SSLConfig& used_ssl_config, |
(...skipping 15 matching lines...) Expand all Loading... |
299 NOTREACHED(); | 300 NOTREACHED(); |
300 } | 301 } |
301 | 302 |
302 void BidirectionalStream::OnStreamFailed(int result, | 303 void BidirectionalStream::OnStreamFailed(int result, |
303 const SSLConfig& used_ssl_config, | 304 const SSLConfig& used_ssl_config, |
304 SSLFailureState ssl_failure_state) { | 305 SSLFailureState ssl_failure_state) { |
305 DCHECK_LT(result, 0); | 306 DCHECK_LT(result, 0); |
306 DCHECK_NE(result, ERR_IO_PENDING); | 307 DCHECK_NE(result, ERR_IO_PENDING); |
307 DCHECK(stream_request_); | 308 DCHECK(stream_request_); |
308 | 309 |
309 delegate_->OnFailed(result); | 310 NotifyFailed(result); |
310 } | 311 } |
311 | 312 |
312 void BidirectionalStream::OnCertificateError(int result, | 313 void BidirectionalStream::OnCertificateError(int result, |
313 const SSLConfig& used_ssl_config, | 314 const SSLConfig& used_ssl_config, |
314 const SSLInfo& ssl_info) { | 315 const SSLInfo& ssl_info) { |
315 DCHECK_LT(result, 0); | 316 DCHECK_LT(result, 0); |
316 DCHECK_NE(result, ERR_IO_PENDING); | 317 DCHECK_NE(result, ERR_IO_PENDING); |
317 DCHECK(stream_request_); | 318 DCHECK(stream_request_); |
318 | 319 |
319 delegate_->OnFailed(result); | 320 NotifyFailed(result); |
320 } | 321 } |
321 | 322 |
322 void BidirectionalStream::OnNeedsProxyAuth( | 323 void BidirectionalStream::OnNeedsProxyAuth( |
323 const HttpResponseInfo& proxy_response, | 324 const HttpResponseInfo& proxy_response, |
324 const SSLConfig& used_ssl_config, | 325 const SSLConfig& used_ssl_config, |
325 const ProxyInfo& used_proxy_info, | 326 const ProxyInfo& used_proxy_info, |
326 HttpAuthController* auth_controller) { | 327 HttpAuthController* auth_controller) { |
327 DCHECK(stream_request_); | 328 DCHECK(stream_request_); |
328 | 329 |
329 delegate_->OnFailed(ERR_PROXY_AUTH_REQUESTED); | 330 NotifyFailed(ERR_PROXY_AUTH_REQUESTED); |
330 } | 331 } |
331 | 332 |
332 void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, | 333 void BidirectionalStream::OnNeedsClientAuth(const SSLConfig& used_ssl_config, |
333 SSLCertRequestInfo* cert_info) { | 334 SSLCertRequestInfo* cert_info) { |
334 DCHECK(stream_request_); | 335 DCHECK(stream_request_); |
335 | 336 |
336 delegate_->OnFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | 337 NotifyFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
337 } | 338 } |
338 | 339 |
339 void BidirectionalStream::OnHttpsProxyTunnelResponse( | 340 void BidirectionalStream::OnHttpsProxyTunnelResponse( |
340 const HttpResponseInfo& response_info, | 341 const HttpResponseInfo& response_info, |
341 const SSLConfig& used_ssl_config, | 342 const SSLConfig& used_ssl_config, |
342 const ProxyInfo& used_proxy_info, | 343 const ProxyInfo& used_proxy_info, |
343 HttpStream* stream) { | 344 HttpStream* stream) { |
344 DCHECK(stream_request_); | 345 DCHECK(stream_request_); |
345 | 346 |
346 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); | 347 NotifyFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); |
347 } | 348 } |
348 | 349 |
349 void BidirectionalStream::OnQuicBroken() {} | 350 void BidirectionalStream::OnQuicBroken() {} |
350 | 351 |
| 352 void BidirectionalStream::NotifyFailed(int error) { |
| 353 delegate_->OnFailed(error); |
| 354 } |
| 355 |
351 } // namespace net | 356 } // namespace net |
OLD | NEW |