summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-26 22:27:30 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-26 22:27:30 +0000
commit4dd2f05527b2c563c1593dc3098bd95ce7e28a39 (patch)
tree68d0d65fd4229e2b5199ea40c559c9485a4feb51 /chrome/renderer
parent3ca3baa83e12bde14fbc453c963bc7bdfe477fa3 (diff)
downloadchromium_src-4dd2f05527b2c563c1593dc3098bd95ce7e28a39.zip
chromium_src-4dd2f05527b2c563c1593dc3098bd95ce7e28a39.tar.gz
chromium_src-4dd2f05527b2c563c1593dc3098bd95ce7e28a39.tar.bz2
Fixing a long resource loading for small clips
The logic for resource loading for media file has a problem in determining the wait condition that it waited for one extra cycle (about ~5s) to know that the resource loading has completed, it is fixed in this patch. Also made clear about the logic in it. Review URL: http://codereview.chromium.org/113861 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/media/buffered_data_source.cc34
1 files changed, 18 insertions, 16 deletions
diff --git a/chrome/renderer/media/buffered_data_source.cc b/chrome/renderer/media/buffered_data_source.cc
index f752eb5..2a4f698 100644
--- a/chrome/renderer/media/buffered_data_source.cc
+++ b/chrome/renderer/media/buffered_data_source.cc
@@ -313,32 +313,34 @@ int BufferedResourceLoader::ReadInternal(uint8* buffer,
break;
}
- // The request has completed and the buffer is empty, don't wait. Return
- // the completion error that we got from OnCompletedRequest().
- if (completed_ && !buffer_->forward_bytes()) {
- error = completion_error_;
- break;
- }
-
// Read into |data|.
size_t unread_bytes = read_size - taken;
size_t bytes_read_this_time = buffer_->Read(unread_bytes, buffer + taken);
- // If we have waited for data in the last iteration but there isn't any
- // more data in the buffer, declare a timeout situation.
- if (waited_for_buffer && !bytes_read_this_time) {
- error = net::ERR_TIMED_OUT;
- break;
- }
-
// Increment the total bytes read from the buffer so we know when to stop
// reading.
taken += bytes_read_this_time;
DCHECK_LE(taken, read_size);
- // We have got enough bytes so we don't need to read anymore.
- if (taken == read_size)
+ // There are three conditions when we should terminate this loop:
+ // 1. We have read enough bytes so we don't need to read anymore.
+ // 2. The request has completed and the buffer is empty. We don't want to
+ // wait an additional iteration, so break on condition of empty forward
+ // buffer instead of breaking on failed read.
+ // 3. The request has timed out. We waited for data in the last iteration
+ // but there isn't any more data in the buffer.
+ if (taken == read_size) {
break;
+ }
+ if (completed_ && buffer_->forward_bytes() == 0) {
+ // We should return the completion error received.
+ error = completion_error_;
+ break;
+ }
+ if (waited_for_buffer && bytes_read_this_time == 0) {
+ error = net::ERR_TIMED_OUT;
+ break;
+ }
buffer_available_.TimedWait(
base::TimeDelta::FromSeconds(kDataTransferTimeoutSeconds));