summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-30 21:55:51 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-30 21:55:51 +0000
commit83ca5d6f9b403134e1f7ebeb1253328e14cfc1db (patch)
tree86925e90ea86282dec3c7c1927e1525ccfff4ae4
parent7dc95e485bc44c7d4736df11bda08d8bf0eb816b (diff)
downloadchromium_src-83ca5d6f9b403134e1f7ebeb1253328e14cfc1db.zip
chromium_src-83ca5d6f9b403134e1f7ebeb1253328e14cfc1db.tar.gz
chromium_src-83ca5d6f9b403134e1f7ebeb1253328e14cfc1db.tar.bz2
Simplify some callbacks-related code now that Bind can curry Callback->Closure.
BUG=none TEST=media_unittests, trybots Review URL: http://codereview.chromium.org/8099001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103553 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/base/composite_filter.cc29
-rw-r--r--media/base/composite_filter.h5
-rw-r--r--media/filters/chunk_demuxer.cc21
-rw-r--r--media/filters/chunk_demuxer_factory.cc18
4 files changed, 18 insertions, 55 deletions
diff --git a/media/base/composite_filter.cc b/media/base/composite_filter.cc
index a7af090..1716f3a 100644
--- a/media/base/composite_filter.cc
+++ b/media/base/composite_filter.cc
@@ -397,31 +397,22 @@ void CompositeFilter::SendErrorToHost(PipelineStatus error) {
host_impl_.get()->host()->SetError(error);
}
+// Execute |closure| if on |message_loop|, otherwise post to it.
+static void TrampolineClosureIfNecessary(MessageLoop* message_loop,
+ const base::Closure& closure) {
+ if (MessageLoop::current() == message_loop)
+ closure.Run();
+ else
+ message_loop->PostTask(FROM_HERE, closure);
+}
+
base::Closure CompositeFilter::NewThreadSafeCallback(
void (CompositeFilter::*method)()) {
- return base::Bind(&CompositeFilter::OnCallback,
+ return base::Bind(&TrampolineClosureIfNecessary,
message_loop_,
base::Bind(method, weak_ptr_factory_.GetWeakPtr()));
}
-// This method is intentionally static so that no reference to the composite
-// is needed to call it. This method may be called by other threads and we
-// don't want those threads to gain ownership of this composite by having a
-// reference to it. |closure| will contain a weak reference to the composite
-// so that the reference can be cleared if the composite is destroyed before
-// the callback is called.
-// static
-void CompositeFilter::OnCallback(MessageLoop* message_loop,
- const base::Closure& closure) {
- if (MessageLoop::current() != message_loop) {
- // Posting callback to the proper thread.
- message_loop->PostTask(FROM_HERE, closure);
- return;
- }
-
- closure.Run();
-}
-
bool CompositeFilter::CanForwardError() {
return (state_ == kCreated) || (state_ == kPlaying) || (state_ == kPaused);
}
diff --git a/media/base/composite_filter.h b/media/base/composite_filter.h
index 712fecb..4b35be3 100644
--- a/media/base/composite_filter.h
+++ b/media/base/composite_filter.h
@@ -99,11 +99,6 @@ class MEDIA_EXPORT CompositeFilter : public Filter {
// to call the specified method on the thread associated with this filter.
base::Closure NewThreadSafeCallback(void (CompositeFilter::*method)());
- // Helper function used by NewThreadSafeCallback() to make sure the
- // method gets called on the right thread.
- static void OnCallback(MessageLoop* message_loop,
- const base::Closure& closure);
-
// Helper function that indicates whether SetError() calls can be forwarded
// to the host of this filter.
bool CanForwardError();
diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc
index d8e0604..b75a71a 100644
--- a/media/filters/chunk_demuxer.cc
+++ b/media/filters/chunk_demuxer.cc
@@ -83,8 +83,6 @@ class ChunkDemuxerStream : public DemuxerStream {
virtual const AudioDecoderConfig& audio_decoder_config();
private:
- static void RunCallback(ReadCallback cb, scoped_refptr<Buffer> buffer);
-
Type type_;
AVStream* av_stream_;
AudioDecoderConfig audio_config_;
@@ -174,9 +172,7 @@ void ChunkDemuxerStream::AddBuffers(const BufferQueue& buffers) {
}
while (!buffers_.empty() && !read_cbs_.empty()) {
- callbacks.push_back(base::Bind(&ChunkDemuxerStream::RunCallback,
- read_cbs_.front(),
- buffers_.front()));
+ callbacks.push_back(base::Bind(read_cbs_.front(), buffers_.front()));
buffers_.pop_front();
read_cbs_.pop_front();
}
@@ -220,23 +216,14 @@ bool ChunkDemuxerStream::GetLastBufferTimestamp(
return true;
}
-// Helper function used to make Closures for ReadCallbacks.
-//static
-void ChunkDemuxerStream::RunCallback(ReadCallback cb,
- scoped_refptr<Buffer> buffer) {
- cb.Run(buffer);
-}
-
// Helper function that makes sure |read_callback| runs on |message_loop|.
static void RunOnMessageLoop(const DemuxerStream::ReadCallback& read_callback,
MessageLoop* message_loop,
Buffer* buffer) {
if (MessageLoop::current() != message_loop) {
- message_loop->PostTask(FROM_HERE,
- base::Bind(&RunOnMessageLoop,
- read_callback,
- message_loop,
- scoped_refptr<Buffer>(buffer)));
+ message_loop->PostTask(FROM_HERE, base::Bind(
+ &RunOnMessageLoop, read_callback, message_loop,
+ scoped_refptr<Buffer>(buffer)));
return;
}
diff --git a/media/filters/chunk_demuxer_factory.cc b/media/filters/chunk_demuxer_factory.cc
index 7887494..0f6920f 100644
--- a/media/filters/chunk_demuxer_factory.cc
+++ b/media/filters/chunk_demuxer_factory.cc
@@ -10,23 +10,13 @@
namespace media {
-static void DoInitDone(const DemuxerFactory::BuildCallback& cb,
- const scoped_refptr<Demuxer>& demuxer,
- PipelineStatus status) {
- if (status != PIPELINE_OK) {
- cb.Run(status, static_cast<Demuxer*>(NULL));
- return;
- }
-
- cb.Run(status, demuxer);
-}
-
static void InitDone(MessageLoop* message_loop,
const DemuxerFactory::BuildCallback& cb,
- const scoped_refptr<Demuxer>& demuxer,
+ scoped_refptr<Demuxer> demuxer,
PipelineStatus status) {
- message_loop->PostTask(FROM_HERE,
- base::Bind(&DoInitDone, cb, demuxer, status));
+ if (status != PIPELINE_OK)
+ demuxer = NULL;
+ message_loop->PostTask(FROM_HERE, base::Bind(cb, status, demuxer));
}
ChunkDemuxerFactory::ChunkDemuxerFactory(const std::string& url,