| 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 20 matching lines...) Expand all Loading... |
| 31 negotiated_protocol_(kProtoUnknown), | 31 negotiated_protocol_(kProtoUnknown), |
| 32 read_buffer_len_(0), | 32 read_buffer_len_(0), |
| 33 headers_bytes_received_(0), | 33 headers_bytes_received_(0), |
| 34 headers_bytes_sent_(0), | 34 headers_bytes_sent_(0), |
| 35 closed_stream_received_bytes_(0), | 35 closed_stream_received_bytes_(0), |
| 36 closed_stream_sent_bytes_(0), | 36 closed_stream_sent_bytes_(0), |
| 37 closed_is_first_stream_(false), | 37 closed_is_first_stream_(false), |
| 38 has_sent_headers_(false), | 38 has_sent_headers_(false), |
| 39 has_received_headers_(false), | 39 has_received_headers_(false), |
| 40 send_request_headers_automatically_(true), | 40 send_request_headers_automatically_(true), |
| 41 waiting_for_confirmation_(false), | |
| 42 weak_factory_(this) { | 41 weak_factory_(this) { |
| 43 DCHECK(session_); | 42 DCHECK(session_); |
| 44 session_->AddObserver(this); | 43 session_->AddObserver(this); |
| 45 } | 44 } |
| 46 | 45 |
| 47 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { | 46 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { |
| 48 if (stream_) { | 47 if (stream_) { |
| 49 delegate_ = nullptr; | 48 delegate_ = nullptr; |
| 50 stream_->Reset(QUIC_STREAM_CANCELLED); | 49 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 51 } | 50 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 send_request_headers_automatically_ = send_request_headers_automatically; | 65 send_request_headers_automatically_ = send_request_headers_automatically; |
| 67 if (!session_) { | 66 if (!session_) { |
| 68 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR | 67 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR |
| 69 : ERR_QUIC_HANDSHAKE_FAILED); | 68 : ERR_QUIC_HANDSHAKE_FAILED); |
| 70 return; | 69 return; |
| 71 } | 70 } |
| 72 | 71 |
| 73 delegate_ = delegate; | 72 delegate_ = delegate; |
| 74 request_info_ = request_info; | 73 request_info_ = request_info; |
| 75 | 74 |
| 76 stream_request_ = session_->CreateStreamRequest(); | 75 stream_request_ = |
| 76 session_->CreateStreamRequest(request_info_->method == "POST"); |
| 77 int rv = stream_request_->StartRequest(base::Bind( | 77 int rv = stream_request_->StartRequest(base::Bind( |
| 78 &BidirectionalStreamQuicImpl::OnStreamReady, weak_factory_.GetWeakPtr())); | 78 &BidirectionalStreamQuicImpl::OnStreamReady, weak_factory_.GetWeakPtr())); |
| 79 if (rv == ERR_IO_PENDING) |
| 80 return; |
| 81 |
| 79 if (rv == OK) { | 82 if (rv == OK) { |
| 80 OnStreamReady(rv); | 83 OnStreamReady(rv); |
| 81 } else if (!was_handshake_confirmed_) { | 84 } else if (!was_handshake_confirmed_) { |
| 82 NotifyError(ERR_QUIC_HANDSHAKE_FAILED); | 85 NotifyError(ERR_QUIC_HANDSHAKE_FAILED); |
| 83 } | 86 } |
| 84 } | 87 } |
| 85 | 88 |
| 86 void BidirectionalStreamQuicImpl::SendRequestHeaders() { | 89 void BidirectionalStreamQuicImpl::SendRequestHeaders() { |
| 87 DCHECK(!has_sent_headers_); | 90 DCHECK(!has_sent_headers_); |
| 88 if (!stream_) { | 91 if (!stream_) { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 void BidirectionalStreamQuicImpl::OnError(int error) { | 282 void BidirectionalStreamQuicImpl::OnError(int error) { |
| 280 NotifyError(error); | 283 NotifyError(error); |
| 281 } | 284 } |
| 282 | 285 |
| 283 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() { | 286 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() { |
| 284 return has_sent_headers_; | 287 return has_sent_headers_; |
| 285 } | 288 } |
| 286 | 289 |
| 287 void BidirectionalStreamQuicImpl::OnCryptoHandshakeConfirmed() { | 290 void BidirectionalStreamQuicImpl::OnCryptoHandshakeConfirmed() { |
| 288 was_handshake_confirmed_ = true; | 291 was_handshake_confirmed_ = true; |
| 289 if (waiting_for_confirmation_) | |
| 290 NotifyStreamReady(); | |
| 291 } | 292 } |
| 292 | 293 |
| 293 void BidirectionalStreamQuicImpl::OnSuccessfulVersionNegotiation( | 294 void BidirectionalStreamQuicImpl::OnSuccessfulVersionNegotiation( |
| 294 const QuicVersion& version) {} | 295 const QuicVersion& version) {} |
| 295 | 296 |
| 296 void BidirectionalStreamQuicImpl::OnSessionClosed( | 297 void BidirectionalStreamQuicImpl::OnSessionClosed( |
| 297 int error, | 298 int error, |
| 298 bool /*port_migration_detected*/) { | 299 bool /*port_migration_detected*/) { |
| 299 DCHECK_NE(OK, error); | 300 DCHECK_NE(OK, error); |
| 300 session_.reset(); | 301 session_.reset(); |
| 301 NotifyError(error); | 302 NotifyError(error); |
| 302 } | 303 } |
| 303 | 304 |
| 304 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { | 305 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { |
| 305 DCHECK_NE(ERR_IO_PENDING, rv); | 306 DCHECK_NE(ERR_IO_PENDING, rv); |
| 306 DCHECK(rv == OK || !stream_); | 307 DCHECK(rv == OK || !stream_); |
| 307 if (rv == OK) { | 308 if (rv == OK) { |
| 308 stream_ = stream_request_->ReleaseStream(); | 309 stream_ = stream_request_->ReleaseStream(); |
| 309 stream_request_.reset(); | 310 stream_request_.reset(); |
| 310 stream_->SetDelegate(this); | 311 stream_->SetDelegate(this); |
| 311 if (!was_handshake_confirmed_ && request_info_->method == "POST") { | |
| 312 waiting_for_confirmation_ = true; | |
| 313 return; | |
| 314 } | |
| 315 NotifyStreamReady(); | 312 NotifyStreamReady(); |
| 316 } else { | 313 } else { |
| 317 NotifyError(rv); | 314 NotifyError(rv); |
| 318 } | 315 } |
| 319 } | 316 } |
| 320 | 317 |
| 321 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { | 318 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { |
| 322 DCHECK(rv == OK || !stream_); | 319 DCHECK(rv == OK || !stream_); |
| 323 if (rv == OK) { | 320 if (rv == OK) { |
| 324 if (delegate_) | 321 if (delegate_) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 if (!stream_) | 353 if (!stream_) |
| 357 return; | 354 return; |
| 358 closed_stream_received_bytes_ = stream_->stream_bytes_read(); | 355 closed_stream_received_bytes_ = stream_->stream_bytes_read(); |
| 359 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 356 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 360 closed_is_first_stream_ = stream_->IsFirstStream(); | 357 closed_is_first_stream_ = stream_->IsFirstStream(); |
| 361 stream_->SetDelegate(nullptr); | 358 stream_->SetDelegate(nullptr); |
| 362 stream_ = nullptr; | 359 stream_ = nullptr; |
| 363 } | 360 } |
| 364 | 361 |
| 365 } // namespace net | 362 } // namespace net |
| OLD | NEW |