Skip to content

Commit

Permalink
Cleaned up threadiness of BufferedDataSource.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fischman@chromium.org committed Sep 27, 2011
1 parent f22f58d commit 96a1b13
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
47 changes: 37 additions & 10 deletions webkit/glue/media/buffered_data_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -262,6 +273,7 @@ void BufferedDataSource::CleanupTask() {

{
base::AutoLock auto_lock(lock_);
initialize_cb_.Reset();
if (stopped_on_render_loop_)
return;

Expand Down Expand Up @@ -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_)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -465,7 +484,7 @@ void BufferedDataSource::HttpInitialStartCallback(int error) {
return;
}

UpdateHostState();
UpdateHostState_Locked();
DoneInitialization_Locked(media::PIPELINE_OK);
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -514,7 +538,7 @@ void BufferedDataSource::NonHttpInitialStartCallback(int error) {
return;
}

UpdateHostState();
UpdateHostState_Locked();
DoneInitialization_Locked(media::PIPELINE_OK);
}
}
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions webkit/glue/media/buffered_data_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 96a1b13

Please sign in to comment.