Chromium Code Reviews| 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/bidirectional_stream_quic_impl.h" | 5 #include "net/quic/bidirectional_stream_quic_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 response_status_(OK), | 26 response_status_(OK), |
| 27 negotiated_protocol_(kProtoUnknown), | 27 negotiated_protocol_(kProtoUnknown), |
| 28 read_buffer_len_(0), | 28 read_buffer_len_(0), |
| 29 headers_bytes_received_(0), | 29 headers_bytes_received_(0), |
| 30 headers_bytes_sent_(0), | 30 headers_bytes_sent_(0), |
| 31 closed_stream_received_bytes_(0), | 31 closed_stream_received_bytes_(0), |
| 32 closed_stream_sent_bytes_(0), | 32 closed_stream_sent_bytes_(0), |
| 33 has_sent_headers_(false), | 33 has_sent_headers_(false), |
| 34 has_received_headers_(false), | 34 has_received_headers_(false), |
| 35 send_request_headers_automatically_(true), | 35 send_request_headers_automatically_(true), |
| 36 waiting_for_confirmation_(false), | |
| 36 weak_factory_(this) { | 37 weak_factory_(this) { |
| 37 DCHECK(session_); | 38 DCHECK(session_); |
| 38 session_->AddObserver(this); | 39 session_->AddObserver(this); |
| 39 } | 40 } |
| 40 | 41 |
| 41 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { | 42 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { |
| 42 Cancel(); | 43 Cancel(); |
| 43 if (session_) | 44 if (session_) |
| 44 session_->RemoveObserver(this); | 45 session_->RemoveObserver(this); |
| 45 } | 46 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 void BidirectionalStreamQuicImpl::OnError(int error) { | 275 void BidirectionalStreamQuicImpl::OnError(int error) { |
| 275 NotifyError(error); | 276 NotifyError(error); |
| 276 } | 277 } |
| 277 | 278 |
| 278 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() { | 279 bool BidirectionalStreamQuicImpl::HasSendHeadersComplete() { |
| 279 return has_sent_headers_; | 280 return has_sent_headers_; |
| 280 } | 281 } |
| 281 | 282 |
| 282 void BidirectionalStreamQuicImpl::OnCryptoHandshakeConfirmed() { | 283 void BidirectionalStreamQuicImpl::OnCryptoHandshakeConfirmed() { |
| 283 was_handshake_confirmed_ = true; | 284 was_handshake_confirmed_ = true; |
| 285 if (waiting_for_confirmation_) | |
| 286 StartStream(); | |
| 284 } | 287 } |
| 285 | 288 |
| 286 void BidirectionalStreamQuicImpl::OnSessionClosed( | 289 void BidirectionalStreamQuicImpl::OnSessionClosed( |
| 287 int error, | 290 int error, |
| 288 bool /*port_migration_detected*/) { | 291 bool /*port_migration_detected*/) { |
| 289 DCHECK_NE(OK, error); | 292 DCHECK_NE(OK, error); |
| 290 session_.reset(); | 293 session_.reset(); |
| 291 NotifyError(error); | 294 NotifyError(error); |
| 292 } | 295 } |
| 293 | 296 |
| 294 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { | 297 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { |
| 295 DCHECK_NE(ERR_IO_PENDING, rv); | 298 DCHECK_NE(ERR_IO_PENDING, rv); |
| 296 DCHECK(rv == OK || !stream_); | 299 DCHECK(rv == OK || !stream_); |
| 297 if (rv == OK) { | 300 if (rv == OK) { |
| 298 stream_->SetDelegate(this); | 301 stream_->SetDelegate(this); |
| 299 if (send_request_headers_automatically_) { | 302 if (!was_handshake_confirmed_ && request_info_->method == "POST") { |
|
xunjieli
2016/06/16 22:52:13
If |was_handshake_confirmed_| is false and method
xunjieli
2016/06/17 01:31:46
Ah, nvm. It won't happen. I was reading the code w
| |
| 300 SendRequestHeaders(); | 303 waiting_for_confirmation_ = true; |
| 304 return; | |
| 301 } | 305 } |
| 302 if (delegate_) | 306 StartStream(); |
| 303 delegate_->OnStreamReady(has_sent_headers_); | |
| 304 } else { | 307 } else { |
| 305 NotifyError(rv); | 308 NotifyError(rv); |
| 306 } | 309 } |
| 307 } | 310 } |
| 308 | 311 |
| 312 void BidirectionalStreamQuicImpl::StartStream() { | |
| 313 if (send_request_headers_automatically_) { | |
| 314 SendRequestHeaders(); | |
| 315 } | |
| 316 if (delegate_) | |
| 317 delegate_->OnStreamReady(has_sent_headers_); | |
| 318 } | |
| 319 | |
| 309 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { | 320 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { |
| 310 DCHECK(rv == OK || !stream_); | 321 DCHECK(rv == OK || !stream_); |
| 311 if (rv == OK) { | 322 if (rv == OK) { |
| 312 if (delegate_) | 323 if (delegate_) |
| 313 delegate_->OnDataSent(); | 324 delegate_->OnDataSent(); |
| 314 } else { | 325 } else { |
| 315 NotifyError(rv); | 326 NotifyError(rv); |
| 316 } | 327 } |
| 317 } | 328 } |
| 318 | 329 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 335 void BidirectionalStreamQuicImpl::ResetStream() { | 346 void BidirectionalStreamQuicImpl::ResetStream() { |
| 336 if (!stream_) | 347 if (!stream_) |
| 337 return; | 348 return; |
| 338 closed_stream_received_bytes_ = stream_->stream_bytes_read(); | 349 closed_stream_received_bytes_ = stream_->stream_bytes_read(); |
| 339 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 350 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 340 stream_->SetDelegate(nullptr); | 351 stream_->SetDelegate(nullptr); |
| 341 stream_ = nullptr; | 352 stream_ = nullptr; |
| 342 } | 353 } |
| 343 | 354 |
| 344 } // namespace net | 355 } // namespace net |
| OLD | NEW |