summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-27 20:55:29 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-27 20:55:29 +0000
commit96a1b138fefd2440b5b8cf9c39ae0c6cc1da4193 (patch)
tree18c63da3ada65e873018621eb74fe15c92d0379f
parentf22f58df3f419245a852188d3b2be25abd9a515a (diff)
downloadchromium_src-96a1b138fefd2440b5b8cf9c39ae0c6cc1da4193.zip
chromium_src-96a1b138fefd2440b5b8cf9c39ae0c6cc1da4193.tar.gz
chromium_src-96a1b138fefd2440b5b8cf9c39ae0c6cc1da4193.tar.bz2
Cleaned up threadiness of BufferedDataSource.
BUG=96292 TEST=trybots Review URL: http://codereview.chromium.org/8046023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103008 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/glue/media/buffered_data_source.cc47
-rw-r--r--webkit/glue/media/buffered_data_source.h7
2 files changed, 42 insertions, 12 deletions
diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc
index 1a6c710..29df58f 100644
--- a/webkit/glue/media/buffered_data_source.cc
+++ b/webkit/glue/media/buffered_data_source.cc
@@ -85,8 +85,10 @@ BufferedResourceLoader* BufferedDataSource::CreateResourceLoader(
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 @@ void BufferedDataSource::Initialize(const std::string& url,
}
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,
@@ -210,8 +215,14 @@ void BufferedDataSource::Abort() {
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
@@ -262,6 +273,7 @@ void BufferedDataSource::CleanupTask() {
{
base::AutoLock auto_lock(lock_);
+ initialize_cb_.Reset();
if (stopped_on_render_loop_)
return;
@@ -334,6 +346,7 @@ void BufferedDataSource::SetBitrateTask(int bitrate) {
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_)
@@ -411,7 +424,13 @@ void BufferedDataSource::HttpInitialStartCallback(int error) {
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;
}
@@ -465,7 +484,7 @@ void BufferedDataSource::HttpInitialStartCallback(int error) {
return;
}
- UpdateHostState();
+ UpdateHostState_Locked();
DoneInitialization_Locked(media::PIPELINE_OK);
}
}
@@ -474,7 +493,12 @@ void BufferedDataSource::NonHttpInitialStartCallback(int error) {
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;
}
@@ -514,7 +538,7 @@ void BufferedDataSource::NonHttpInitialStartCallback(int error) {
return;
}
- UpdateHostState();
+ UpdateHostState_Locked();
DoneInitialization_Locked(media::PIPELINE_OK);
}
}
@@ -631,7 +655,10 @@ void BufferedDataSource::NetworkEventCallback() {
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;
diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h
index 4dc3e96..fd20e64 100644
--- a/webkit/glue/media/buffered_data_source.h
+++ b/webkit/glue/media/buffered_data_source.h
@@ -20,6 +20,8 @@ class MediaLog;
namespace webkit_glue {
+// This class may be created on any thread, and is callable from the render
+// thread as well as media-specific threads.
class BufferedDataSource : public WebDataSource {
public:
// Creates a DataSourceFactory for building BufferedDataSource objects.
@@ -129,7 +131,7 @@ class BufferedDataSource : public WebDataSource {
// Callback method when a network event is received.
void NetworkEventCallback();
- void UpdateHostState();
+ void UpdateHostState_Locked();
// URL of the resource requested.
GURL url_;
@@ -182,7 +184,8 @@ class BufferedDataSource : public WebDataSource {
// The message loop of the render thread.
MessageLoop* render_loop_;
- // Protects |stopped_|.
+ // Protects |stop_signal_received_|, |stopped_on_render_loop_| and
+ // |initialize_cb_|.
base::Lock lock_;
// Stop signal to suppressing activities. This variable is set on the pipeline