summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 02:01:34 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 02:01:34 +0000
commit554efaa8b3220e675ad3743eca7f699ad52e2c82 (patch)
tree36794e209261e40ee866036ab0d3548724be2f77 /net
parentd6b061bf189e0661a3d94d89dbcb2e6f70b433da (diff)
downloadchromium_src-554efaa8b3220e675ad3743eca7f699ad52e2c82.zip
chromium_src-554efaa8b3220e675ad3743eca7f699ad52e2c82.tar.gz
chromium_src-554efaa8b3220e675ad3743eca7f699ad52e2c82.tar.bz2
net: Simplify SpdyHttpStream::OnSendBody() and OnSendBodyComplete().
I don't know why I didn't come up with this simpler code from the beginning. BUG=113107 TEST=net_unittests Review URL: http://codereview.chromium.org/9362023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121379 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/spdy/spdy_http_stream.cc41
-rw-r--r--net/spdy/spdy_network_transaction_unittest.cc5
-rw-r--r--net/spdy/spdy_stream.h3
3 files changed, 16 insertions, 33 deletions
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc
index bf6dfce..ef48595 100644
--- a/net/spdy/spdy_http_stream.cc
+++ b/net/spdy/spdy_http_stream.cc
@@ -282,13 +282,18 @@ bool SpdyHttpStream::OnSendHeadersComplete(int status) {
int SpdyHttpStream::OnSendBody() {
CHECK(request_body_stream_.get());
- // TODO(satorux): Clean up the logic here. This behavior is weird. Reading
- // of upload data should happen in OnSendBody(). crbug.com/113107.
- //
- // Nothing to send. This happens when OnSendBody() is first called.
- // A read of the upload data stream is initiated in OnSendBodyComplete().
- if (request_body_buf_->BytesRemaining() == 0)
- return OK;
+ // Read the data from the request body stream if the buffer is empty.
+ if (!request_body_buf_->BytesRemaining()) {
+ const int bytes_read = request_body_stream_->Read(
+ raw_request_body_buf_, raw_request_body_buf_->size());
+ if (request_body_stream_->is_chunked() && bytes_read == ERR_IO_PENDING)
+ return ERR_IO_PENDING;
+ // ERR_IO_PENDING with chunked encoding is the only possible error.
+ DCHECK_GE(bytes_read, 0);
+
+ request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_,
+ bytes_read);
+ }
const bool eof = request_body_stream_->IsEOF();
return stream_->WriteStreamData(
@@ -300,32 +305,12 @@ int SpdyHttpStream::OnSendBody() {
int SpdyHttpStream::OnSendBodyComplete(int status, bool* eof) {
// |status| is the number of bytes written to the SPDY stream.
CHECK(request_body_stream_.get());
- *eof = false;
- if (status > 0) {
- request_body_buf_->DidConsume(status);
- if (request_body_buf_->BytesRemaining()) {
- // Go back to OnSendBody() to send the remaining data.
- return OK;
- }
- }
+ request_body_buf_->DidConsume(status);
// Check if the entire body data has been sent.
*eof = (request_body_stream_->IsEOF() &&
!request_body_buf_->BytesRemaining());
- if (*eof)
- return OK;
-
- // Read the data from the request body stream.
- const int bytes_read = request_body_stream_->Read(
- raw_request_body_buf_, raw_request_body_buf_->size());
- if (request_body_stream_->is_chunked() && bytes_read == ERR_IO_PENDING)
- return ERR_IO_PENDING;
- // ERR_IO_PENDING with chunked encoding is the only possible error.
- DCHECK_GE(bytes_read, 0);
-
- request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_,
- bytes_read);
return OK;
}
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index 47b4f6a..6d4c496d 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -2227,10 +2227,9 @@ TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) {
ASSERT_TRUE(stream->stream() != NULL);
EXPECT_EQ(0, stream->stream()->send_window_size());
// All the body data should have been read.
- // TODO(satorux): This is because of the weirdness in reading the request
- // body in OnSendBodyComplete(). See crbug.com/113107.
EXPECT_TRUE(stream->request_body_stream_->IsEOF());
- // But the body is not yet fully sent ("hello!" is not yet sent).
+ // But the body is not yet fully sent ("hello!" is not yet sent, and
+ // left in the internal buffer of |stream|).
EXPECT_FALSE(stream->stream()->body_sent());
data->ForceNextRead(); // Read in WINDOW_UPDATE frame.
diff --git a/net/spdy/spdy_stream.h b/net/spdy/spdy_stream.h
index 0512dce..c36ccdc 100644
--- a/net/spdy/spdy_stream.h
+++ b/net/spdy/spdy_stream.h
@@ -208,8 +208,7 @@ class NET_EXPORT_PRIVATE SpdyStream
void Close();
bool cancelled() const { return cancelled_; }
bool closed() const { return io_state_ == STATE_DONE; }
- // TODO(satorux): This is only for testing. We should be able to remove
- // this once crbug.com/113107 is addressed.
+ // This is only for testing.
bool body_sent() const { return io_state_ > STATE_SEND_BODY_COMPLETE; }
// Interface for Spdy[Http|WebSocket]Stream to use.