| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/quic/chromium/bidirectional_stream_quic_impl.h" | 5 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 | 92 |
| 93 SpdyHeaderBlock headers; | 93 SpdyHeaderBlock headers; |
| 94 HttpRequestInfo http_request_info; | 94 HttpRequestInfo http_request_info; |
| 95 http_request_info.url = request_info_->url; | 95 http_request_info.url = request_info_->url; |
| 96 http_request_info.method = request_info_->method; | 96 http_request_info.method = request_info_->method; |
| 97 http_request_info.extra_headers = request_info_->extra_headers; | 97 http_request_info.extra_headers = request_info_->extra_headers; |
| 98 | 98 |
| 99 CreateSpdyHeadersFromHttpRequest( | 99 CreateSpdyHeadersFromHttpRequest( |
| 100 http_request_info, http_request_info.extra_headers, true, &headers); | 100 http_request_info, http_request_info.extra_headers, true, &headers); |
| 101 // Sending the request might result in |this| being deleted. |
| 102 auto guard = weak_factory_.GetWeakPtr(); |
| 101 size_t headers_bytes_sent = stream_->WriteHeaders( | 103 size_t headers_bytes_sent = stream_->WriteHeaders( |
| 102 std::move(headers), request_info_->end_stream_on_headers, nullptr); | 104 std::move(headers), request_info_->end_stream_on_headers, nullptr); |
| 105 if (!guard.get()) |
| 106 return; |
| 103 headers_bytes_sent_ += headers_bytes_sent; | 107 headers_bytes_sent_ += headers_bytes_sent; |
| 104 has_sent_headers_ = true; | 108 has_sent_headers_ = true; |
| 105 } | 109 } |
| 106 | 110 |
| 107 int BidirectionalStreamQuicImpl::ReadData(IOBuffer* buffer, int buffer_len) { | 111 int BidirectionalStreamQuicImpl::ReadData(IOBuffer* buffer, int buffer_len) { |
| 108 DCHECK(buffer); | 112 DCHECK(buffer); |
| 109 DCHECK(buffer_len); | 113 DCHECK(buffer_len); |
| 110 | 114 |
| 111 if (!stream_) { | 115 if (!stream_) { |
| 112 // If the stream is already closed, there is no body to read. | 116 // If the stream is already closed, there is no body to read. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 261 |
| 258 void BidirectionalStreamQuicImpl::OnError(int error) { | 262 void BidirectionalStreamQuicImpl::OnError(int error) { |
| 259 NotifyError(error); | 263 NotifyError(error); |
| 260 } | 264 } |
| 261 | 265 |
| 262 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { | 266 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { |
| 263 DCHECK_NE(ERR_IO_PENDING, rv); | 267 DCHECK_NE(ERR_IO_PENDING, rv); |
| 264 DCHECK(rv == OK || !stream_); | 268 DCHECK(rv == OK || !stream_); |
| 265 if (rv == OK) { | 269 if (rv == OK) { |
| 266 stream_ = session_->ReleaseStream(this); | 270 stream_ = session_->ReleaseStream(this); |
| 271 |
| 272 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 273 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::ReadInitialHeaders, |
| 274 weak_factory_.GetWeakPtr())); |
| 275 |
| 267 NotifyStreamReady(); | 276 NotifyStreamReady(); |
| 268 | |
| 269 rv = stream_->ReadInitialHeaders( | |
| 270 &initial_headers_, | |
| 271 base::Bind(&BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete, | |
| 272 weak_factory_.GetWeakPtr())); | |
| 273 if (rv == ERR_IO_PENDING) | |
| 274 return; | |
| 275 | |
| 276 OnReadInitialHeadersComplete(rv); | |
| 277 } else { | 277 } else { |
| 278 NotifyError(rv); | 278 NotifyError(rv); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { | 282 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { |
| 283 DCHECK(rv == OK || !stream_); | 283 DCHECK(rv == OK || !stream_); |
| 284 if (rv == OK) { | 284 if (rv == OK) { |
| 285 if (delegate_) | 285 if (delegate_) |
| 286 delegate_->OnDataSent(); | 286 delegate_->OnDataSent(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 299 headers_bytes_received_ += rv; | 299 headers_bytes_received_ += rv; |
| 300 negotiated_protocol_ = kProtoQUIC; | 300 negotiated_protocol_ = kProtoQUIC; |
| 301 connect_timing_ = session_->GetConnectTiming(); | 301 connect_timing_ = session_->GetConnectTiming(); |
| 302 base::ThreadTaskRunnerHandle::Get()->PostTask( | 302 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 303 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::ReadTrailingHeaders, | 303 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::ReadTrailingHeaders, |
| 304 weak_factory_.GetWeakPtr())); | 304 weak_factory_.GetWeakPtr())); |
| 305 if (delegate_) | 305 if (delegate_) |
| 306 delegate_->OnHeadersReceived(initial_headers_); | 306 delegate_->OnHeadersReceived(initial_headers_); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void BidirectionalStreamQuicImpl::ReadInitialHeaders() { |
| 310 int rv = stream_->ReadInitialHeaders( |
| 311 &initial_headers_, |
| 312 base::Bind(&BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete, |
| 313 weak_factory_.GetWeakPtr())); |
| 314 |
| 315 if (rv != ERR_IO_PENDING) |
| 316 OnReadInitialHeadersComplete(rv); |
| 317 } |
| 318 |
| 309 void BidirectionalStreamQuicImpl::ReadTrailingHeaders() { | 319 void BidirectionalStreamQuicImpl::ReadTrailingHeaders() { |
| 310 int rv = stream_->ReadTrailingHeaders( | 320 int rv = stream_->ReadTrailingHeaders( |
| 311 &trailing_headers_, | 321 &trailing_headers_, |
| 312 base::Bind(&BidirectionalStreamQuicImpl::OnReadTrailingHeadersComplete, | 322 base::Bind(&BidirectionalStreamQuicImpl::OnReadTrailingHeadersComplete, |
| 313 weak_factory_.GetWeakPtr())); | 323 weak_factory_.GetWeakPtr())); |
| 314 | 324 |
| 315 if (rv != ERR_IO_PENDING) | 325 if (rv != ERR_IO_PENDING) |
| 316 OnReadTrailingHeadersComplete(rv); | 326 OnReadTrailingHeadersComplete(rv); |
| 317 } | 327 } |
| 318 | 328 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 delegate_ = nullptr; | 365 delegate_ = nullptr; |
| 356 // Cancel any pending callback. | 366 // Cancel any pending callback. |
| 357 weak_factory_.InvalidateWeakPtrs(); | 367 weak_factory_.InvalidateWeakPtrs(); |
| 358 delegate->OnFailed(error); | 368 delegate->OnFailed(error); |
| 359 // |this| might be destroyed at this point. | 369 // |this| might be destroyed at this point. |
| 360 } | 370 } |
| 361 } | 371 } |
| 362 | 372 |
| 363 void BidirectionalStreamQuicImpl::NotifyStreamReady() { | 373 void BidirectionalStreamQuicImpl::NotifyStreamReady() { |
| 364 if (send_request_headers_automatically_) { | 374 if (send_request_headers_automatically_) { |
| 375 // Sending the request might result in |this| being deleted. |
| 376 auto guard = weak_factory_.GetWeakPtr(); |
| 365 SendRequestHeaders(); | 377 SendRequestHeaders(); |
| 378 if (!guard.get()) |
| 379 return; |
| 366 } | 380 } |
| 367 if (delegate_) | 381 if (delegate_) |
| 368 delegate_->OnStreamReady(has_sent_headers_); | 382 delegate_->OnStreamReady(has_sent_headers_); |
| 369 } | 383 } |
| 370 | 384 |
| 371 void BidirectionalStreamQuicImpl::ResetStream() { | 385 void BidirectionalStreamQuicImpl::ResetStream() { |
| 372 if (!stream_) | 386 if (!stream_) |
| 373 return; | 387 return; |
| 374 closed_stream_received_bytes_ = stream_->stream_bytes_read(); | 388 closed_stream_received_bytes_ = stream_->stream_bytes_read(); |
| 375 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 389 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 376 closed_is_first_stream_ = stream_->IsFirstStream(); | 390 closed_is_first_stream_ = stream_->IsFirstStream(); |
| 377 stream_->ClearDelegate(); | 391 stream_->ClearDelegate(); |
| 378 stream_ = nullptr; | 392 stream_ = nullptr; |
| 379 } | 393 } |
| 380 | 394 |
| 381 } // namespace net | 395 } // namespace net |
| OLD | NEW |