Index: third_party/mojo/src/mojo/public/cpp/bindings/callback.h |
diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/callback.h b/third_party/mojo/src/mojo/public/cpp/bindings/callback.h |
index 17d1caf24a18efcb54b9602fd7b34fdbcd09698c..beec1a102e7024a44a33b51c20ba9da49e1ee4fe 100644 |
--- a/third_party/mojo/src/mojo/public/cpp/bindings/callback.h |
+++ b/third_party/mojo/src/mojo/public/cpp/bindings/callback.h |
@@ -37,7 +37,7 @@ class Callback<void(Args...)> { |
explicit Callback(Runnable* runnable) : sink_(runnable) {} |
// As above, but can take an object that isn't derived from Runnable, so long |
- // as it has a compatible operator() or Run() method. operator() will be |
+ // as it has a compatible operator() or Run() method. operator() will be |
// preferred if the type has both. |
template <typename Sink> |
Callback(const Sink& sink) { |
@@ -47,6 +47,11 @@ class Callback<void(Args...)> { |
sink_ = internal::SharedPtr<Runnable>(new sink_type(sink)); |
} |
+ // As above, but can take a compatible function pointer. |
+ Callback(void (*function_ptr)( |
+ typename internal::Callback_ParamTraits<Args>::ForwardType...)) |
+ : sink_(new FunctionPtrAdapter(function_ptr)) {} |
+ |
// Executes the callback function, invoking Pass() on move-only types. |
void Run(typename internal::Callback_ParamTraits<Args>::ForwardType... args) |
const { |
@@ -73,7 +78,7 @@ class Callback<void(Args...)> { |
Sink sink; |
}; |
- // Adapts a class that has a compatible operator() callable by Callback. |
+ // Adapts a class that has a compatible operator() to be callable by Callback. |
template <typename Sink> |
struct FunctorAdapter : public Runnable { |
explicit FunctorAdapter(const Sink& sink) : sink(sink) {} |
@@ -85,6 +90,20 @@ class Callback<void(Args...)> { |
Sink sink; |
}; |
+ // Adapts a function pointer. |
+ struct FunctionPtrAdapter : public Runnable { |
+ explicit FunctionPtrAdapter(void (*function_ptr)( |
+ typename internal::Callback_ParamTraits<Args>::ForwardType...)) |
+ : function_ptr(function_ptr) {} |
+ virtual void Run( |
+ typename internal::Callback_ParamTraits<Args>::ForwardType... args) |
+ const override { |
+ (*function_ptr)(internal::Forward(args)...); |
+ } |
+ void (*function_ptr)( |
+ typename internal::Callback_ParamTraits<Args>::ForwardType...); |
+ }; |
+ |
internal::SharedPtr<Runnable> sink_; |
}; |