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

Unified Diff: third_party/WebKit/public/platform/callback/WebClosure.h

Issue 1830033003: Make lost context callback a base::Closure thru the WGC3DProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lostcontext-webclosure: 80 Created 4 years, 9 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
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

Powered by Google App Engine
This is Rietveld 408576698