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

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

Issue 917433003: Update mojo sdk to rev 1027d24a1f68c6d10b7539b32114f1272b2cc9f1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add //build/module_args/mojo.gni. Created 5 years, 10 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 b8bc423eedfffcb17767865175fee3b6e3d90b51..c2ed95572475d3826637e33486d468cff2afb325 100644
--- a/third_party/mojo/src/mojo/public/cpp/bindings/callback.h
+++ b/third_party/mojo/src/mojo/public/cpp/bindings/callback.h
@@ -37,10 +37,15 @@ 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 Run() method.
+ // as it has a compatible operator() or Run() method. operator() will be
+ // prefered if the type has both.
template <typename Sink>
- Callback(const Sink& sink)
- : sink_(new Adapter<Sink>(sink)) {}
+ Callback(const Sink& sink) {
+ using sink_type = typename internal::Conditional<
+ internal::HasCompatibleCallOperator<Sink, Args...>::value,
+ FunctorAdapter<Sink>, RunnableAdapter<Sink>>::type;
+ sink_ = internal::SharedPtr<Runnable>(new sink_type(sink));
+ }
// Executes the callback function, invoking Pass() on move-only types.
void Run(typename internal::Callback_ParamTraits<Args>::ForwardType... args)
@@ -58,8 +63,8 @@ class Callback<void(Args...)> {
// Adapts a class that has a Run() method but is not derived from Runnable to
// be callable by Callback.
template <typename Sink>
- struct Adapter : public Runnable {
- explicit Adapter(const Sink& sink) : sink(sink) {}
+ struct RunnableAdapter : public Runnable {
+ explicit RunnableAdapter(const Sink& sink) : sink(sink) {}
virtual void Run(
typename internal::Callback_ParamTraits<Args>::ForwardType... args)
const override {
@@ -68,6 +73,18 @@ class Callback<void(Args...)> {
Sink sink;
};
+ // Adapts a class that has a compatible operator() callable by Callback.
+ template <typename Sink>
+ struct FunctorAdapter : public Runnable {
+ explicit FunctorAdapter(const Sink& sink) : sink(sink) {}
+ virtual void Run(
+ typename internal::Callback_ParamTraits<Args>::ForwardType... args)
+ const override {
+ sink.operator()(internal::Forward(args)...);
+ }
+ Sink sink;
+ };
+
internal::SharedPtr<Runnable> sink_;
};
« no previous file with comments | « third_party/mojo/src/mojo/public/VERSION ('k') | third_party/mojo/src/mojo/public/cpp/bindings/lib/callback_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698