Index: net/spdy/spdy_stream.cc |
diff --git a/net/spdy/spdy_stream.cc b/net/spdy/spdy_stream.cc |
index e20fb8d73125baa10d1316d87830d6663f87fae9..8d97f3dc6c87d3c3e538b7d500b05fbb4f1eef97 100644 |
--- a/net/spdy/spdy_stream.cc |
+++ b/net/spdy/spdy_stream.cc |
@@ -83,35 +83,33 @@ SpdyStream::SpdyStream(SpdySession* session, |
domain_bound_cert_type_(CLIENT_CERT_INVALID_TYPE) { |
} |
-class SpdyStream::SpdyStreamIOBufferProducer |
- : public SpdySession::SpdyIOBufferProducer { |
+// A wrapper around a stream that calls into ProduceNextFrame(). |
+class SpdyStream::SpdyStreamFrameProducer : public SpdyFrameProducer { |
public: |
- SpdyStreamIOBufferProducer(SpdyStream* stream) : stream_(stream) {} |
+ SpdyStreamFrameProducer(const scoped_refptr<SpdyStream>& stream) |
+ : stream_(stream) { |
+ DCHECK(stream_); |
+ } |
+ |
+ virtual ~SpdyStreamFrameProducer() {} |
- // SpdyFrameProducer |
- virtual RequestPriority GetPriority() const OVERRIDE { |
- return stream_->priority(); |
+ virtual SpdyStream* GetStream() OVERRIDE { |
+ return stream_.get(); |
} |
- virtual SpdyIOBuffer* ProduceNextBuffer(SpdySession* session) OVERRIDE { |
- if (stream_->cancelled()) |
- return NULL; |
- if (stream_->stream_id() == 0) |
- SpdySession::SpdyIOBufferProducer::ActivateStream(session, stream_); |
- frame_ = stream_->ProduceNextFrame(); |
- return frame_ == NULL ? NULL : |
- SpdySession::SpdyIOBufferProducer::CreateIOBuffer( |
- frame_.get(), GetPriority(), stream_); |
+ virtual scoped_ptr<SpdyFrame> ProduceFrame() OVERRIDE { |
+ DCHECK_GT(stream_->stream_id(), 0u); |
+ return stream_->ProduceNextFrame(); |
} |
private: |
- scoped_refptr<SpdyStream> stream_; |
- scoped_ptr<SpdyFrame> frame_; |
+ const scoped_refptr<SpdyStream> stream_; |
}; |
void SpdyStream::SetHasWriteAvailable() { |
- session_->SetStreamHasWriteAvailable(this, |
- new SpdyStreamIOBufferProducer(this)); |
+ session_->SetStreamHasWriteAvailable( |
+ this, |
+ scoped_ptr<SpdyFrameProducer>(new SpdyStreamFrameProducer(this))); |
} |
scoped_ptr<SpdyFrame> SpdyStream::ProduceNextFrame() { |
@@ -126,7 +124,9 @@ scoped_ptr<SpdyFrame> SpdyStream::ProduceNextFrame() { |
origin, domain_bound_cert_type_, domain_bound_private_key_, |
domain_bound_cert_, priority_)); |
return frame.Pass(); |
- } else if (io_state_ == STATE_SEND_HEADERS_COMPLETE) { |
+ } |
+ |
+ if (io_state_ == STATE_SEND_HEADERS_COMPLETE) { |
CHECK(request_.get()); |
CHECK_GT(stream_id_, 0u); |
@@ -136,34 +136,33 @@ scoped_ptr<SpdyFrame> SpdyStream::ProduceNextFrame() { |
stream_id_, priority_, slot_, flags, *request_)); |
send_time_ = base::TimeTicks::Now(); |
return frame.Pass(); |
- } else { |
- CHECK(!cancelled()); |
- // We must need to write stream data. |
- // Until the headers have been completely sent, we can not be sure |
- // that our stream_id is correct. |
- DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); |
- DCHECK_GT(stream_id_, 0u); |
- DCHECK(!pending_frames_.empty()); |
- |
- PendingFrame frame = pending_frames_.front(); |
- pending_frames_.pop_front(); |
- |
- waiting_completions_.push_back(frame.type); |
- |
- if (frame.type == TYPE_DATA) { |
- // Send queued data frame. |
- return scoped_ptr<SpdyFrame>(frame.data_frame); |
- } else { |
- DCHECK(frame.type == TYPE_HEADERS); |
- // Create actual HEADERS frame just in time because it depends on |
- // compression context and should not be reordered after the creation. |
- scoped_ptr<SpdyFrame> header_frame(session_->CreateHeadersFrame( |
- stream_id_, *frame.header_block, SpdyControlFlags())); |
- delete frame.header_block; |
- return header_frame.Pass(); |
- } |
} |
- NOTREACHED(); |
+ |
+ CHECK(!cancelled()); |
+ // We must need to write stream data. |
+ // Until the headers have been completely sent, we can not be sure |
+ // that our stream_id is correct. |
+ DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); |
+ DCHECK_GT(stream_id_, 0u); |
+ DCHECK(!pending_frames_.empty()); |
+ |
+ PendingFrame frame = pending_frames_.front(); |
+ pending_frames_.pop_front(); |
+ |
+ waiting_completions_.push_back(frame.type); |
+ |
+ if (frame.type == TYPE_DATA) { |
+ // Send queued data frame. |
+ return scoped_ptr<SpdyFrame>(frame.data_frame); |
+ } |
+ |
+ DCHECK(frame.type == TYPE_HEADERS); |
+ // Create actual HEADERS frame just in time because it depends on |
+ // compression context and should not be reordered after the creation. |
+ scoped_ptr<SpdyFrame> header_frame(session_->CreateHeadersFrame( |
+ stream_id_, *frame.header_block, SpdyControlFlags())); |
+ delete frame.header_block; |
+ return header_frame.Pass(); |
} |
SpdyStream::~SpdyStream() { |