Index: webkit/glue/media/buffered_data_source.cc |
=================================================================== |
--- webkit/glue/media/buffered_data_source.cc (revision 103382) |
+++ webkit/glue/media/buffered_data_source.cc (working copy) |
@@ -85,8 +85,10 @@ |
void BufferedDataSource::set_host(media::FilterHost* host) { |
DataSource::set_host(host); |
- if (loader_.get()) |
- UpdateHostState(); |
+ if (loader_.get()) { |
+ base::AutoLock auto_lock(lock_); |
+ UpdateHostState_Locked(); |
+ } |
} |
void BufferedDataSource::Initialize(const std::string& url, |
@@ -104,7 +106,10 @@ |
} |
DCHECK(!callback.is_null()); |
- initialize_cb_ = callback; |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ initialize_cb_ = callback; |
+ } |
// Post a task to complete the initialization task. |
render_loop_->PostTask(FROM_HERE, |
@@ -205,9 +210,15 @@ |
void BufferedDataSource::InitializeTask() { |
DCHECK(MessageLoop::current() == render_loop_); |
DCHECK(!loader_.get()); |
- if (stopped_on_render_loop_ || initialize_cb_.is_null()) |
- return; |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ if (stopped_on_render_loop_ || initialize_cb_.is_null() || |
+ stop_signal_received_) { |
+ return; |
+ } |
+ } |
+ |
if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { |
// Do an unbounded range request starting at the beginning. If the server |
// responds with 200 instead of 206 we'll fall back into a streaming mode. |
@@ -257,6 +268,7 @@ |
{ |
base::AutoLock auto_lock(lock_); |
+ initialize_cb_.Reset(); |
if (stopped_on_render_loop_) |
return; |
@@ -321,6 +333,7 @@ |
BufferedResourceLoader::DeferStrategy |
BufferedDataSource::ChooseDeferStrategy() { |
+ DCHECK(MessageLoop::current() == render_loop_); |
// If the user indicates preload=metadata, then just load exactly |
// what is needed for starting the pipeline and prerolling frames. |
if (preload_ == media::METADATA && !media_has_played_) |
@@ -398,7 +411,13 @@ |
int64 instance_size = loader_->instance_size(); |
bool success = error == net::OK; |
- if (initialize_cb_.is_null()) { |
+ |
+ bool initialize_cb_is_null = false; |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ initialize_cb_is_null = initialize_cb_.is_null(); |
+ } |
+ if (initialize_cb_is_null) { |
loader_->Stop(); |
return; |
} |
@@ -452,7 +471,7 @@ |
return; |
} |
- UpdateHostState(); |
+ UpdateHostState_Locked(); |
DoneInitialization_Locked(media::PIPELINE_OK); |
} |
} |
@@ -461,7 +480,12 @@ |
DCHECK(MessageLoop::current() == render_loop_); |
DCHECK(loader_.get()); |
- if (initialize_cb_.is_null()) { |
+ bool initialize_cb_is_null = false; |
+ { |
+ base::AutoLock auto_lock(lock_); |
+ initialize_cb_is_null = initialize_cb_.is_null(); |
+ } |
+ if (initialize_cb_is_null) { |
loader_->Stop(); |
return; |
} |
@@ -501,7 +525,7 @@ |
return; |
} |
- UpdateHostState(); |
+ UpdateHostState_Locked(); |
DoneInitialization_Locked(media::PIPELINE_OK); |
} |
} |
@@ -618,7 +642,10 @@ |
host()->SetBufferedBytes(buffered_bytes_); |
} |
-void BufferedDataSource::UpdateHostState() { |
+void BufferedDataSource::UpdateHostState_Locked() { |
+ // Called from various threads, under lock. |
+ lock_.AssertAcquired(); |
+ |
media::FilterHost* filter_host = host(); |
if (!filter_host) |
return; |