Index: third_party/WebKit/public/platform/functional/WebFunction.h |
diff --git a/third_party/WebKit/public/platform/callback/WebClosure.h b/third_party/WebKit/public/platform/functional/WebFunction.h |
similarity index 52% |
rename from third_party/WebKit/public/platform/callback/WebClosure.h |
rename to third_party/WebKit/public/platform/functional/WebFunction.h |
index 5666e3f2de8f0cd12578e51d9f31cbc2c45ea81a..7d0c13b480ebba48111ccde61f59adb814d2bca6 100644 |
--- a/third_party/WebKit/public/platform/callback/WebClosure.h |
+++ b/third_party/WebKit/public/platform/functional/WebFunction.h |
@@ -2,8 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef WebClosure_h |
-#define WebClosure_h |
+#ifndef WebFunction_h |
+#define WebFunction_h |
#include "base/bind.h" |
#include "base/callback.h" |
@@ -23,57 +23,76 @@ |
namespace blink { |
+template <typename...> |
+class WebFunction; |
+ |
// Conversion from WTF closures to base closures to pass a callback out of |
// blink. |
-class WebClosure { |
+template <typename R, typename... Args> |
+class WebFunction<R(Args...)> { |
+private: |
+#if BLINK_IMPLEMENTATION |
+ using WTFFunction = WTF::Function<R(Args...), WTF::SameThreadAffinity>; |
+#endif |
+ |
public: |
#if BLINK_IMPLEMENTATION |
- WebClosure() {} |
+ WebFunction() |
+ { |
+ } |
- explicit WebClosure(PassOwnPtr<SameThreadClosure> c) |
+ explicit WebFunction(PassOwnPtr<WTFFunction> c) |
{ |
- m_closure = base::Bind(&RunAndDelete, base::Passed(base::WrapUnique(c.leakPtr()))); |
+ m_callback = base::Bind(&RunAndDelete<R, Args...>, base::Passed(base::WrapUnique(c.leakPtr()))); |
danakj
2016/04/12 21:42:16
A problem came up in the webgl tests. Using Passed
|
} |
#endif |
- // TODO(danakj): These could be =default with MSVC 2015. |
- WebClosure(WebClosure&& other) { *this = std::move(other); } |
- WebClosure& operator=(WebClosure&& other) |
+ WebFunction(WebFunction&& other) |
+ { |
+ *this = std::move(other); |
+ } |
+ WebFunction& operator=(WebFunction&& other) |
{ |
#if DCHECK_IS_ON() |
m_haveClosure = other.m_haveClosure; |
other.m_haveClosure = false; |
#endif |
- m_closure = std::move(other.m_closure); |
+ m_callback = std::move(other.m_callback); |
return *this; |
} |
#if !BLINK_IMPLEMENTATION |
// TODO(danakj): This could be rvalue-ref-qualified. |
- base::Closure TakeBaseClosure() |
+ base::Callback<R(Args...)> TakeBaseCallback() |
{ |
#if DCHECK_IS_ON() |
// Don't call this more than once! |
DCHECK(m_haveClosure); |
m_haveClosure = false; |
#endif |
- return std::move(m_closure); |
+ return std::move(m_callback); |
} |
#endif |
private: |
#if BLINK_IMPLEMENTATION |
- static void RunAndDelete(std::unique_ptr<SameThreadClosure> c) { (*c)(); } |
+ template <typename RunR, typename... RunArgs> |
+ static RunR RunAndDelete(std::unique_ptr<WTFFunction> c, RunArgs... args) |
+ { |
+ return (*c)(std::forward<RunArgs>(args)...); |
+ } |
#endif |
#if DCHECK_IS_ON() |
bool m_haveClosure = true; |
#endif |
- base::Closure m_closure; |
+ base::Callback<R(Args...)> m_callback; |
- DISALLOW_COPY_AND_ASSIGN(WebClosure); |
+ DISALLOW_COPY_AND_ASSIGN(WebFunction); |
}; |
+using WebClosure = WebFunction<void()>; |
+ |
} // namespace blink |
#endif // WebClosure_h |