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

Side by Side Diff: base/mac/bind_objc_block.h

Issue 708743002: Update base::BindBlock for three parameters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/mac/bind_objc_block_unittest.mm » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_MAC_BIND_OBJC_BLOCK_H_ 5 #ifndef BASE_MAC_BIND_OBJC_BLOCK_H_
6 #define BASE_MAC_BIND_OBJC_BLOCK_H_ 6 #define BASE_MAC_BIND_OBJC_BLOCK_H_
7 7
8 #include <Block.h> 8 #include <Block.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 27 matching lines...) Expand all
38 R(^extracted_block)(A1) = block.get(); 38 R(^extracted_block)(A1) = block.get();
39 return extracted_block(a); 39 return extracted_block(a);
40 } 40 }
41 41
42 template<typename R, typename A1, typename A2> 42 template<typename R, typename A1, typename A2>
43 R RunBlock(base::mac::ScopedBlock<R(^)(A1, A2)> block, A1 a, A2 b) { 43 R RunBlock(base::mac::ScopedBlock<R(^)(A1, A2)> block, A1 a, A2 b) {
44 R(^extracted_block)(A1, A2) = block.get(); 44 R(^extracted_block)(A1, A2) = block.get();
45 return extracted_block(a, b); 45 return extracted_block(a, b);
46 } 46 }
47 47
48 template<typename R, typename A1, typename A2, typename A3>
49 R RunBlock(base::mac::ScopedBlock<R(^)(A1, A2, A3)> block, A1 a, A2 b, A3 c) {
50 R(^extracted_block)(A1, A2, A3) = block.get();
51 return extracted_block(a, b, c);
Nico 2014/11/06 17:44:47 Can you make RunBlock() a variadic template? Then
marq (ping after 24h) 2014/11/07 09:00:55 Done, and BindBlock() is now also variadic.
52 }
53
48 } // namespace internal 54 } // namespace internal
49 55
50 // Construct a callback with no argument from an objective-C block. 56 // Construct a callback with no argument from an objective-C block.
51 template<typename R> 57 template<typename R>
52 base::Callback<R(void)> BindBlock(R(^block)()) { 58 base::Callback<R(void)> BindBlock(R(^block)()) {
53 return base::Bind(&base::internal::RunBlock<R>, 59 return base::Bind(&base::internal::RunBlock<R>,
54 base::mac::ScopedBlock<R(^)()>(Block_copy(block))); 60 base::mac::ScopedBlock<R(^)()>(Block_copy(block)));
55 } 61 }
56 62
57 // Construct a callback with one argument from an objective-C block. 63 // Construct a callback with one argument from an objective-C block.
58 template<typename R, typename A1> 64 template<typename R, typename A1>
59 base::Callback<R(A1)> BindBlock(R(^block)(A1)) { 65 base::Callback<R(A1)> BindBlock(R(^block)(A1)) {
60 return base::Bind(&base::internal::RunBlock<R, A1>, 66 return base::Bind(&base::internal::RunBlock<R, A1>,
61 base::mac::ScopedBlock<R(^)(A1)>(Block_copy(block))); 67 base::mac::ScopedBlock<R(^)(A1)>(Block_copy(block)));
62 } 68 }
63 69
64 // Construct a callback with two arguments from an objective-C block. 70 // Construct a callback with two arguments from an objective-C block.
65 template<typename R, typename A1, typename A2> 71 template<typename R, typename A1, typename A2>
66 base::Callback<R(A1, A2)> BindBlock(R(^block)(A1, A2)) { 72 base::Callback<R(A1, A2)> BindBlock(R(^block)(A1, A2)) {
67 return base::Bind(&base::internal::RunBlock<R, A1, A2>, 73 return base::Bind(&base::internal::RunBlock<R, A1, A2>,
68 base::mac::ScopedBlock<R(^)(A1, A2)>(Block_copy(block))); 74 base::mac::ScopedBlock<R(^)(A1, A2)>(Block_copy(block)));
69 } 75 }
70 76
77 // Construct a callback with three arguments from an objective-C block.
78 template<typename R, typename A1, typename A2, typename A3>
79 base::Callback<R(A1, A2, A3)> BindBlock(R(^block)(A1, A2, A3)) {
80 return base::Bind(&base::internal::RunBlock<R, A1, A2, A3>,
81 base::mac::ScopedBlock<R(^)(A1, A2, A3)>(
82 Block_copy(block)));
83 }
84
71 } // namespace base 85 } // namespace base
72 86
73 #endif // BASE_MAC_BIND_OBJC_BLOCK_H_ 87 #endif // BASE_MAC_BIND_OBJC_BLOCK_H_
OLDNEW
« no previous file with comments | « no previous file | base/mac/bind_objc_block_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698