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

Side by Side Diff: base/bind.h

Issue 2042223002: Introduce OnceClosure and BindOnce (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 | « no previous file | base/bind_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_BIND_H_ 5 #ifndef BASE_BIND_H_
6 #define BASE_BIND_H_ 6 #define BASE_BIND_H_
7 7
8 #include "base/bind_internal.h" 8 #include "base/bind_internal.h"
9 9
10 // ----------------------------------------------------------------------------- 10 // -----------------------------------------------------------------------------
11 // Usage documentation 11 // Usage documentation
12 // ----------------------------------------------------------------------------- 12 // -----------------------------------------------------------------------------
13 // 13 //
14 // See base/callback.h for documentation. 14 // See base/callback.h for documentation.
15 // 15 //
16 // 16 //
17 // ----------------------------------------------------------------------------- 17 // -----------------------------------------------------------------------------
18 // Implementation notes 18 // Implementation notes
19 // ----------------------------------------------------------------------------- 19 // -----------------------------------------------------------------------------
20 // 20 //
21 // If you're reading the implementation, before proceeding further, you should 21 // If you're reading the implementation, before proceeding further, you should
22 // read the top comment of base/bind_internal.h for a definition of common 22 // read the top comment of base/bind_internal.h for a definition of common
23 // terms and concepts. 23 // terms and concepts.
24 24
25 namespace base { 25 namespace base {
26 26
27 // Default Bind.
27 template <typename Functor, typename... Args> 28 template <typename Functor, typename... Args>
28 inline base::Callback<MakeUnboundRunType<Functor, Args...>> Bind( 29 inline base::Callback<MakeUnboundRunType<Functor, Args...>>
hiroshige 2016/07/04 10:04:22 It might be unclear for developers which Bind()/Ca
tzik 2016/07/06 07:36:13 Hmm, I think it's still not ready to use for devs,
hiroshige 2016/08/12 06:00:47 Placing new variants in internal namespace looks g
29 Functor&& functor, 30 Bind(Functor&& functor, Args&&... args) {
30 Args&&... args) {
31 using BindState = internal::MakeBindStateType<Functor, Args...>; 31 using BindState = internal::MakeBindStateType<Functor, Args...>;
32 using UnboundRunType = MakeUnboundRunType<Functor, Args...>; 32 using UnboundRunType = MakeUnboundRunType<Functor, Args...>;
33 using Invoker = internal::Invoker<BindState, UnboundRunType>; 33 using Invoker = internal::Invoker<BindState, UnboundRunType>;
34 34
35 using CallbackType = Callback<UnboundRunType>; 35 using CallbackType = Callback<UnboundRunType>;
36 return CallbackType(new BindState(std::forward<Functor>(functor), 36 return CallbackType(new BindState(std::forward<Functor>(functor),
37 std::forward<Args>(args)...), 37 std::forward<Args>(args)...),
38 &Invoker::Run); 38 &Invoker::Run);
39 } 39 }
40 40
41 // Bind as RepeatingCallback.
42 template <typename Functor, typename... Args>
43 inline base::RepeatingCallback<MakeUnboundRunType<Functor, Args...>>
44 BindRepeating(Functor&& functor, Args&&... args) {
45 using BindState = internal::MakeBindStateType<Functor, Args...>;
46 using UnboundRunType = MakeUnboundRunType<Functor, Args...>;
47 using Invoker = internal::Invoker<BindState, UnboundRunType>;
48
49 using CallbackType = RepeatingCallback<UnboundRunType>;
50 return CallbackType(new BindState(std::forward<Functor>(functor),
51 std::forward<Args>(args)...),
52 &Invoker::Run);
53 }
54
55 // Bind as OneShotCallback.
56 template <typename Functor, typename... Args>
57 inline base::OneShotCallback<MakeUnboundRunType<Functor, Args...>>
58 BindOneShot(Functor&& functor, Args&&... args) {
59 using BindState = internal::MakeBindStateType<Functor, Args...>;
60 using UnboundRunType = MakeUnboundRunType<Functor, Args...>;
61 using Invoker = internal::Invoker<BindState, UnboundRunType>;
62
63 using CallbackType = OneShotCallback<UnboundRunType>;
64 return CallbackType(new BindState(std::forward<Functor>(functor),
65 std::forward<Args>(args)...),
66 &Invoker::RunOneShot);
67 }
68
41 } // namespace base 69 } // namespace base
42 70
43 #endif // BASE_BIND_H_ 71 #endif // BASE_BIND_H_
OLDNEW
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698