Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Unified Diff: third_party/WebKit/public/platform/functional/WebFunction.h

Issue 1882503002: Remove setErrorMessageCallback from WebGraphicsContext3D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@errorcallback
Patch Set: weberrors: owned Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/public/platform/functional/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/public/platform/functional/WebFunction.h
diff --git a/third_party/WebKit/public/platform/functional/WebFunction.h b/third_party/WebKit/public/platform/functional/WebFunction.h
new file mode 100644
index 0000000000000000000000000000000000000000..7eb4a226fffed6aac24f50aa00465b3efaa43cdc
--- /dev/null
+++ b/third_party/WebKit/public/platform/functional/WebFunction.h
@@ -0,0 +1,101 @@
+// 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 WebFunction_h
+#define WebFunction_h
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/callback_helpers.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "public/platform/WebCommon.h"
+
+#include <memory>
+#include <utility>
+
+#if BLINK_IMPLEMENTATION
+#include "wtf/Functional.h"
+#else
+#include "base/logging.h"
+#endif
+
+namespace blink {
+
+template <typename...>
+class WebFunction;
+
+// Conversion from WTF closures to base closures to pass a callback out of
+// blink.
+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
+ WebFunction()
+ {
+ }
+
+ explicit WebFunction(PassOwnPtr<WTFFunction> c)
+ {
+ // Make the base::Callback own the WTF::Function, allowing it to call the
+ // WTF::Function more than once but destroy it when the base::Callback is
+ // destroyed.
+ m_callback = base::Bind(&RunWTFFunction<R, Args...>, base::Owned(c.leakPtr()));
+ }
+#endif
+
+ 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_callback = std::move(other.m_callback);
+ return *this;
+ }
+
+#if !BLINK_IMPLEMENTATION
+ // TODO(danakj): This could be rvalue-ref-qualified.
+ 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_callback);
+ }
+#endif
+
+private:
+#if BLINK_IMPLEMENTATION
+ template <typename RunR, typename... RunArgs>
+ static RunR RunWTFFunction(WTFFunction* c, RunArgs... args)
+ {
+ return (*c)(std::forward<RunArgs>(args)...);
+ }
+#endif
+
+#if DCHECK_IS_ON()
+ bool m_haveClosure = true;
+#endif
+ base::Callback<R(Args...)> m_callback;
+
+ DISALLOW_COPY_AND_ASSIGN(WebFunction);
+};
+
+using WebClosure = WebFunction<void()>;
+
+} // namespace blink
+
+#endif // WebClosure_h
« no previous file with comments | « third_party/WebKit/public/platform/functional/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698