Index: media/base/bind_to_loop.h.pump |
diff --git a/media/base/bind_to_loop.h.pump b/media/base/bind_to_loop.h.pump |
index 8490413eb1cc333cb2279712014f825c7487779c..e50e17543243886fb393d45a2323b364330a22dd 100644 |
--- a/media/base/bind_to_loop.h.pump |
+++ b/media/base/bind_to_loop.h.pump |
@@ -18,6 +18,7 @@ $var MAX_ARITY = 7 |
#include "base/bind.h" |
#include "base/location.h" |
#include "base/message_loop/message_loop_proxy.h" |
+#include "base/synchronization/waitable_event.h" |
// This is a helper utility for base::Bind()ing callbacks on to particular |
// MessageLoops. A typical use is when |a| (of class |A|) wants to hand a |
@@ -55,6 +56,10 @@ base::internal::PassedWrapper<ScopedVector<T> > TrampolineForward( |
template <typename T> struct TrampolineHelper; |
+// Caller helper to call a base::Closure synchronously |
+void TrampolineSyncCaller(const base::Closure& closure, |
+ base::WaitableEvent* waiter); |
+ |
$range ARITY 0..MAX_ARITY |
$for ARITY [[ |
$range ARG 1..ARITY |
@@ -71,6 +76,23 @@ $for ARG , [[A$(ARG) a$(ARG)]] |
$if ARITY != 0 [[, ]] |
$for ARG , [[internal::TrampolineForward(a$(ARG))]])); |
} |
+ static void RunSync( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<void($for ARG , [[A$(ARG)]])>& cb |
+$if ARITY != 0 [[, ]] |
+$for ARG , [[A$(ARG) a$(ARG)]] |
+) { |
+ base::WaitableEvent waiter(false, false); |
+ loop->PostTask( |
+ FROM_HERE, |
+ base::Bind( |
+ &TrampolineSyncCaller, |
+ base::Bind(cb |
+$if ARITY != 0 [[, ]] |
+$for ARG , [[internal::TrampolineForward(a$(ARG))]]), |
+ &waiter)); |
+ waiter.Wait(); |
+ } |
}; |
@@ -86,6 +108,14 @@ static base::Callback<T> BindToLoop( |
} |
template<typename T> |
+static base::Callback<T> BindToLoopSync( |
+ const scoped_refptr<base::MessageLoopProxy>& loop, |
+ const base::Callback<T>& cb) { |
+ DCHECK(!loop->BelongsToCurrentThread()); |
Ami GONE FROM CHROMIUM
2013/10/22 17:21:19
This wants to live inside RunSync, not here, right
sheu
2013/10/24 01:16:39
That's true. Done.
|
+ return base::Bind(&internal::TrampolineHelper<T>::RunSync, loop, cb); |
+} |
+ |
+template<typename T> |
static base::Callback<T> BindToCurrentLoop( |
Ami GONE FROM CHROMIUM
2013/10/22 17:21:19
...which gives rise to wondering whether there's g
|
const base::Callback<T>& cb) { |
return BindToLoop(base::MessageLoopProxy::current(), cb); |