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

Side by Side Diff: mojo/public/cpp/bindings/callback.h

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/binding.h ('k') | mojo/public/cpp/bindings/error_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
7
8 #include "mojo/public/cpp/bindings/lib/callback_internal.h"
9 #include "mojo/public/cpp/bindings/lib/shared_ptr.h"
10 #include "mojo/public/cpp/bindings/lib/template_util.h"
11
12 namespace mojo {
13
14 template <typename Sig>
15 class Callback;
16
17 template <typename... Args>
18 class Callback<void(Args...)> {
19 public:
20 struct Runnable {
21 virtual ~Runnable() {}
22 virtual void Run(
23 typename internal::Callback_ParamTraits<Args>::ForwardType...)
24 const = 0;
25 };
26
27 Callback() {}
28
29 // The Callback assumes ownership of |runnable|.
30 explicit Callback(Runnable* runnable) : sink_(runnable) {}
31
32 // Any class that is copy-constructable and has a compatible Run method may
33 // be adapted to a Callback using this constructor.
34 template <typename Sink>
35 Callback(const Sink& sink)
36 : sink_(new Adapter<Sink>(sink)) {}
37
38 void Run(typename internal::Callback_ParamTraits<Args>::ForwardType... args)
39 const {
40 if (sink_.get())
41 sink_->Run(internal::Forward(args)...);
42 }
43
44 bool is_null() const { return !sink_.get(); }
45
46 void reset() { sink_.reset(); }
47
48 private:
49 template <typename Sink>
50 struct Adapter : public Runnable {
51 explicit Adapter(const Sink& sink) : sink(sink) {}
52 virtual void Run(
53 typename internal::Callback_ParamTraits<Args>::ForwardType... args)
54 const override {
55 sink.Run(internal::Forward(args)...);
56 }
57 Sink sink;
58 };
59
60 internal::SharedPtr<Runnable> sink_;
61 };
62
63 typedef Callback<void()> Closure;
64
65 } // namespace mojo
66
67 #endif // MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/binding.h ('k') | mojo/public/cpp/bindings/error_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698