Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(861)

Unified Diff: third_party/mojo/src/mojo/public/cpp/bindings/callback.h

Issue 1310103002: Update mojo sdk to rev c02a28868825edfa57ab77947b8cb15e741c5598 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_;
};
« no previous file with comments | « third_party/mojo/src/mojo/public/cpp/bindings/binding.h ('k') | third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698