| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 // Spurrious notification. Wait for the next one. | 261 // Spurrious notification. Wait for the next one. |
| 262 return; | 262 return; |
| 263 } | 263 } |
| 264 read_buffer_ = nullptr; | 264 read_buffer_ = nullptr; |
| 265 read_buffer_len_ = 0; | 265 read_buffer_len_ = 0; |
| 266 if (delegate_) | 266 if (delegate_) |
| 267 delegate_->OnDataRead(rv); | 267 delegate_->OnDataRead(rv); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void BidirectionalStreamQuicImpl::OnClose() { | 270 void BidirectionalStreamQuicImpl::OnClose() { |
| 271 DCHECK(session_); |
| 271 DCHECK(stream_); | 272 DCHECK(stream_); |
| 272 | 273 |
| 273 if (stream_->connection_error() == QUIC_NO_ERROR && | 274 if (stream_->connection_error() != QUIC_NO_ERROR || |
| 274 stream_->stream_error() == QUIC_STREAM_NO_ERROR) { | 275 stream_->stream_error() != QUIC_STREAM_NO_ERROR) { |
| 275 ResetStream(); | 276 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR |
| 277 : ERR_QUIC_HANDSHAKE_FAILED); |
| 276 return; | 278 return; |
| 277 } | 279 } |
| 278 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR | 280 |
| 279 : ERR_QUIC_HANDSHAKE_FAILED); | 281 if (!stream_->fin_sent() || !stream_->fin_received()) { |
| 282 // The connection must have been closed by the peer with QUIC_NO_ERROR, |
| 283 // which is improper. |
| 284 NotifyError(ERR_UNEXPECTED); |
| 285 return; |
| 286 } |
| 287 |
| 288 // The connection was closed normally so there is no need to notify |
| 289 // the delegate. |
| 290 ResetStream(); |
| 280 } | 291 } |
| 281 | 292 |
| 282 void BidirectionalStreamQuicImpl::OnError(int error) { | 293 void BidirectionalStreamQuicImpl::OnError(int error) { |
| 283 NotifyError(error); | 294 NotifyError(error); |
| 284 } | 295 } |
| 285 | 296 |
| 286 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() { | 297 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() { |
| 287 return has_sent_headers_; | 298 return has_sent_headers_; |
| 288 } | 299 } |
| 289 | 300 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 354 |
| 344 void BidirectionalStreamQuicImpl::NotifyStreamReady() { | 355 void BidirectionalStreamQuicImpl::NotifyStreamReady() { |
| 345 if (send_request_headers_automatically_) { | 356 if (send_request_headers_automatically_) { |
| 346 SendRequestHeaders(); | 357 SendRequestHeaders(); |
| 347 } | 358 } |
| 348 if (delegate_) | 359 if (delegate_) |
| 349 delegate_->OnStreamReady(has_sent_headers_); | 360 delegate_->OnStreamReady(has_sent_headers_); |
| 350 } | 361 } |
| 351 | 362 |
| 352 void BidirectionalStreamQuicImpl::ResetStream() { | 363 void BidirectionalStreamQuicImpl::ResetStream() { |
| 364 if (session_) { |
| 365 session_->RemoveObserver(this); |
| 366 session_ = nullptr; |
| 367 } |
| 368 |
| 353 if (!stream_) | 369 if (!stream_) |
| 354 return; | 370 return; |
| 355 closed_stream_received_bytes_ = stream_->stream_bytes_read(); | 371 closed_stream_received_bytes_ = stream_->stream_bytes_read(); |
| 356 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 372 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 357 closed_is_first_stream_ = stream_->IsFirstStream(); | 373 closed_is_first_stream_ = stream_->IsFirstStream(); |
| 358 stream_->SetDelegate(nullptr); | 374 stream_->SetDelegate(nullptr); |
| 359 stream_ = nullptr; | 375 stream_ = nullptr; |
| 360 } | 376 } |
| 361 | 377 |
| 362 } // namespace net | 378 } // namespace net |
| OLD | NEW |