Chromium Code Reviews| 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..b85a23efa8dccb53f415510270d1f78d904ebce0 |
| --- /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) |
| + { |
| + m_closure = base::Bind(&RunAndDelete, 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; |
|
esprehn
2016/03/25 01:05:06
ditto, guard the m_haveClosure code with debug ifd
danakj
2016/03/25 01:41:53
Done.
|
| + 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: |
| +#if BLINK_IMPLEMENTATION |
| + static void RunAndDelete(scoped_ptr<SameThreadClosure> c) { (*c)(); } |
| +#endif |
| + |
| + bool m_haveClosure = true; |
|
esprehn
2016/03/25 01:05:05
ifdef this to debug only, the boolean is only used
danakj
2016/03/25 01:41:53
Done, to DCHECK_IS_ON().
|
| + base::Closure m_closure; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebClosure); |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // WebClosure_h |