Commit 6cbdefdd authored by scherkus@chromium.org's avatar scherkus@chromium.org

Fold RestartLoadingTask() into ReadCallback() as the method is called on the render thread.

This is the cache miss equivalent of r118386. We were unnecessarily posting a task to restart the HTTP request on a cache miss. On pages with heavy activity this can delay the load until the task can get executed.

BUG=none
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10700125

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146281 0039d316-1c4b-4281-b951-d872f2087c98
parent 109eb5cb
...@@ -254,27 +254,6 @@ void BufferedDataSource::CleanupTask() { ...@@ -254,27 +254,6 @@ void BufferedDataSource::CleanupTask() {
read_buffer_ = 0; read_buffer_ = 0;
} }
void BufferedDataSource::RestartLoadingTask() {
DCHECK(MessageLoop::current() == render_loop_);
if (stopped_on_render_loop_)
return;
{
// If there's no outstanding read then return early.
base::AutoLock auto_lock(lock_);
if (read_cb_.is_null())
return;
}
// Start reading from where we last left off until the end of the resource.
loader_.reset(CreateResourceLoader(last_read_start_, kPositionNotSpecified));
loader_->Start(
base::Bind(&BufferedDataSource::PartialReadStartCallback, this),
base::Bind(&BufferedDataSource::LoadingStateChangedCallback, this),
base::Bind(&BufferedDataSource::ProgressCallback, this),
frame_);
}
void BufferedDataSource::SetPlaybackRateTask(float playback_rate) { void BufferedDataSource::SetPlaybackRateTask(float playback_rate) {
DCHECK(MessageLoop::current() == render_loop_); DCHECK(MessageLoop::current() == render_loop_);
DCHECK(loader_.get()); DCHECK(loader_.get());
...@@ -437,8 +416,16 @@ void BufferedDataSource::ReadCallback( ...@@ -437,8 +416,16 @@ void BufferedDataSource::ReadCallback(
if (status == BufferedResourceLoader::kCacheMiss && if (status == BufferedResourceLoader::kCacheMiss &&
cache_miss_retries_left_ > 0) { cache_miss_retries_left_ > 0) {
cache_miss_retries_left_--; cache_miss_retries_left_--;
render_loop_->PostTask(FROM_HERE,
base::Bind(&BufferedDataSource::RestartLoadingTask, this)); // Recreate a loader starting from where we last left off until the
// end of the resource.
loader_.reset(CreateResourceLoader(
last_read_start_, kPositionNotSpecified));
loader_->Start(
base::Bind(&BufferedDataSource::PartialReadStartCallback, this),
base::Bind(&BufferedDataSource::LoadingStateChangedCallback, this),
base::Bind(&BufferedDataSource::ProgressCallback, this),
frame_);
return; return;
} }
......
...@@ -95,14 +95,11 @@ class BufferedDataSource : public media::DataSource { ...@@ -95,14 +95,11 @@ class BufferedDataSource : public media::DataSource {
// Task posted to perform actual reading on the render thread. // Task posted to perform actual reading on the render thread.
void ReadTask(int64 position, int read_size, uint8* read_buffer); void ReadTask(int64 position, int read_size, uint8* read_buffer);
// Task posted when Stop() is called. Stops |watch_dog_timer_| and // Task posted when Stop() is called. Stops |loader_|, resets Read()
// |loader_|, reset Read() variables, and set |stopped_on_render_loop_| // variables, and sets |stopped_on_render_loop_| to signal any remaining
// to signal any remaining tasks to stop. // tasks to stop.
void CleanupTask(); void CleanupTask();
// Restart resource loading on render thread.
void RestartLoadingTask();
// This task uses the current playback rate with the previous playback rate // This task uses the current playback rate with the previous playback rate
// to determine whether we are going from pause to play and play to pause, // to determine whether we are going from pause to play and play to pause,
// and signals the buffered resource loader accordingly. // and signals the buffered resource loader accordingly.
......
...@@ -509,8 +509,7 @@ void BufferedResourceLoader::didFinishLoading( ...@@ -509,8 +509,7 @@ void BufferedResourceLoader::didFinishLoading(
return; return;
} }
// If there is a pending read but the request has ended, return with what // Don't leave read callbacks hanging around.
// we have.
if (HasPendingRead()) { if (HasPendingRead()) {
// Try to fulfill with what is in the buffer. // Try to fulfill with what is in the buffer.
if (CanFulfillRead()) if (CanFulfillRead())
...@@ -518,9 +517,6 @@ void BufferedResourceLoader::didFinishLoading( ...@@ -518,9 +517,6 @@ void BufferedResourceLoader::didFinishLoading(
else else
DoneRead(kCacheMiss, 0); DoneRead(kCacheMiss, 0);
} }
// There must not be any outstanding read request.
DCHECK(!HasPendingRead());
} }
void BufferedResourceLoader::didFail( void BufferedResourceLoader::didFail(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment