Index: webkit/glue/media/buffered_data_source.cc |
diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc |
index d7a2f47e5736015c31d5ffc3c71b03a26097bf1e..444910044a35d7e18bbf65e4ffc61fb7114fd4f8 100644 |
--- a/webkit/glue/media/buffered_data_source.cc |
+++ b/webkit/glue/media/buffered_data_source.cc |
@@ -137,9 +137,25 @@ void BufferedDataSource::SetPlaybackRate(float playback_rate) { |
// media::DataSource implementation. |
void BufferedDataSource::Read(int64 position, size_t size, uint8* data, |
media::DataSource::ReadCallback* read_callback) { |
+ DCHECK(read_callback); |
+ |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ DCHECK(!read_callback_.get()); |
+ |
+ if (stop_signal_received_ || stopped_on_render_loop_) { |
+ read_callback->RunWithParams( |
+ Tuple1<size_t>(static_cast<size_t>(media::DataSource::kReadError))); |
+ delete read_callback; |
+ return; |
+ } |
+ |
+ read_callback_.reset(read_callback); |
+ } |
+ |
render_loop_->PostTask(FROM_HERE, |
NewRunnableMethod(this, &BufferedDataSource::ReadTask, |
- position, static_cast<int>(size), data, read_callback)); |
+ position, static_cast<int>(size), data)); |
} |
bool BufferedDataSource::GetSize(int64* size_out) { |
@@ -163,10 +179,12 @@ bool BufferedDataSource::HasSingleOrigin() { |
void BufferedDataSource::Abort() { |
DCHECK(MessageLoop::current() == render_loop_); |
- // If we are told to abort, immediately return from any pending read |
- // with an error. |
- if (read_callback_.get()) { |
- base::AutoLock auto_lock(lock_); |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ |
+ // If we are told to abort, immediately return from any pending read |
+ // with an error. |
+ if (read_callback_.get()) |
DoneRead_Locked(net::ERR_FAILED); |
} |
@@ -212,19 +230,21 @@ void BufferedDataSource::InitializeTask() { |
} |
void BufferedDataSource::ReadTask( |
- int64 position, int read_size, uint8* buffer, |
- media::DataSource::ReadCallback* read_callback) { |
+ int64 position, |
+ int read_size, |
+ uint8* buffer) { |
DCHECK(MessageLoop::current() == render_loop_); |
- if (stopped_on_render_loop_) |
- return; |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ if (stopped_on_render_loop_) |
+ return; |
- DCHECK(!read_callback_.get()); |
- DCHECK(read_callback); |
+ DCHECK(read_callback_.get()); |
+ } |
// Saves the read parameters. |
read_position_ = position; |
read_size_ = read_size; |
- read_callback_.reset(read_callback); |
read_buffer_ = buffer; |
read_submitted_time_ = base::Time::Now(); |
read_attempts_ = 0; |
@@ -235,8 +255,14 @@ void BufferedDataSource::ReadTask( |
void BufferedDataSource::CleanupTask() { |
DCHECK(MessageLoop::current() == render_loop_); |
- if (stopped_on_render_loop_) |
- return; |
+ |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ if (stopped_on_render_loop_) |
+ return; |
+ |
+ read_callback_.reset(); |
+ } |
// Stop the watch dog. |
watch_dog_timer_.Stop(); |
@@ -246,7 +272,6 @@ void BufferedDataSource::CleanupTask() { |
loader_->Stop(); |
// Reset the parameters of the current read request. |
- read_callback_.reset(); |
read_position_ = 0; |
read_size_ = 0; |
read_buffer_ = 0; |
@@ -262,9 +287,12 @@ void BufferedDataSource::RestartLoadingTask() { |
if (stopped_on_render_loop_) |
return; |
- // If there's no outstanding read then return early. |
- if (!read_callback_.get()) |
- return; |
+ { |
+ // If there's no outstanding read then return early. |
+ base::AutoLock auto_lock(lock_); |
+ if (!read_callback_.get()) |
+ return; |
+ } |
loader_ = CreateResourceLoader(read_position_, kPositionNotSpecified); |
loader_->SetAllowDefer(!media_is_paused_); |
@@ -280,8 +308,11 @@ void BufferedDataSource::WatchDogTask() { |
return; |
// We only care if there is an active read request. |
- if (!read_callback_.get()) |
- return; |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ if (!read_callback_.get()) |
+ return; |
+ } |
DCHECK(loader_.get()); |
base::TimeDelta delta = base::Time::Now() - read_submitted_time_; |