Chromium Code Reviews| 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/spdy/spdy_stream.h" | 5 #include "net/spdy/spdy_stream.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 CHECK_EQ(type_, SPDY_PUSH_STREAM); | 473 CHECK_EQ(type_, SPDY_PUSH_STREAM); |
| 474 DCHECK(!delegate_); | 474 DCHECK(!delegate_); |
| 475 | 475 |
| 476 io_state_ = STATE_RESERVED_REMOTE; | 476 io_state_ = STATE_RESERVED_REMOTE; |
| 477 request_headers_.reset(new SpdyHeaderBlock(headers)); | 477 request_headers_.reset(new SpdyHeaderBlock(headers)); |
| 478 } | 478 } |
| 479 | 479 |
| 480 void SpdyStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { | 480 void SpdyStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { |
| 481 DCHECK(session_->IsStreamActive(stream_id_)); | 481 DCHECK(session_->IsStreamActive(stream_id_)); |
| 482 | 482 |
| 483 // Track our bandwidth. | |
| 484 recv_bytes_ += buffer ? buffer->GetRemainingSize() : 0; | |
| 485 recv_last_byte_time_ = base::TimeTicks::Now(); | |
| 486 | |
| 483 // If we're still buffering data for a push stream, we will do the | 487 // If we're still buffering data for a push stream, we will do the |
| 484 // check for data received with incomplete headers in | 488 // check for data received with incomplete headers in |
| 485 // PushedStreamReplayData(). | 489 // PushedStreamReplayData(). |
| 486 if (io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED) { | 490 if (io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED) { |
| 487 DCHECK_EQ(type_, SPDY_PUSH_STREAM); | 491 DCHECK_EQ(type_, SPDY_PUSH_STREAM); |
| 488 // It should be valid for this to happen in the server push case. | 492 // It should be valid for this to happen in the server push case. |
| 489 // We'll return received data when delegate gets attached to the stream. | 493 // We'll return received data when delegate gets attached to the stream. |
| 490 if (buffer) { | 494 if (buffer) { |
| 491 pending_recv_data_.push_back(std::move(buffer)); | 495 pending_recv_data_.push_back(std::move(buffer)); |
| 492 } else { | 496 } else { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 size_t length = buffer->GetRemainingSize(); | 538 size_t length = buffer->GetRemainingSize(); |
| 535 DCHECK_LE(length, session_->GetDataFrameMaximumPayload()); | 539 DCHECK_LE(length, session_->GetDataFrameMaximumPayload()); |
| 536 base::WeakPtr<SpdyStream> weak_this = GetWeakPtr(); | 540 base::WeakPtr<SpdyStream> weak_this = GetWeakPtr(); |
| 537 // May close the stream. | 541 // May close the stream. |
| 538 DecreaseRecvWindowSize(static_cast<int32_t>(length)); | 542 DecreaseRecvWindowSize(static_cast<int32_t>(length)); |
| 539 if (!weak_this) | 543 if (!weak_this) |
| 540 return; | 544 return; |
| 541 buffer->AddConsumeCallback( | 545 buffer->AddConsumeCallback( |
| 542 base::Bind(&SpdyStream::OnReadBufferConsumed, GetWeakPtr())); | 546 base::Bind(&SpdyStream::OnReadBufferConsumed, GetWeakPtr())); |
| 543 | 547 |
| 544 // Track our bandwidth. | |
| 545 recv_bytes_ += length; | |
| 546 recv_last_byte_time_ = base::TimeTicks::Now(); | |
| 547 | |
| 548 // May close |this|. | 548 // May close |this|. |
| 549 delegate_->OnDataReceived(std::move(buffer)); | 549 delegate_->OnDataReceived(std::move(buffer)); |
| 550 } | 550 } |
| 551 | 551 |
| 552 void SpdyStream::OnPaddingConsumed(size_t len) { | 552 void SpdyStream::OnPaddingConsumed(size_t len) { |
| 553 // Decrease window size because padding bytes are received. | 553 // Decrease window size because padding bytes are received. |
| 554 // Increase window size because padding bytes are consumed (by discarding). | 554 // Increase window size because padding bytes are consumed (by discarding). |
| 555 // Net result: |unacked_recv_window_bytes_| increases by |len|, | 555 // Net result: |unacked_recv_window_bytes_| increases by |len|, |
| 556 // |recv_window_size_| does not change. | 556 // |recv_window_size_| does not change. |
| 557 base::WeakPtr<SpdyStream> weak_this = GetWeakPtr(); | 557 base::WeakPtr<SpdyStream> weak_this = GetWeakPtr(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 569 frame_type == DATA) << frame_type; | 569 frame_type == DATA) << frame_type; |
| 570 | 570 |
| 571 int result = (frame_type == SYN_STREAM) ? | 571 int result = (frame_type == SYN_STREAM) ? |
| 572 OnRequestHeadersSent() : OnDataSent(frame_size); | 572 OnRequestHeadersSent() : OnDataSent(frame_size); |
| 573 if (result == ERR_IO_PENDING) { | 573 if (result == ERR_IO_PENDING) { |
| 574 // The write operation hasn't completed yet. | 574 // The write operation hasn't completed yet. |
| 575 return; | 575 return; |
| 576 } | 576 } |
| 577 | 577 |
| 578 if (pending_send_status_ == NO_MORE_DATA_TO_SEND) { | 578 if (pending_send_status_ == NO_MORE_DATA_TO_SEND) { |
| 579 if(io_state_ == STATE_OPEN) { | 579 if (io_state_ == STATE_OPEN) { |
| 580 io_state_ = STATE_HALF_CLOSED_LOCAL; | 580 io_state_ = STATE_HALF_CLOSED_LOCAL; |
| 581 } else if(io_state_ == STATE_HALF_CLOSED_REMOTE) { | 581 } else if (io_state_ == STATE_HALF_CLOSED_REMOTE) { |
| 582 io_state_ = STATE_CLOSED; | 582 io_state_ = STATE_CLOSED; |
| 583 } else { | 583 } else { |
| 584 NOTREACHED() << io_state_; | 584 NOTREACHED() << io_state_; |
| 585 } | 585 } |
| 586 } | 586 } |
| 587 // Notify delegate of write completion. Must not destroy |this|. | 587 // Notify delegate of write completion. Must not destroy |this|. |
| 588 CHECK(delegate_); | 588 CHECK(delegate_); |
| 589 { | 589 { |
| 590 base::WeakPtr<SpdyStream> weak_this = GetWeakPtr(); | 590 base::WeakPtr<SpdyStream> weak_this = GetWeakPtr(); |
| 591 write_handler_guard_ = true; | 591 write_handler_guard_ = true; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 raw_received_bytes_ += received_bytes; | 767 raw_received_bytes_ += received_bytes; |
| 768 } | 768 } |
| 769 | 769 |
| 770 void SpdyStream::AddRawSentBytes(size_t sent_bytes) { | 770 void SpdyStream::AddRawSentBytes(size_t sent_bytes) { |
| 771 raw_sent_bytes_ += sent_bytes; | 771 raw_sent_bytes_ += sent_bytes; |
| 772 } | 772 } |
| 773 | 773 |
| 774 bool SpdyStream::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { | 774 bool SpdyStream::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { |
| 775 if (stream_id_ == 0) | 775 if (stream_id_ == 0) |
| 776 return false; | 776 return false; |
| 777 | 777 bool result = session_->GetLoadTimingInfo(stream_id_, load_timing_info); |
| 778 return session_->GetLoadTimingInfo(stream_id_, load_timing_info); | 778 if (type_ == SPDY_PUSH_STREAM) { |
| 779 load_timing_info->push_start = recv_first_byte_time_; | |
| 780 bool done_receiving = IsClosed() || (!pending_recv_data_.empty() && | |
| 781 !pending_recv_data_.back()); | |
| 782 load_timing_info->push_end = | |
|
Bence
2016/03/25 14:42:54
How about this instead:
if (done_receiving) push_e
| |
| 783 done_receiving ? recv_last_byte_time_ : base::TimeTicks(); | |
| 784 } | |
| 785 return result; | |
| 779 } | 786 } |
| 780 | 787 |
| 781 GURL SpdyStream::GetUrlFromHeaders() const { | 788 GURL SpdyStream::GetUrlFromHeaders() const { |
| 782 if (!request_headers_) | 789 if (!request_headers_) |
| 783 return GURL(); | 790 return GURL(); |
| 784 | 791 |
| 785 return GetUrlFromHeaderBlock(*request_headers_, GetProtocolVersion()); | 792 return GetUrlFromHeaderBlock(*request_headers_, GetProtocolVersion()); |
| 786 } | 793 } |
| 787 | 794 |
| 788 bool SpdyStream::HasUrlFromHeaders() const { | 795 bool SpdyStream::HasUrlFromHeaders() const { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 951 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
| 945 state); | 952 state); |
| 946 break; | 953 break; |
| 947 } | 954 } |
| 948 return description; | 955 return description; |
| 949 } | 956 } |
| 950 | 957 |
| 951 #undef STATE_CASE | 958 #undef STATE_CASE |
| 952 | 959 |
| 953 } // namespace net | 960 } // namespace net |
| OLD | NEW |