Index: third_party/WebKit/public/platform/callback/WebClosure.h |
diff --git a/third_party/WebKit/public/platform/callback/WebClosure.h b/third_party/WebKit/public/platform/callback/WebClosure.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6de6aa5f586995fbc5a37571374c0ad26b333c92 |
--- /dev/null |
+++ b/third_party/WebKit/public/platform/callback/WebClosure.h |
@@ -0,0 +1,72 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// 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 |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/callback_helpers.h" |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "public/platform/WebCommon.h" |
+ |
+#include <utility> |
+ |
+#if BLINK_IMPLEMENTATION |
+#include "wtf/Functional.h" |
+#else |
+#include "base/logging.h" |
+#endif |
+ |
+namespace blink { |
+ |
+// Conversion from WTF closures to base closures to pass a callback out of |
+// blink. |
+class WebClosure { |
+public: |
+#if BLINK_IMPLEMENTATION |
+ WebClosure() {} |
+ |
+ explicit WebClosure(PassOwnPtr<SameThreadClosure> c) |
+ { |
+ auto run_and_delete = +[](scoped_ptr<SameThreadClosure> c) |
Ken Russell (switch to Gerrit)
2016/03/24 18:29:04
Is the "+" strictly needed to avoid compile errors
danakj
2016/03/24 18:36:50
The + let's bind work. Bind won't let you use a la
danakj
2016/03/24 18:38:09
But apparently does not work in MSVC. Cool.
|
+ { |
+ (*c)(); |
+ }; |
+ m_closure = base::Bind(run_and_delete, base::Passed(make_scoped_ptr(c.leakPtr()))); |
+ } |
+#endif |
+ |
+ // TODO(danakj): These could be =default with MSVC 2015. |
+ WebClosure(WebClosure&& other) { *this = std::move(other); } |
+ WebClosure& operator=(WebClosure&& other) |
+ { |
+ m_haveClosure = other.m_haveClosure; |
+ other.m_haveClosure = false; |
+ m_closure = std::move(other.m_closure); |
+ return *this; |
+ } |
+ |
+#if !BLINK_IMPLEMENTATION |
+ // TODO(danakj): This could be rvalue-ref-qualified. |
+ base::Closure ToBaseClosure() |
+ { |
+ // Don't call this more than once! |
+ DCHECK(m_haveClosure); |
+ m_haveClosure = false; |
+ return std::move(m_closure); |
+ } |
+#endif |
+ |
+private: |
+ bool m_haveClosure = true; |
+ base::Closure m_closure; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebClosure); |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // WebClosure_h |