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

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

Issue 883843002: Update mojo sdk to rev 126532ce21c5c3c55a1e1693731411cb60169efd (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 11 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 d7bab1632fb87397c817123e4bdbe2e9a263a2de..b8bc423eedfffcb17767865175fee3b6e3d90b51 100644
--- a/third_party/mojo/src/mojo/public/cpp/bindings/callback.h
+++ b/third_party/mojo/src/mojo/public/cpp/bindings/callback.h
@@ -14,27 +14,35 @@ namespace mojo {
template <typename Sig>
class Callback;
+// Represents a callback with any number of parameters and no return value. The
+// callback is executed by calling its Run() method. The callback may be "null",
+// meaning it does nothing.
template <typename... Args>
class Callback<void(Args...)> {
public:
+ // An interface that may be implemented to define the Run() method.
struct Runnable {
virtual ~Runnable() {}
virtual void Run(
+ // ForwardType ensures String is passed as a const reference.
typename internal::Callback_ParamTraits<Args>::ForwardType...)
const = 0;
};
+ // Constructs a "null" callback that does nothing.
Callback() {}
- // The Callback assumes ownership of |runnable|.
+ // Constructs a callback that will run |runnable|. The callback takes
+ // ownership of |runnable|.
explicit Callback(Runnable* runnable) : sink_(runnable) {}
- // Any class that is copy-constructable and has a compatible Run method may
- // be adapted to a Callback using this constructor.
+ // As above, but can take an object that isn't derived from Runnable, so long
+ // as it has a Run() method.
template <typename Sink>
Callback(const Sink& sink)
: sink_(new Adapter<Sink>(sink)) {}
+ // Executes the callback function, invoking Pass() on move-only types.
void Run(typename internal::Callback_ParamTraits<Args>::ForwardType... args)
const {
if (sink_.get())
@@ -43,9 +51,12 @@ class Callback<void(Args...)> {
bool is_null() const { return !sink_.get(); }
+ // Resets the callback to the "null" state.
void reset() { sink_.reset(); }
private:
+ // 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) {}
@@ -60,6 +71,7 @@ class Callback<void(Args...)> {
internal::SharedPtr<Runnable> sink_;
};
+// A specialization of Callback which takes no parameters.
typedef Callback<void()> Closure;
} // namespace mojo
« no previous file with comments | « third_party/mojo/src/mojo/public/cpp/bindings/binding.h ('k') | third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698