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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 SpdyStream::~SpdyStream() { | 115 SpdyStream::~SpdyStream() { |
116 CHECK(!write_handler_guard_); | 116 CHECK(!write_handler_guard_); |
117 UpdateHistograms(); | 117 UpdateHistograms(); |
118 } | 118 } |
119 | 119 |
120 void SpdyStream::SetDelegate(Delegate* delegate) { | 120 void SpdyStream::SetDelegate(Delegate* delegate) { |
121 CHECK(!delegate_); | 121 CHECK(!delegate_); |
122 CHECK(delegate); | 122 CHECK(delegate); |
123 delegate_ = delegate; | 123 delegate_ = delegate; |
124 | 124 |
| 125 // TODO(baranovich): allow STATE_RESERVED_REMOTE when push promises will be |
| 126 // implemented. |
125 CHECK(io_state_ == STATE_IDLE || | 127 CHECK(io_state_ == STATE_IDLE || |
126 io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED); | 128 io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED); |
127 | 129 |
128 if (io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED) { | 130 if (io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED) { |
129 DCHECK_EQ(type_, SPDY_PUSH_STREAM); | 131 DCHECK_EQ(type_, SPDY_PUSH_STREAM); |
130 base::MessageLoop::current()->PostTask( | 132 base::MessageLoop::current()->PostTask( |
131 FROM_HERE, | 133 FROM_HERE, |
132 base::Bind(&SpdyStream::PushedStreamReplay, GetWeakPtr())); | 134 base::Bind(&SpdyStream::PushedStreamReplay, GetWeakPtr())); |
133 } | 135 } |
134 } | 136 } |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 session_->ResetStream(stream_id_, RST_STREAM_PROTOCOL_ERROR, | 412 session_->ResetStream(stream_id_, RST_STREAM_PROTOCOL_ERROR, |
411 "Response received before request sent"); | 413 "Response received before request sent"); |
412 return ERR_SPDY_PROTOCOL_ERROR; | 414 return ERR_SPDY_PROTOCOL_ERROR; |
413 } | 415 } |
414 break; | 416 break; |
415 | 417 |
416 case SPDY_PUSH_STREAM: | 418 case SPDY_PUSH_STREAM: |
417 // Push streams transition to a locally half-closed state upon headers. | 419 // Push streams transition to a locally half-closed state upon headers. |
418 // We must continue to buffer data while waiting for a call to | 420 // We must continue to buffer data while waiting for a call to |
419 // SetDelegate() (which may not ever happen). | 421 // SetDelegate() (which may not ever happen). |
420 // TODO(jgraettinger): When PUSH_PROMISE is added, Handle RESERVED_REMOTE | 422 // TODO(baranovich): For HTTP 2 push streams, delegate may be set before |
421 // cases here depending on whether the delegate is already set. | 423 // receiving response headers when PUSH_PROMISE will be implemented. |
422 CHECK_EQ(io_state_, STATE_IDLE); | 424 // TODO(baranovich): In HTTP 2 additional HEADERS frames are not allowed. |
| 425 // Set |response_headers_status_| to RESPONSE_HEADERS_ARE_COMPLETE. |
| 426 CHECK_EQ(io_state_, STATE_RESERVED_REMOTE); |
423 DCHECK(!delegate_); | 427 DCHECK(!delegate_); |
424 io_state_ = STATE_HALF_CLOSED_LOCAL_UNCLAIMED; | 428 io_state_ = STATE_HALF_CLOSED_LOCAL_UNCLAIMED; |
425 break; | 429 break; |
426 } | 430 } |
427 | 431 |
428 metrics_.StartStream(); | 432 metrics_.StartStream(); |
429 | 433 |
430 DCHECK_NE(io_state_, STATE_IDLE); | 434 DCHECK_NE(io_state_, STATE_IDLE); |
431 | 435 |
432 response_time_ = response_time; | 436 response_time_ = response_time; |
(...skipping 11 matching lines...) Expand all Loading... |
444 } else if (type_ == SPDY_PUSH_STREAM && | 448 } else if (type_ == SPDY_PUSH_STREAM && |
445 response_headers_status_ == RESPONSE_HEADERS_ARE_COMPLETE) { | 449 response_headers_status_ == RESPONSE_HEADERS_ARE_COMPLETE) { |
446 session_->ResetStream( | 450 session_->ResetStream( |
447 stream_id_, RST_STREAM_PROTOCOL_ERROR, | 451 stream_id_, RST_STREAM_PROTOCOL_ERROR, |
448 "Additional headers received for push stream"); | 452 "Additional headers received for push stream"); |
449 return ERR_SPDY_PROTOCOL_ERROR; | 453 return ERR_SPDY_PROTOCOL_ERROR; |
450 } | 454 } |
451 return MergeWithResponseHeaders(additional_response_headers); | 455 return MergeWithResponseHeaders(additional_response_headers); |
452 } | 456 } |
453 | 457 |
| 458 |
| 459 int SpdyStream::OnPushPromiseHeadersReceived(const SpdyHeaderBlock& headers) { |
| 460 CHECK(!request_headers_.get()); |
| 461 CHECK_EQ(io_state_, STATE_IDLE); |
| 462 CHECK_EQ(type_, SPDY_PUSH_STREAM); |
| 463 DCHECK(!delegate_); |
| 464 |
| 465 io_state_ = STATE_RESERVED_REMOTE; |
| 466 request_headers_.reset(new SpdyHeaderBlock(headers)); |
| 467 return OK; |
| 468 } |
| 469 |
454 void SpdyStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { | 470 void SpdyStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { |
455 DCHECK(session_->IsStreamActive(stream_id_)); | 471 DCHECK(session_->IsStreamActive(stream_id_)); |
456 | 472 |
457 // If we're still buffering data for a push stream, we will do the | 473 // If we're still buffering data for a push stream, we will do the |
458 // check for data received with incomplete headers in | 474 // check for data received with incomplete headers in |
459 // PushedStreamReplayData(). | 475 // PushedStreamReplayData(). |
460 if (io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED) { | 476 if (io_state_ == STATE_HALF_CLOSED_LOCAL_UNCLAIMED) { |
461 DCHECK_EQ(type_, SPDY_PUSH_STREAM); | 477 DCHECK_EQ(type_, SPDY_PUSH_STREAM); |
462 // It should be valid for this to happen in the server push case. | 478 // It should be valid for this to happen in the server push case. |
463 // We'll return received data when delegate gets attached to the stream. | 479 // We'll return received data when delegate gets attached to the stream. |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 } | 739 } |
724 | 740 |
725 bool SpdyStream::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { | 741 bool SpdyStream::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { |
726 if (stream_id_ == 0) | 742 if (stream_id_ == 0) |
727 return false; | 743 return false; |
728 | 744 |
729 return session_->GetLoadTimingInfo(stream_id_, load_timing_info); | 745 return session_->GetLoadTimingInfo(stream_id_, load_timing_info); |
730 } | 746 } |
731 | 747 |
732 GURL SpdyStream::GetUrlFromHeaders() const { | 748 GURL SpdyStream::GetUrlFromHeaders() const { |
733 if (type_ != SPDY_PUSH_STREAM && !request_headers_) | 749 if (!request_headers_) |
734 return GURL(); | 750 return GURL(); |
735 | 751 |
736 const SpdyHeaderBlock& headers = | 752 return GetUrlFromHeaderBlock(*request_headers_, GetProtocolVersion(), |
737 (type_ == SPDY_PUSH_STREAM) ? response_headers_ : *request_headers_; | |
738 return GetUrlFromHeaderBlock(headers, GetProtocolVersion(), | |
739 type_ == SPDY_PUSH_STREAM); | 753 type_ == SPDY_PUSH_STREAM); |
740 } | 754 } |
741 | 755 |
742 bool SpdyStream::HasUrlFromHeaders() const { | 756 bool SpdyStream::HasUrlFromHeaders() const { |
743 return !GetUrlFromHeaders().is_empty(); | 757 return !GetUrlFromHeaders().is_empty(); |
744 } | 758 } |
745 | 759 |
746 void SpdyStream::UpdateHistograms() { | 760 void SpdyStream::UpdateHistograms() { |
747 // We need at least the receive timers to be filled in, as otherwise | 761 // We need at least the receive timers to be filled in, as otherwise |
748 // metrics can be bogus. | 762 // metrics can be bogus. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 903 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
890 state); | 904 state); |
891 break; | 905 break; |
892 } | 906 } |
893 return description; | 907 return description; |
894 } | 908 } |
895 | 909 |
896 #undef STATE_CASE | 910 #undef STATE_CASE |
897 | 911 |
898 } // namespace net | 912 } // namespace net |
OLD | NEW |