Index: third_party/WebKit/Source/wtf/Functional.h |
diff --git a/third_party/WebKit/Source/wtf/Functional.h b/third_party/WebKit/Source/wtf/Functional.h |
index 34f721557c687bf5fb58009f24ec7e367afb56dc..bdcff7c12602e8cfd6f35a9fb937b235663cc1e4 100644 |
--- a/third_party/WebKit/Source/wtf/Functional.h |
+++ b/third_party/WebKit/Source/wtf/Functional.h |
@@ -61,8 +61,19 @@ namespace WTF { |
// WTF::bind() and WTF::Closure should be used for same-thread closures |
// only, i.e. the closures must be created, executed and destructed on |
// the same thread. |
-// Use crossThreadBind() and CrossThreadClosure if the function/task is called |
-// or destructed on a (potentially) different thread from the current thread. |
+// |
+// Use WTF::crossThreadBind() and WTF::CrossThreadClosure if the function/task |
+// is called or destructed on a (potentially) different thread from the current |
+// thread. |
+// WTF::crossThreadBind() applies CrossThreadCopier to the arguments. |
+// Example: |
+// void func1(int, const String&); |
+// f = crossThreadBind(func1, 42, str); |
+// func1(42, str2) will be called when |f()| is executed, |
+// where |str2| is a deep copy of |str| (created by str.isolatedCopy()). |
+// Don't (if you pass the task across threads): |
+// bind(func1, 42, str); |
+// bind(func1, 42, str.isolatedCopy()); |
// WTF::bind() and move semantics |
// ============================== |
@@ -269,11 +280,19 @@ std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters. |
return bindInternal<SameThreadAffinity>(function, std::forward<BoundParameters>(boundParameters)...); |
} |
+template <typename FunctionType, typename... BoundParameters> |
+std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters...>, CrossThreadAffinity>> crossThreadBind(FunctionType function, BoundParameters&&... boundParameters) |
+{ |
+ return bindInternal<CrossThreadAffinity>(function, CrossThreadCopier<typename std::decay<BoundParameters>::type>::copy(std::forward<BoundParameters>(boundParameters))...); |
+} |
+ |
typedef Function<void(), SameThreadAffinity> Closure; |
typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; |
} // namespace WTF |
+using WTF::crossThreadBind; |
+ |
using WTF::passed; |
using WTF::unretained; |
using WTF::crossThreadUnretained; |