summaryrefslogtreecommitdiffstats
path: root/webkit/glue/media
diff options
context:
space:
mode:
authorboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 17:40:15 +0000
committerboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 17:40:15 +0000
commit5badb08f6f862645e950d97c7a58995724cd0c42 (patch)
tree415b0860139754f61db04cde1f4dba9501fd47be /webkit/glue/media
parent21ab5b9c9c64061b15d79a29b5ea337e4acc8953 (diff)
downloadchromium_src-5badb08f6f862645e950d97c7a58995724cd0c42.zip
chromium_src-5badb08f6f862645e950d97c7a58995724cd0c42.tar.gz
chromium_src-5badb08f6f862645e950d97c7a58995724cd0c42.tar.bz2
Make MediaFilter::Stop() asynchronous.
This is the second issue regarding making Stop() asynchronous. All Stop() in subclasses of MediaFilter is made to accept a callback and runs the callback at the end of its stop. BUG=16059 TEST=media_unittest, unit_tests, test_shell_tests still passes Review URL: http://codereview.chromium.org/2541003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49548 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/media')
-rw-r--r--webkit/glue/media/buffered_data_source.cc18
-rw-r--r--webkit/glue/media/buffered_data_source.h12
-rw-r--r--webkit/glue/media/buffered_data_source_unittest.cc7
-rw-r--r--webkit/glue/media/simple_data_source.cc8
-rw-r--r--webkit/glue/media/simple_data_source.h4
-rw-r--r--webkit/glue/media/simple_data_source_unittest.cc7
6 files changed, 36 insertions, 20 deletions
diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc
index bf91da0..64e09b4 100644
--- a/webkit/glue/media/buffered_data_source.cc
+++ b/webkit/glue/media/buffered_data_source.cc
@@ -592,13 +592,17 @@ void BufferedDataSource::Initialize(const std::string& url,
NewRunnableMethod(this, &BufferedDataSource::InitializeTask));
}
-void BufferedDataSource::Stop() {
+void BufferedDataSource::Stop(media::FilterCallback* callback) {
{
AutoLock auto_lock(lock_);
stop_signal_received_ = true;
}
+ if (callback) {
+ callback->Run();
+ delete callback;
+ }
render_loop_->PostTask(FROM_HERE,
- NewRunnableMethod(this, &BufferedDataSource::StopTask));
+ NewRunnableMethod(this, &BufferedDataSource::CleanupTask));
}
/////////////////////////////////////////////////////////////////////////////
@@ -664,7 +668,7 @@ void BufferedDataSource::ReadTask(
media::DataSource::ReadCallback* read_callback) {
DCHECK(MessageLoop::current() == render_loop_);
- // If StopTask() was executed we should return immediately. We check this
+ // If CleanupTask() was executed we should return immediately. We check this
// variable to prevent doing any actual work after clean up was done. We do
// not check |stop_signal_received_| because anything use of it has to be
// within |lock_| which is not desirable.
@@ -686,7 +690,7 @@ void BufferedDataSource::ReadTask(
ReadInternal();
}
-void BufferedDataSource::StopTask() {
+void BufferedDataSource::CleanupTask() {
DCHECK(MessageLoop::current() == render_loop_);
DCHECK(!stopped_on_render_loop_);
@@ -712,11 +716,11 @@ void BufferedDataSource::StopTask() {
void BufferedDataSource::RestartLoadingTask() {
DCHECK(MessageLoop::current() == render_loop_);
- // This variable is set in StopTask(). We check this and do an early return.
- // The sequence of actions which enable this conditions is:
+ // This variable is set in CleanupTask(). We check this and do an early
+ // return. The sequence of actions which enable this conditions is:
// 1. Stop() is called from the pipeline.
// 2. ReadCallback() is called from the resource loader.
- // 3. StopTask() is executed.
+ // 3. CleanupTask() is executed.
// 4. RestartLoadingTask() is executed.
if (stopped_on_render_loop_)
return;
diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h
index 74813a9..4440f2f 100644
--- a/webkit/glue/media/buffered_data_source.h
+++ b/webkit/glue/media/buffered_data_source.h
@@ -230,7 +230,7 @@ class BufferedDataSource : public media::DataSource {
// media::MediaFilter implementation.
virtual void Initialize(const std::string& url,
media::FilterCallback* callback);
- virtual void Stop();
+ virtual void Stop(media::FilterCallback* callback);
// media::DataSource implementation.
// Called from demuxer thread.
@@ -275,15 +275,17 @@ class BufferedDataSource : public media::DataSource {
void ReadTask(int64 position, int read_size, uint8* read_buffer,
media::DataSource::ReadCallback* read_callback);
- // Task posted when Stop() is called.
- void StopTask();
+ // Task posted when Stop() is called. Stops |watch_dog_timer_| and
+ // |loader_|, reset Read() variables, and set |stopped_on_render_loop_|
+ // to signal any remaining tasks to stop.
+ void CleanupTask();
// Restart resource loading on render thread.
void RestartLoadingTask();
// This task monitors the current active read request. If the current read
// request has timed out, this task will destroy the current loader and
- // creates a new one to accomodate the read request.
+ // creates a new one to accommodate the read request.
void WatchDogTask();
// The method that performs actual read. This method can only be executed on
@@ -381,7 +383,7 @@ class BufferedDataSource : public media::DataSource {
// thread and read from the render thread.
bool stop_signal_received_;
- // This variable is set by StopTask() that indicates this object is stopped
+ // This variable is set by CleanupTask() that indicates this object is stopped
// on the render thread.
bool stopped_on_render_loop_;
diff --git a/webkit/glue/media/buffered_data_source_unittest.cc b/webkit/glue/media/buffered_data_source_unittest.cc
index 13e40f9..14e125c 100644
--- a/webkit/glue/media/buffered_data_source_unittest.cc
+++ b/webkit/glue/media/buffered_data_source_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -534,7 +534,10 @@ class BufferedDataSourceTest : public testing::Test {
EXPECT_CALL(*loader_, Stop());
}
- data_source_->Stop();
+ StrictMock<media::MockFilterCallback> callback;
+ EXPECT_CALL(callback, OnFilterCallback());
+ EXPECT_CALL(callback, OnCallbackDestroyed());
+ data_source_->Stop(callback.NewCallback());
message_loop_->RunAllPending();
}
diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc
index 57b294a..20bf0af 100644
--- a/webkit/glue/media/simple_data_source.cc
+++ b/webkit/glue/media/simple_data_source.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -56,9 +56,13 @@ SimpleDataSource::~SimpleDataSource() {
DCHECK(state_ == UNINITIALIZED || state_ == STOPPED);
}
-void SimpleDataSource::Stop() {
+void SimpleDataSource::Stop(media::FilterCallback* callback) {
AutoLock auto_lock(lock_);
state_ = STOPPED;
+ if (callback) {
+ callback->Run();
+ delete callback;
+ }
// Post a task to the render thread to cancel loading the resource.
render_loop_->PostTask(FROM_HERE,
diff --git a/webkit/glue/media/simple_data_source.h b/webkit/glue/media/simple_data_source.h
index 10bbb7d..577d973 100644
--- a/webkit/glue/media/simple_data_source.h
+++ b/webkit/glue/media/simple_data_source.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -39,7 +39,7 @@ class SimpleDataSource : public media::DataSource,
const media::MediaFormat& media_format);
// MediaFilter implementation.
- virtual void Stop();
+ virtual void Stop(media::FilterCallback* callback);
// DataSource implementation.
virtual void Initialize(const std::string& url,
diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc
index c43cbc9..e6acba9 100644
--- a/webkit/glue/media/simple_data_source_unittest.cc
+++ b/webkit/glue/media/simple_data_source_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -132,7 +132,10 @@ class SimpleDataSourceTest : public testing::Test {
EXPECT_CALL(*bridge_factory_, OnDestroy())
.WillOnce(Invoke(this, &SimpleDataSourceTest::ReleaseBridgeFactory));
- data_source_->Stop();
+ StrictMock<media::MockFilterCallback> callback;
+ EXPECT_CALL(callback, OnFilterCallback());
+ EXPECT_CALL(callback, OnCallbackDestroyed());
+ data_source_->Stop(callback.NewCallback());
MessageLoop::current()->RunAllPending();
data_source_ = NULL;