diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-11-21 14:09:57 +0100 |
---|---|---|
committer | Andras Becsi <andras.becsi@digia.com> | 2013-11-29 15:14:36 +0100 |
commit | eb32ba6f51d0c21d58cd7d89785285ff8fa64624 (patch) | |
tree | 2c7c940e1dbee81b89d935626110816b494aa32c /chromium/content/browser/streams | |
parent | 9427c1a0222ebd67efef1a2c7990a0fa5c9aac84 (diff) | |
download | qtwebengine-chromium-eb32ba6f51d0c21d58cd7d89785285ff8fa64624.tar.gz |
Update chromium to branch 1599.
Change-Id: I04e775a946a208bb4500d3b722bcb05c82b9d7cb
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'chromium/content/browser/streams')
-rw-r--r-- | chromium/content/browser/streams/stream.cc | 3 | ||||
-rw-r--r-- | chromium/content/browser/streams/stream_unittest.cc | 51 | ||||
-rw-r--r-- | chromium/content/browser/streams/stream_url_request_job.cc | 44 |
3 files changed, 17 insertions, 81 deletions
diff --git a/chromium/content/browser/streams/stream.cc b/chromium/content/browser/streams/stream.cc index 6026df9e7c7..f5abe0276e8 100644 --- a/chromium/content/browser/streams/stream.cc +++ b/chromium/content/browser/streams/stream.cc @@ -90,9 +90,6 @@ void Stream::Finalize() { Stream::StreamState Stream::ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read) { - DCHECK(buf); - DCHECK(bytes_read); - *bytes_read = 0; if (!data_.get()) { data_length_ = 0; diff --git a/chromium/content/browser/streams/stream_unittest.cc b/chromium/content/browser/streams/stream_unittest.cc index c0077b7375b..36add1d649d 100644 --- a/chromium/content/browser/streams/stream_unittest.cc +++ b/chromium/content/browser/streams/stream_unittest.cc @@ -41,7 +41,7 @@ class StreamTest : public testing::Test { class TestStreamReader : public StreamReadObserver { public: - TestStreamReader() : buffer_(new net::GrowableIOBuffer()), completed_(false) { + TestStreamReader() : buffer_(new net::GrowableIOBuffer()) { } virtual ~TestStreamReader() {} @@ -50,22 +50,8 @@ class TestStreamReader : public StreamReadObserver { scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); int bytes_read = 0; - while (true) { - Stream::StreamState state = - stream->ReadRawData(buffer.get(), kBufferSize, &bytes_read); - switch (state) { - case Stream::STREAM_HAS_DATA: - // TODO(tyoshino): Move these expectations to the beginning of Read() - // method once Stream::Finalize() is fixed. - EXPECT_FALSE(completed_); - break; - case Stream::STREAM_COMPLETE: - completed_ = true; - return; - case Stream::STREAM_EMPTY: - EXPECT_FALSE(completed_); - return; - } + while (stream->ReadRawData(buffer.get(), kBufferSize, &bytes_read) == + Stream::STREAM_HAS_DATA) { size_t old_capacity = buffer_->capacity(); buffer_->SetCapacity(old_capacity + bytes_read); memcpy(buffer_->StartOfBuffer() + old_capacity, @@ -79,13 +65,8 @@ class TestStreamReader : public StreamReadObserver { scoped_refptr<net::GrowableIOBuffer> buffer() { return buffer_; } - bool completed() const { - return completed_; - } - private: scoped_refptr<net::GrowableIOBuffer> buffer_; - bool completed_; }; class TestStreamWriter : public StreamWriteObserver { @@ -156,38 +137,14 @@ TEST_F(StreamTest, Stream) { scoped_refptr<net::IOBuffer> buffer(NewIOBuffer(kBufferSize)); writer.Write(stream.get(), buffer, kBufferSize); stream->Finalize(); + reader.Read(stream.get()); base::MessageLoop::current()->RunUntilIdle(); - EXPECT_TRUE(reader.completed()); ASSERT_EQ(reader.buffer()->capacity(), kBufferSize); for (int i = 0; i < kBufferSize; i++) EXPECT_EQ(buffer->data()[i], reader.buffer()->data()[i]); } -// Test that even if a reader receives an empty buffer, once TransferData() -// method is called on it with |source_complete| = true, following Read() calls -// on it never returns STREAM_EMPTY. Together with StreamTest.Stream above, this -// guarantees that Reader::Read() call returns only STREAM_HAS_DATA -// or STREAM_COMPLETE in |data_available_callback_| call corresponding to -// Writer::Close(). -TEST_F(StreamTest, ClosedReaderDoesNotReturnStreamEmpty) { - TestStreamReader reader; - TestStreamWriter writer; - - GURL url("blob://stream"); - scoped_refptr<Stream> stream( - new Stream(registry_.get(), &writer, url)); - EXPECT_TRUE(stream->SetReadObserver(&reader)); - - const int kBufferSize = 0; - scoped_refptr<net::IOBuffer> buffer(NewIOBuffer(kBufferSize)); - stream->AddData(buffer, kBufferSize); - stream->Finalize(); - base::MessageLoop::current()->RunUntilIdle(); - EXPECT_TRUE(reader.completed()); - EXPECT_EQ(0, reader.buffer()->capacity()); -} - TEST_F(StreamTest, GetStream) { TestStreamWriter writer; diff --git a/chromium/content/browser/streams/stream_url_request_job.cc b/chromium/content/browser/streams/stream_url_request_job.cc index 0965178de2c..e36c5d49ae6 100644 --- a/chromium/content/browser/streams/stream_url_request_job.cc +++ b/chromium/content/browser/streams/stream_url_request_job.cc @@ -39,37 +39,19 @@ StreamURLRequestJob::~StreamURLRequestJob() { void StreamURLRequestJob::OnDataAvailable(Stream* stream) { // Clear the IO_PENDING status. SetStatus(net::URLRequestStatus()); - // Do nothing if pending_buffer_ is empty, i.e. there's no ReadRawData() - // operation waiting for IO completion. - if (!pending_buffer_.get()) - return; - - // pending_buffer_ is set to the IOBuffer instance provided to ReadRawData() - // by URLRequestJob. - - int bytes_read; - switch (stream_->ReadRawData( - pending_buffer_.get(), pending_buffer_size_, &bytes_read)) { - case Stream::STREAM_HAS_DATA: - DCHECK_GT(bytes_read, 0); - break; - case Stream::STREAM_COMPLETE: - // Ensure this. Calling NotifyReadComplete call with 0 signals - // completion. - bytes_read = 0; - break; - case Stream::STREAM_EMPTY: - NOTREACHED(); - break; + if (pending_buffer_.get()) { + int bytes_read; + stream_->ReadRawData( + pending_buffer_.get(), pending_buffer_size_, &bytes_read); + + // Clear the buffers before notifying the read is complete, so that it is + // safe for the observer to read. + pending_buffer_ = NULL; + pending_buffer_size_ = 0; + + total_bytes_read_ += bytes_read; + NotifyReadComplete(bytes_read); } - - // Clear the buffers before notifying the read is complete, so that it is - // safe for the observer to read. - pending_buffer_ = NULL; - pending_buffer_size_ = 0; - - total_bytes_read_ += bytes_read; - NotifyReadComplete(bytes_read); } // net::URLRequestJob methods. @@ -92,7 +74,6 @@ bool StreamURLRequestJob::ReadRawData(net::IOBuffer* buf, if (request_failed_) return true; - DCHECK(buf); DCHECK(bytes_read); int to_read = buf_size; if (max_range_ && to_read) { @@ -186,6 +167,7 @@ void StreamURLRequestJob::NotifyFailure(int error_code) { // TODO(zork): Share these with BlobURLRequestJob. net::HttpStatusCode status_code = net::HTTP_INTERNAL_SERVER_ERROR; + std::string status_txt; switch (error_code) { case net::ERR_ACCESS_DENIED: status_code = net::HTTP_FORBIDDEN; |