summaryrefslogtreecommitdiffstats
path: root/content/browser/streams
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-14 04:44:38 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-14 04:44:38 +0000
commite4923e8e5ce3727a0a78db75458348d2d85ce705 (patch)
tree0eb49e104d8ca3ae7b20ed077aefe1770d71ea1d /content/browser/streams
parent9f632b84199c51ccae45a53e9304e6dc638a085b (diff)
downloadchromium_src-e4923e8e5ce3727a0a78db75458348d2d85ce705.zip
chromium_src-e4923e8e5ce3727a0a78db75458348d2d85ce705.tar.gz
chromium_src-e4923e8e5ce3727a0a78db75458348d2d85ce705.tar.bz2
StreamURLRequestJob::OnDataAvailable refactoring
- Use return value of reader_->Read() call rather than depending on bytes_read - More comments - More DCHECKs BUG= Review URL: https://chromiumcodereview.appspot.com/23025002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217481 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/streams')
-rw-r--r--content/browser/streams/stream.cc3
-rw-r--r--content/browser/streams/stream_url_request_job.cc43
2 files changed, 34 insertions, 12 deletions
diff --git a/content/browser/streams/stream.cc b/content/browser/streams/stream.cc
index f5abe02..6026df9 100644
--- a/content/browser/streams/stream.cc
+++ b/content/browser/streams/stream.cc
@@ -90,6 +90,9 @@ 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/content/browser/streams/stream_url_request_job.cc b/content/browser/streams/stream_url_request_job.cc
index d2719a0..0965178 100644
--- a/content/browser/streams/stream_url_request_job.cc
+++ b/content/browser/streams/stream_url_request_job.cc
@@ -39,19 +39,37 @@ StreamURLRequestJob::~StreamURLRequestJob() {
void StreamURLRequestJob::OnDataAvailable(Stream* stream) {
// Clear the IO_PENDING status.
SetStatus(net::URLRequestStatus());
- 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);
+ // 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;
}
+
+ // 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.
@@ -74,6 +92,7 @@ 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) {