diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 00:22:33 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 00:22:33 +0000 |
commit | edbfa8c3e18e952bf497930350a30ce3ed9b8f44 (patch) | |
tree | 9c9a482bdcbcab15ab3871ef09c625aecf2d3ba6 /net/spdy | |
parent | 041834525ed2e88ecdd260f449011d778fe6cf2a (diff) | |
download | chromium_src-edbfa8c3e18e952bf497930350a30ce3ed9b8f44.zip chromium_src-edbfa8c3e18e952bf497930350a30ce3ed9b8f44.tar.gz chromium_src-edbfa8c3e18e952bf497930350a30ce3ed9b8f44.tar.bz2 |
[SPDY] Refactor SpdyStream::Delegate
Merge some member functions and rename others.
Clean up SpdyHttpStream logic a bit.
BUG=243643
Review URL: https://chromiumcodereview.appspot.com/15936003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202703 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_http_stream.cc | 80 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream.h | 28 | ||||
-rw-r--r-- | net/spdy/spdy_proxy_client_socket.cc | 18 | ||||
-rw-r--r-- | net/spdy/spdy_proxy_client_socket.h | 10 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_session_spdy3_unittest.cc | 4 | ||||
-rw-r--r-- | net/spdy/spdy_stream.cc | 34 | ||||
-rw-r--r-- | net/spdy/spdy_stream.h | 53 | ||||
-rw-r--r-- | net/spdy/spdy_stream_spdy2_unittest.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_stream_spdy3_unittest.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_stream_test_util.cc | 51 | ||||
-rw-r--r-- | net/spdy/spdy_stream_test_util.h | 36 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream.cc | 14 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream.h | 17 |
14 files changed, 134 insertions, 217 deletions
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc index a3f905e..2115787 100644 --- a/net/spdy/spdy_http_stream.cc +++ b/net/spdy/spdy_http_stream.cc @@ -33,11 +33,10 @@ SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session, closed_stream_status_(ERR_FAILED), closed_stream_id_(0), request_info_(NULL), - has_upload_data_(false), response_info_(NULL), response_headers_received_(false), user_buffer_len_(0), - raw_request_body_buf_size_(0), + request_body_buf_size_(0), buffered_read_callback_pending_(false), more_read_data_pending_(false), direct_(direct) {} @@ -98,7 +97,7 @@ const HttpResponseInfo* SpdyHttpStream::GetResponseInfo() const { } UploadProgress SpdyHttpStream::GetUploadProgress() const { - if (!request_info_ || !request_info_->upload_data_stream) + if (!HasUploadData()) return UploadProgress(); return UploadProgress(request_info_->upload_data_stream->position(), @@ -219,16 +218,13 @@ int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, if (response_info_) response_info_->request_time = request_time; - CHECK(!has_upload_data_); - has_upload_data_ = request_info_->upload_data_stream && - (request_info_->upload_data_stream->size() || - request_info_->upload_data_stream->is_chunked()); - if (has_upload_data_) { + CHECK(!request_body_buf_); + if (HasUploadData()) { // Use kMaxSpdyFrameChunkSize as the buffer size, since the request // body data is written with this size at a time. - raw_request_body_buf_ = new IOBufferWithSize(kMaxSpdyFrameChunkSize); + request_body_buf_ = new IOBufferWithSize(kMaxSpdyFrameChunkSize); // The request body buffer is empty at first. - raw_request_body_buf_size_ = 0; + request_body_buf_size_ = 0; } CHECK(!callback.is_null()); @@ -274,7 +270,7 @@ int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, result = stream_->SendRequestHeaders( headers.Pass(), - has_upload_data_ ? MORE_DATA_TO_SEND : NO_MORE_DATA_TO_SEND); + HasUploadData() ? MORE_DATA_TO_SEND : NO_MORE_DATA_TO_SEND); } if (result == ERR_IO_PENDING) { @@ -292,31 +288,17 @@ void SpdyHttpStream::Cancel() { } } -void SpdyHttpStream::OnSendRequestHeadersComplete() { +void SpdyHttpStream::OnRequestHeadersSent() { if (!callback_.is_null()) DoCallback(OK); -} -void SpdyHttpStream::OnSendBody() { - CHECK(request_info_ && request_info_->upload_data_stream); - if (raw_request_body_buf_size_ > 0) { - SendRequestBodyData(); - } else { - // We shouldn't be called if there's no more data to read. - CHECK(!request_info_->upload_data_stream->IsEOF()); + if (HasUploadData()) ReadAndSendRequestBodyData(); - } } -void SpdyHttpStream::OnSendBodyComplete() { - // |status| is the number of bytes written to the SPDY stream. - CHECK(request_info_ && request_info_->upload_data_stream); - raw_request_body_buf_size_ = 0; -} - -int SpdyHttpStream::OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) { +int SpdyHttpStream::OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) { if (!response_info_) { DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); push_response_info_.reset(new HttpResponseInfo); @@ -399,9 +381,8 @@ int SpdyHttpStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { } void SpdyHttpStream::OnDataSent() { - // For HTTP streams, no data is sent from the client while in the OPEN state, - // so it is never called. - CHECK(false); + request_body_buf_size_ = 0; + ReadAndSendRequestBodyData(); } void SpdyHttpStream::OnClose(int status) { @@ -420,6 +401,14 @@ void SpdyHttpStream::OnClose(int status) { DoCallback(status); } +bool SpdyHttpStream::HasUploadData() const { + CHECK(request_info_); + return + request_info_->upload_data_stream && + ((request_info_->upload_data_stream->size() > 0) || + request_info_->upload_data_stream->is_chunked()); +} + void SpdyHttpStream::OnStreamCreated( const CompletionCallback& callback, int rv) { @@ -431,12 +420,15 @@ void SpdyHttpStream::OnStreamCreated( } void SpdyHttpStream::ReadAndSendRequestBodyData() { - CHECK(request_info_ && request_info_->upload_data_stream); - CHECK_EQ(raw_request_body_buf_size_, 0); + CHECK(HasUploadData()); + CHECK_EQ(request_body_buf_size_, 0); + + if (request_info_->upload_data_stream->IsEOF()) + return; // Read the data from the request body stream. const int rv = request_info_->upload_data_stream->Read( - raw_request_body_buf_, raw_request_body_buf_->size(), + request_body_buf_, request_body_buf_->size(), base::Bind( &SpdyHttpStream::OnRequestBodyReadCompleted, weak_factory_.GetWeakPtr())); @@ -450,20 +442,16 @@ void SpdyHttpStream::ReadAndSendRequestBodyData() { void SpdyHttpStream::OnRequestBodyReadCompleted(int status) { CHECK_GE(status, 0); - raw_request_body_buf_size_ = status; - SendRequestBodyData(); -} - -void SpdyHttpStream::SendRequestBodyData() { + request_body_buf_size_ = status; const bool eof = request_info_->upload_data_stream->IsEOF(); if (eof) { - CHECK_GE(raw_request_body_buf_size_, 0); + CHECK_GE(request_body_buf_size_, 0); } else { - CHECK_GT(raw_request_body_buf_size_, 0); + CHECK_GT(request_body_buf_size_, 0); } - stream_->SendStreamData(raw_request_body_buf_, - raw_request_body_buf_size_, - eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); + stream_->SendData(request_body_buf_, + request_body_buf_size_, + eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); } void SpdyHttpStream::ScheduleBufferedReadCallback() { diff --git a/net/spdy/spdy_http_stream.h b/net/spdy/spdy_http_stream.h index 7562510..34483d0 100644 --- a/net/spdy/spdy_http_stream.h +++ b/net/spdy/spdy_http_stream.h @@ -85,31 +85,29 @@ class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate, virtual void Drain(HttpNetworkSession* session) OVERRIDE; // SpdyStream::Delegate implementation. - virtual void OnSendRequestHeadersComplete() OVERRIDE; - virtual void OnSendBody() OVERRIDE; - virtual void OnSendBodyComplete() OVERRIDE; - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) OVERRIDE; + virtual void OnRequestHeadersSent() OVERRIDE; + virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) OVERRIDE; virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; virtual void OnDataSent() OVERRIDE; virtual void OnClose(int status) OVERRIDE; private: + bool HasUploadData() const; + void OnStreamCreated(const CompletionCallback& callback, int rv); - // Reads the data (whether chunked or not) from the request body - // stream and sends it. The read and subsequent sending may happen - // asynchronously. + // Reads the remaining data (whether chunked or not) from the + // request body stream and sends it if there's any. The read and + // subsequent sending may happen asynchronously. Must be called only + // when HasUploadData() is true. void ReadAndSendRequestBodyData(); // Called when data has just been read from the request body stream; // does the actual sending of data. void OnRequestBodyReadCompleted(int status); - // Queues some request body data to be sent. - void SendRequestBodyData(); - // Call the user callback. void DoCallback(int rv); @@ -134,8 +132,6 @@ class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate, // The request to send. const HttpRequestInfo* request_info_; - bool has_upload_data_; - // |response_info_| is the HTTP response data object which is filled in // when a SYN_REPLY comes in for the stream. // It is not owned by this stream object, or point to |push_response_info_|. @@ -155,8 +151,8 @@ class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate, int user_buffer_len_; // Temporary buffer used to read the request body from UploadDataStream. - scoped_refptr<IOBufferWithSize> raw_request_body_buf_; - int raw_request_body_buf_size_; + scoped_refptr<IOBufferWithSize> request_body_buf_; + int request_body_buf_size_; // Is there a scheduled read callback pending. bool buffered_read_callback_pending_; diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc index 176240f..096599c 100644 --- a/net/spdy/spdy_proxy_client_socket.cc +++ b/net/spdy/spdy_proxy_client_socket.cc @@ -226,7 +226,7 @@ int SpdyProxyClientSocket::Write(IOBuffer* buf, int buf_len, return ERR_SOCKET_NOT_CONNECTED; DCHECK(spdy_stream_); - spdy_stream_->SendStreamData(buf, buf_len, MORE_DATA_TO_SEND); + spdy_stream_->SendData(buf, buf_len, MORE_DATA_TO_SEND); net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, buf_len, buf->data()); write_callback_ = callback; @@ -435,25 +435,13 @@ int SpdyProxyClientSocket::DoReadReplyComplete(int result) { // SpdyStream::Delegate methods: // Called when SYN frame has been sent. // Returns true if no more data to be sent after SYN frame. -void SpdyProxyClientSocket::OnSendRequestHeadersComplete() { +void SpdyProxyClientSocket::OnRequestHeadersSent() { DCHECK_EQ(next_state_, STATE_SEND_REQUEST_COMPLETE); OnIOComplete(OK); } -void SpdyProxyClientSocket::OnSendBody() { - // Because we use |spdy_stream_| via STATE_OPEN (ala WebSockets) - // OnSendBody() must never be called. - CHECK(false); -} - -void SpdyProxyClientSocket::OnSendBodyComplete() { - // Because we use |spdy_stream_| via STATE_OPEN (ala WebSockets) - // OnSendBodyComplete() must never be called. - CHECK(false); -} - -int SpdyProxyClientSocket::OnResponseReceived( +int SpdyProxyClientSocket::OnResponseHeadersReceived( const SpdyHeaderBlock& response, base::Time response_time, int status) { diff --git a/net/spdy/spdy_proxy_client_socket.h b/net/spdy/spdy_proxy_client_socket.h index cefea5c..d80e1d8 100644 --- a/net/spdy/spdy_proxy_client_socket.h +++ b/net/spdy/spdy_proxy_client_socket.h @@ -91,12 +91,10 @@ class NET_EXPORT_PRIVATE SpdyProxyClientSocket : public ProxyClientSocket, virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; // SpdyStream::Delegate implementation. - virtual void OnSendRequestHeadersComplete() OVERRIDE; - virtual void OnSendBody() OVERRIDE; - virtual void OnSendBodyComplete() OVERRIDE; - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) OVERRIDE; + virtual void OnRequestHeadersSent() OVERRIDE; + virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) OVERRIDE; virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; virtual void OnDataSent() OVERRIDE; virtual void OnClose(int status) OVERRIDE; diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index 8b6b1ed..ebaba1c 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -1599,7 +1599,7 @@ bool SpdySession::Respond(const SpdyHeaderBlock& headers, SpdyStream* stream) { int rv = OK; SpdyStreamId stream_id = stream->stream_id(); // May invalidate |stream|. - rv = stream->OnResponseReceived(headers); + rv = stream->OnResponseHeadersReceived(headers); if (rv < 0) { DCHECK_NE(rv, ERR_IO_PENDING); CloseActiveStream(stream_id, rv); diff --git a/net/spdy/spdy_session_spdy3_unittest.cc b/net/spdy/spdy_session_spdy3_unittest.cc index d1ef360..4cef00e 100644 --- a/net/spdy/spdy_session_spdy3_unittest.cc +++ b/net/spdy/spdy_session_spdy3_unittest.cc @@ -3245,8 +3245,8 @@ class StreamClosingDelegate : public test::StreamDelegateWithBody { stream_to_close_ = stream_to_close; } - virtual void OnSendBodyComplete() OVERRIDE { - test::StreamDelegateWithBody::OnSendBodyComplete(); + virtual void OnDataSent() OVERRIDE { + test::StreamDelegateWithBody::OnDataSent(); if (stream_to_close_) { stream_to_close_->Close(); EXPECT_EQ(NULL, stream_to_close_.get()); diff --git a/net/spdy/spdy_stream.cc b/net/spdy/spdy_stream.cc index 4470dfc..7db3b8c 100644 --- a/net/spdy/spdy_stream.cc +++ b/net/spdy/spdy_stream.cc @@ -144,7 +144,7 @@ void SpdyStream::PushedStreamReplayData() { // TODO(akalin): This call may delete this object. Figure out what // to do in that case. - int rv = delegate_->OnResponseReceived(*response_, response_time_, OK); + int rv = delegate_->OnResponseHeadersReceived(*response_, response_time_, OK); if (rv == ERR_INCOMPLETE_SPDY_HEADERS) { // We don't have complete headers. Assume we're waiting for another // HEADERS frame. Since we don't have headers, we had better not have @@ -368,7 +368,7 @@ void SpdyStream::SetRequestTime(base::Time t) { request_time_ = t; } -int SpdyStream::OnResponseReceived(const SpdyHeaderBlock& response) { +int SpdyStream::OnResponseHeadersReceived(const SpdyHeaderBlock& response) { int rv = OK; metrics_.StartStream(); @@ -406,10 +406,11 @@ int SpdyStream::OnResponseReceived(const SpdyHeaderBlock& response) { if (delegate_) { // May delete this object. - rv = delegate_->OnResponseReceived(*response_, response_time_, rv); + rv = delegate_->OnResponseHeadersReceived(*response_, response_time_, rv); } - // If delegate_ is not yet attached, we'll call OnResponseReceived after the - // delegate gets attached to the stream. + // If delegate_ is not yet attached, we'll call + // OnResponseHeadersReceived after the delegate gets attached to the + // stream. return rv; } @@ -446,7 +447,7 @@ int SpdyStream::OnHeaders(const SpdyHeaderBlock& headers) { int rv = OK; if (delegate_) { // May delete this object. - rv = delegate_->OnResponseReceived(*response_, response_time_, rv); + rv = delegate_->OnResponseHeadersReceived(*response_, response_time_, rv); // ERR_INCOMPLETE_SPDY_HEADERS means that we are waiting for more // headers before the response header block is complete. if (rv == ERR_INCOMPLETE_SPDY_HEADERS) @@ -576,9 +577,9 @@ int SpdyStream::SendRequestHeaders(scoped_ptr<SpdyHeaderBlock> headers, return DoLoop(OK); } -void SpdyStream::SendStreamData(IOBuffer* data, - int length, - SpdySendStatus send_status) { +void SpdyStream::SendData(IOBuffer* data, + int length, + SpdySendStatus send_status) { CHECK_NE(type_, SPDY_PUSH_STREAM); CHECK_EQ(send_status_, MORE_DATA_TO_SEND); CHECK_GE(io_state_, STATE_SEND_BODY); @@ -667,6 +668,9 @@ int SpdyStream::DoLoop(int result) { CHECK_EQ(result, OK); result = DoSendRequestHeadersComplete(); break; + // TODO(akalin): Remove the states STATE_SEND_BODY through + // STATE_WAITING_FOR_RESPONSE; we can infer correct behavior + // from |type_| and |send_status_|. case STATE_SEND_BODY: CHECK_EQ(result, OK); result = DoSendBody(); @@ -681,7 +685,7 @@ int SpdyStream::DoLoop(int result) { result = ERR_IO_PENDING; break; // State machine 2: connection is established. - // In STATE_OPEN, OnResponseReceived has already been called. + // In STATE_OPEN, OnResponseHeadersReceived has already been called. // OnDataReceived, OnClose and OnFrameWriteComplete can be called. // Only OnFrameWriteComplete calls DoLoop(). // @@ -816,8 +820,6 @@ int SpdyStream::DoSendRequestHeadersComplete() { if (!delegate_) return ERR_UNEXPECTED; - delegate_->OnSendRequestHeadersComplete(); - switch (type_) { case SPDY_BIDIRECTIONAL_STREAM: DCHECK_EQ(send_status_, MORE_DATA_TO_SEND); @@ -837,6 +839,8 @@ int SpdyStream::DoSendRequestHeadersComplete() { return ERR_UNEXPECTED; } + delegate_->OnRequestHeadersSent(); + return OK; } @@ -845,8 +849,6 @@ int SpdyStream::DoSendRequestHeadersComplete() { int SpdyStream::DoSendBody() { DCHECK_NE(type_, SPDY_PUSH_STREAM); io_state_ = STATE_SEND_BODY_COMPLETE; - CHECK(delegate_); - delegate_->OnSendBody(); return ERR_IO_PENDING; } @@ -857,12 +859,12 @@ int SpdyStream::DoSendBodyComplete(int result) { if (result != OK) return result; - delegate_->OnSendBodyComplete(); - io_state_ = (send_status_ == MORE_DATA_TO_SEND) ? STATE_SEND_BODY : STATE_WAITING_FOR_RESPONSE; + delegate_->OnDataSent(); + return OK; } diff --git a/net/spdy/spdy_stream.h b/net/spdy/spdy_stream.h index 91f2400..01f04f1 100644 --- a/net/spdy/spdy_stream.h +++ b/net/spdy/spdy_stream.h @@ -71,23 +71,7 @@ class NET_EXPORT_PRIVATE SpdyStream { // Called when the request headers have been sent. Never called // for push streams. - virtual void OnSendRequestHeadersComplete() = 0; - - // Called when the stream is ready to send body data. The - // delegate must call SendStreamData() on the stream, either - // immediately or asynchronously (e.g., if the data to be send has - // to be read asynchronously). - // - // Called only for request/response streams when - // SendRequestHeaders() is called with MORE_DATA_TO_SEND. - // - // TODO(akalin): Unify this with OnSendRequestHeadersComplete(). - virtual void OnSendBody() = 0; - - // Called when body data has been sent. - // - // TODO(akalin): Unify this with OnDataSent(). - virtual void OnSendBodyComplete() = 0; + virtual void OnRequestHeadersSent() = 0; // Called when the SYN_STREAM, SYN_REPLY, or HEADERS frames are received. // Normal streams will receive a SYN_REPLY and optional HEADERS frames. @@ -95,9 +79,9 @@ class NET_EXPORT_PRIVATE SpdyStream { // Because a stream may have a SYN_* frame and multiple HEADERS frames, // this callback may be called multiple times. // |status| indicates network error. Returns network error code. - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) = 0; + virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) = 0; // Called when data is received. |buffer| may be NULL, which // signals EOF. Must return OK if the data was received @@ -130,8 +114,8 @@ class NET_EXPORT_PRIVATE SpdyStream { ~SpdyStream(); - // Set new |delegate|. |delegate| must not be NULL. - // If it already received SYN_REPLY or data, OnResponseReceived() or + // Set new |delegate|. |delegate| must not be NULL. If it already + // received SYN_REPLY or data, OnResponseHeadersReceived() or // OnDataReceived() will be called. void SetDelegate(Delegate* delegate); Delegate* GetDelegate() { return delegate_; } @@ -247,15 +231,16 @@ class NET_EXPORT_PRIVATE SpdyStream { // Called by the SpdySession when a response (e.g. a SYN_STREAM or // SYN_REPLY) has been received for this stream. This is the entry // point for a push stream. Returns a status code. - int OnResponseReceived(const SpdyHeaderBlock& response); + int OnResponseHeadersReceived(const SpdyHeaderBlock& response); // Called by the SpdySession when late-bound headers are received for a // stream. Returns a status code. int OnHeaders(const SpdyHeaderBlock& headers); - // Called by the SpdySession when response data has been received for this - // stream. This callback may be called multiple times as data arrives - // from the network, and will never be called prior to OnResponseReceived. + // Called by the SpdySession when response data has been received + // for this stream. This callback may be called multiple times as + // data arrives from the network, and will never be called prior to + // OnResponseHeadersReceived. // // |buffer| contains the data received, or NULL if the stream is // being closed. The stream must copy any data from this @@ -303,8 +288,8 @@ class NET_EXPORT_PRIVATE SpdyStream { // streams, which must not send anything. // Sends the request headers. The delegate is called back via - // OnSendRequestHeadersComplete() when the request headers have - // completed sending. |send_status| must be MORE_DATA_TO_SEND for + // OnRequestHeadersSent() when the request headers have completed + // sending. |send_status| must be MORE_DATA_TO_SEND for // bidirectional streams; for request/response streams, it must be // MORE_DATA_TO_SEND if the request has data to upload, or // NO_MORE_DATA_TO_SEND if not. @@ -312,13 +297,11 @@ class NET_EXPORT_PRIVATE SpdyStream { SpdySendStatus send_status); // Sends a DATA frame. The delegate will be notified via - // OnSendBodyComplete() (if the response hasn't been received yet) - // or OnDataSent() (if the response has been received) when the send - // is complete. |send_status| must be MORE_DATA_TO_SEND for - // bidirectional streams; for request/response streams, it must be - // MORE_DATA_TO_SEND if there is more data to upload, or - // NO_MORE_DATA_TO_SEND if not. - void SendStreamData(IOBuffer* data, int length, SpdySendStatus send_status); + // OnDataSent() when the send is complete. |send_status| must be + // MORE_DATA_TO_SEND for bidirectional streams; for request/response + // streams, it must be MORE_DATA_TO_SEND if there is more data to + // upload, or NO_MORE_DATA_TO_SEND if not. + void SendData(IOBuffer* data, int length, SpdySendStatus send_status); // Fills SSL info in |ssl_info| and returns true when SSL is in use. bool GetSSLInfo(SSLInfo* ssl_info, diff --git a/net/spdy/spdy_stream_spdy2_unittest.cc b/net/spdy/spdy_stream_spdy2_unittest.cc index e6689f1..835bc13 100644 --- a/net/spdy/spdy_stream_spdy2_unittest.cc +++ b/net/spdy/spdy_stream_spdy2_unittest.cc @@ -176,7 +176,7 @@ TEST_F(SpdyStreamSpdy2Test, PushedStream) { // Set a couple of headers. SpdyHeaderBlock response; response["url"] = kStreamUrl; - stream.OnResponseReceived(response); + stream.OnResponseHeadersReceived(response); // Send some basic headers. SpdyHeaderBlock headers; diff --git a/net/spdy/spdy_stream_spdy3_unittest.cc b/net/spdy/spdy_stream_spdy3_unittest.cc index 99f370b..2da85ff 100644 --- a/net/spdy/spdy_stream_spdy3_unittest.cc +++ b/net/spdy/spdy_stream_spdy3_unittest.cc @@ -188,7 +188,7 @@ TEST_F(SpdyStreamSpdy3Test, PushedStream) { response[":host"] = url.host(); response[":scheme"] = url.scheme(); response[":path"] = url.path(); - stream.OnResponseReceived(response); + stream.OnResponseHeadersReceived(response); // Send some basic headers. SpdyHeaderBlock headers; diff --git a/net/spdy/spdy_stream_test_util.cc b/net/spdy/spdy_stream_test_util.cc index 36c233e..e72f408 100644 --- a/net/spdy/spdy_stream_test_util.cc +++ b/net/spdy/spdy_stream_test_util.cc @@ -20,17 +20,11 @@ ClosingDelegate::ClosingDelegate( ClosingDelegate::~ClosingDelegate() {} -void ClosingDelegate::OnSendRequestHeadersComplete() {} +void ClosingDelegate::OnRequestHeadersSent() {} -void ClosingDelegate::OnSendBody() { - ADD_FAILURE() << "OnSendBody should not be called"; -} - -void ClosingDelegate::OnSendBodyComplete() {} - -int ClosingDelegate::OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) { +int ClosingDelegate::OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) { return OK; } @@ -56,15 +50,16 @@ StreamDelegateBase::StreamDelegateBase( StreamDelegateBase::~StreamDelegateBase() { } -void StreamDelegateBase::OnSendRequestHeadersComplete() { +void StreamDelegateBase::OnRequestHeadersSent() { stream_id_ = stream_->stream_id(); EXPECT_NE(stream_id_, 0u); send_headers_completed_ = true; } -int StreamDelegateBase::OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) { +int StreamDelegateBase::OnResponseHeadersReceived( + const SpdyHeaderBlock& response, + base::Time response_time, + int status) { EXPECT_TRUE(send_headers_completed_); response_ = response; return status; @@ -116,12 +111,6 @@ StreamDelegateDoNothing::StreamDelegateDoNothing( StreamDelegateDoNothing::~StreamDelegateDoNothing() { } -void StreamDelegateDoNothing::OnSendBody() { - ADD_FAILURE() << "OnSendBody should not be called"; -} - -void StreamDelegateDoNothing::OnSendBodyComplete() {} - StreamDelegateSendImmediate::StreamDelegateSendImmediate( const base::WeakPtr<SpdyStream>& stream, base::StringPiece data) @@ -131,23 +120,16 @@ StreamDelegateSendImmediate::StreamDelegateSendImmediate( StreamDelegateSendImmediate::~StreamDelegateSendImmediate() { } -void StreamDelegateSendImmediate::OnSendBody() { - ADD_FAILURE() << "OnSendBody should not be called"; -} - -void StreamDelegateSendImmediate::OnSendBodyComplete() { - ADD_FAILURE() << "OnSendBodyComplete should not be called"; -} - -int StreamDelegateSendImmediate::OnResponseReceived( +int StreamDelegateSendImmediate::OnResponseHeadersReceived( const SpdyHeaderBlock& response, base::Time response_time, int status) { status = - StreamDelegateBase::OnResponseReceived(response, response_time, status); + StreamDelegateBase::OnResponseHeadersReceived( + response, response_time, status); if (data_.data()) { scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(data_.as_string())); - stream()->SendStreamData(buf, buf->size(), MORE_DATA_TO_SEND); + stream()->SendData(buf, buf->size(), MORE_DATA_TO_SEND); } return status; } @@ -161,12 +143,11 @@ StreamDelegateWithBody::StreamDelegateWithBody( StreamDelegateWithBody::~StreamDelegateWithBody() { } -void StreamDelegateWithBody::OnSendBody() { - stream()->SendStreamData(buf_.get(), buf_->size(), NO_MORE_DATA_TO_SEND); +void StreamDelegateWithBody::OnRequestHeadersSent() { + StreamDelegateBase::OnRequestHeadersSent(); + stream()->SendData(buf_.get(), buf_->size(), NO_MORE_DATA_TO_SEND); } -void StreamDelegateWithBody::OnSendBodyComplete() {} - } // namespace test } // namespace net diff --git a/net/spdy/spdy_stream_test_util.h b/net/spdy/spdy_stream_test_util.h index 51823161..fb2520d 100644 --- a/net/spdy/spdy_stream_test_util.h +++ b/net/spdy/spdy_stream_test_util.h @@ -26,12 +26,10 @@ class ClosingDelegate : public SpdyStream::Delegate { virtual ~ClosingDelegate(); // SpdyStream::Delegate implementation. - virtual void OnSendRequestHeadersComplete() OVERRIDE; - virtual void OnSendBody() OVERRIDE; - virtual void OnSendBodyComplete() OVERRIDE; - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) OVERRIDE; + virtual void OnRequestHeadersSent() OVERRIDE; + virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) OVERRIDE; virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; virtual void OnDataSent() OVERRIDE; virtual void OnClose(int status) OVERRIDE; @@ -50,12 +48,10 @@ class StreamDelegateBase : public SpdyStream::Delegate { explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); virtual ~StreamDelegateBase(); - virtual void OnSendRequestHeadersComplete() OVERRIDE; - virtual void OnSendBody() = 0; - virtual void OnSendBodyComplete() = 0; - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) OVERRIDE; + virtual void OnRequestHeadersSent() OVERRIDE; + virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) OVERRIDE; virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; virtual void OnDataSent() OVERRIDE; virtual void OnClose(int status) OVERRIDE; @@ -96,12 +92,9 @@ class StreamDelegateDoNothing : public StreamDelegateBase { public: StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); virtual ~StreamDelegateDoNothing(); - - virtual void OnSendBody() OVERRIDE; - virtual void OnSendBodyComplete() OVERRIDE; }; -// Test delegate that sends data immediately in OnResponseReceived(). +// Test delegate that sends data immediately in OnResponseHeadersReceived(). class StreamDelegateSendImmediate : public StreamDelegateBase { public: // |data| can be NULL. @@ -109,11 +102,9 @@ class StreamDelegateSendImmediate : public StreamDelegateBase { base::StringPiece data); virtual ~StreamDelegateSendImmediate(); - virtual void OnSendBody() OVERRIDE; - virtual void OnSendBodyComplete() OVERRIDE; - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) OVERRIDE; + virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) OVERRIDE; private: base::StringPiece data_; @@ -126,8 +117,7 @@ class StreamDelegateWithBody : public StreamDelegateBase { base::StringPiece data); virtual ~StreamDelegateWithBody(); - virtual void OnSendBody() OVERRIDE; - virtual void OnSendBodyComplete() OVERRIDE; + virtual void OnRequestHeadersSent() OVERRIDE; private: scoped_refptr<StringIOBuffer> buf_; diff --git a/net/spdy/spdy_websocket_stream.cc b/net/spdy/spdy_websocket_stream.cc index 0d56454..61ee5eb 100644 --- a/net/spdy/spdy_websocket_stream.cc +++ b/net/spdy/spdy_websocket_stream.cc @@ -71,7 +71,7 @@ int SpdyWebSocketStream::SendData(const char* data, int length) { pending_send_data_length_ = static_cast<size_t>(length); scoped_refptr<IOBuffer> buf(new IOBuffer(length)); memcpy(buf->data(), data, length); - stream_->SendStreamData(buf.get(), length, MORE_DATA_TO_SEND); + stream_->SendData(buf.get(), length, MORE_DATA_TO_SEND); return ERR_IO_PENDING; } @@ -82,20 +82,12 @@ void SpdyWebSocketStream::Close() { } } -void SpdyWebSocketStream::OnSendRequestHeadersComplete() { +void SpdyWebSocketStream::OnRequestHeadersSent() { DCHECK(delegate_); delegate_->OnSentSpdyHeaders(); } -void SpdyWebSocketStream::OnSendBody() { - CHECK(false); -} - -void SpdyWebSocketStream::OnSendBodyComplete() { - CHECK(false); -} - -int SpdyWebSocketStream::OnResponseReceived( +int SpdyWebSocketStream::OnResponseHeadersReceived( const SpdyHeaderBlock& response, base::Time response_time, int status) { DCHECK(delegate_); diff --git a/net/spdy/spdy_websocket_stream.h b/net/spdy/spdy_websocket_stream.h index f5812b8..903c0bc 100644 --- a/net/spdy/spdy_websocket_stream.h +++ b/net/spdy/spdy_websocket_stream.h @@ -38,9 +38,10 @@ class NET_EXPORT_PRIVATE SpdyWebSocketStream // has been sent. virtual void OnSentSpdyHeaders() = 0; - // Called on corresponding to OnResponseReceived() or SPDY's SYN_STREAM, - // SYN_REPLY, or HEADERS frames are received. This callback may be called - // multiple times as SPDY's delegate does. + // Called on corresponding to OnResponseHeadersReceived() or + // SPDY's SYN_STREAM, SYN_REPLY, or HEADERS frames are + // received. This callback may be called multiple times as SPDY's + // delegate does. virtual int OnReceivedSpdyResponseHeader( const SpdyHeaderBlock& headers, int status) = 0; @@ -74,12 +75,10 @@ class NET_EXPORT_PRIVATE SpdyWebSocketStream void Close(); // SpdyStream::Delegate - virtual void OnSendRequestHeadersComplete() OVERRIDE; - virtual void OnSendBody() OVERRIDE; - virtual void OnSendBodyComplete() OVERRIDE; - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) OVERRIDE; + virtual void OnRequestHeadersSent() OVERRIDE; + virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) OVERRIDE; virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; virtual void OnDataSent() OVERRIDE; virtual void OnClose(int status) OVERRIDE; |