Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / base / mac / bind_objc_block.h
index 75da437..9deb2d2 100644 (file)
 // BindBlock builds a callback from an Objective-C block. Example usages:
 //
 // Closure closure = BindBlock(^{DoSomething();});
+//
 // Callback<int(void)> callback = BindBlock(^{return 42;});
+//
+// Callback<void(const std::string&, const std::string&)> callback =
+//     BindBlock(^(const std::string& arg0, const std::string& arg1) {
+//         ...
+//     });
 
 namespace base {
 
@@ -33,6 +39,12 @@ R RunBlock(base::mac::ScopedBlock<R(^)(A1)> block, A1 a) {
   return extracted_block(a);
 }
 
+template<typename R, typename A1, typename A2>
+R RunBlock(base::mac::ScopedBlock<R(^)(A1, A2)> block, A1 a, A2 b) {
+  R(^extracted_block)(A1, A2) = block.get();
+  return extracted_block(a, b);
+}
+
 }  // namespace internal
 
 // Construct a callback with no argument from an objective-C block.
@@ -49,6 +61,13 @@ base::Callback<R(A1)> BindBlock(R(^block)(A1)) {
                     base::mac::ScopedBlock<R(^)(A1)>(Block_copy(block)));
 }
 
+// Construct a callback with two arguments from an objective-C block.
+template<typename R, typename A1, typename A2>
+base::Callback<R(A1, A2)> BindBlock(R(^block)(A1, A2)) {
+  return base::Bind(&base::internal::RunBlock<R, A1, A2>,
+                    base::mac::ScopedBlock<R(^)(A1, A2)>(Block_copy(block)));
+}
+
 }  // namespace base
 
 #endif  // BASE_MAC_BIND_OBJC_BLOCK_H_