| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 if (!callback_.is_null()) | 518 if (!callback_.is_null()) |
| 519 DoCallback(response_status_); | 519 DoCallback(response_status_); |
| 520 } | 520 } |
| 521 | 521 |
| 522 bool QuicHttpStream::HasSendHeadersComplete() { | 522 bool QuicHttpStream::HasSendHeadersComplete() { |
| 523 return next_state_ > STATE_SEND_HEADERS_COMPLETE; | 523 return next_state_ > STATE_SEND_HEADERS_COMPLETE; |
| 524 } | 524 } |
| 525 | 525 |
| 526 void QuicHttpStream::OnCryptoHandshakeConfirmed() { | 526 void QuicHttpStream::OnCryptoHandshakeConfirmed() { |
| 527 was_handshake_confirmed_ = true; | 527 was_handshake_confirmed_ = true; |
| 528 if (next_state_ == STATE_WAIT_FOR_CONFIRMATION_COMPLETE) { |
| 529 int rv = DoLoop(OK); |
| 530 |
| 531 if (rv != ERR_IO_PENDING && !callback_.is_null()) { |
| 532 DoCallback(rv); |
| 533 } |
| 534 } |
| 528 } | 535 } |
| 529 | 536 |
| 530 void QuicHttpStream::OnSessionClosed(int error, bool port_migration_detected) { | 537 void QuicHttpStream::OnSessionClosed(int error, bool port_migration_detected) { |
| 531 Close(false); | 538 Close(false); |
| 532 session_error_ = error; | 539 session_error_ = error; |
| 533 port_migration_detected_ = port_migration_detected; | 540 port_migration_detected_ = port_migration_detected; |
| 534 session_.reset(); | 541 session_.reset(); |
| 535 } | 542 } |
| 536 | 543 |
| 537 void QuicHttpStream::OnIOComplete(int rv) { | 544 void QuicHttpStream::OnIOComplete(int rv) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 555 do { | 562 do { |
| 556 State state = next_state_; | 563 State state = next_state_; |
| 557 next_state_ = STATE_NONE; | 564 next_state_ = STATE_NONE; |
| 558 switch (state) { | 565 switch (state) { |
| 559 case STATE_REQUEST_STREAM: | 566 case STATE_REQUEST_STREAM: |
| 560 rv = DoStreamRequest(); | 567 rv = DoStreamRequest(); |
| 561 break; | 568 break; |
| 562 case STATE_SET_REQUEST_PRIORITY: | 569 case STATE_SET_REQUEST_PRIORITY: |
| 563 rv = DoSetRequestPriority(); | 570 rv = DoSetRequestPriority(); |
| 564 break; | 571 break; |
| 572 case STATE_WAIT_FOR_CONFIRMATION: |
| 573 CHECK_EQ(OK, rv); |
| 574 rv = DoWaitForConfirmation(); |
| 575 break; |
| 576 case STATE_WAIT_FOR_CONFIRMATION_COMPLETE: |
| 577 rv = DoWaitForConfirmationComplete(rv); |
| 578 break; |
| 565 case STATE_SEND_HEADERS: | 579 case STATE_SEND_HEADERS: |
| 566 CHECK_EQ(OK, rv); | 580 CHECK_EQ(OK, rv); |
| 567 rv = DoSendHeaders(); | 581 rv = DoSendHeaders(); |
| 568 break; | 582 break; |
| 569 case STATE_SEND_HEADERS_COMPLETE: | 583 case STATE_SEND_HEADERS_COMPLETE: |
| 570 rv = DoSendHeadersComplete(rv); | 584 rv = DoSendHeadersComplete(rv); |
| 571 break; | 585 break; |
| 572 case STATE_READ_REQUEST_BODY: | 586 case STATE_READ_REQUEST_BODY: |
| 573 CHECK_EQ(OK, rv); | 587 CHECK_EQ(OK, rv); |
| 574 rv = DoReadRequestBody(); | 588 rv = DoReadRequestBody(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 if (response_info_) { | 628 if (response_info_) { |
| 615 next_state_ = STATE_SET_REQUEST_PRIORITY; | 629 next_state_ = STATE_SET_REQUEST_PRIORITY; |
| 616 } | 630 } |
| 617 } else if (rv != ERR_IO_PENDING && !was_handshake_confirmed_) { | 631 } else if (rv != ERR_IO_PENDING && !was_handshake_confirmed_) { |
| 618 rv = ERR_QUIC_HANDSHAKE_FAILED; | 632 rv = ERR_QUIC_HANDSHAKE_FAILED; |
| 619 } | 633 } |
| 620 return rv; | 634 return rv; |
| 621 } | 635 } |
| 622 | 636 |
| 623 int QuicHttpStream::DoSetRequestPriority() { | 637 int QuicHttpStream::DoSetRequestPriority() { |
| 624 // Set priority according to request and, and advance to | 638 // Set priority according to request |
| 625 // STATE_SEND_HEADERS. | |
| 626 DCHECK(stream_); | 639 DCHECK(stream_); |
| 627 DCHECK(response_info_); | 640 DCHECK(response_info_); |
| 628 SpdyPriority priority = ConvertRequestPriorityToQuicPriority(priority_); | 641 SpdyPriority priority = ConvertRequestPriorityToQuicPriority(priority_); |
| 629 stream_->SetPriority(priority); | 642 stream_->SetPriority(priority); |
| 643 next_state_ = STATE_WAIT_FOR_CONFIRMATION; |
| 644 return OK; |
| 645 } |
| 646 |
| 647 int QuicHttpStream::DoWaitForConfirmation() { |
| 648 next_state_ = STATE_WAIT_FOR_CONFIRMATION_COMPLETE; |
| 649 if (!session_->IsCryptoHandshakeConfirmed() && |
| 650 request_info_->method == "POST") { |
| 651 return ERR_IO_PENDING; |
| 652 } |
| 653 return OK; |
| 654 } |
| 655 |
| 656 int QuicHttpStream::DoWaitForConfirmationComplete(int rv) { |
| 657 if (rv < 0) |
| 658 return rv; |
| 659 |
| 630 next_state_ = STATE_SEND_HEADERS; | 660 next_state_ = STATE_SEND_HEADERS; |
| 631 return OK; | 661 return OK; |
| 632 } | 662 } |
| 633 | 663 |
| 634 int QuicHttpStream::DoSendHeaders() { | 664 int QuicHttpStream::DoSendHeaders() { |
| 635 if (!stream_) | 665 if (!stream_) |
| 636 return ERR_UNEXPECTED; | 666 return ERR_UNEXPECTED; |
| 637 | 667 |
| 638 // Log the actual request with the URL Request's net log. | 668 // Log the actual request with the URL Request's net log. |
| 639 stream_net_log_.AddEvent( | 669 stream_net_log_.AddEvent( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 808 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 779 stream_ = nullptr; | 809 stream_ = nullptr; |
| 780 | 810 |
| 781 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress | 811 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress |
| 782 // read. | 812 // read. |
| 783 if (request_body_stream_) | 813 if (request_body_stream_) |
| 784 request_body_stream_->Reset(); | 814 request_body_stream_->Reset(); |
| 785 } | 815 } |
| 786 | 816 |
| 787 } // namespace net | 817 } // namespace net |
| OLD | NEW |