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

Unified Diff: public/platform/WebPassOwnPtr.h

Issue 23455058: WIP: WebLayer::addAnimation should transfer the ownership of WebAnimation instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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 | « public/platform/WebLayer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: public/platform/WebPassOwnPtr.h
diff --git a/public/platform/WebPassOwnPtr.h b/public/platform/WebPassOwnPtr.h
new file mode 100644
index 0000000000000000000000000000000000000000..fecd6172e7d15c28ead8206b3eaa8b6b92e21255
--- /dev/null
+++ b/public/platform/WebPassOwnPtr.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPassOwnPtr_h
+#define WebPassOwnPtr_h
+
+#include "WebCommon.h"
+
+#if INSIDE_WEBKIT
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+using WTF::EnableIf;
+using WTF::IsPointerConvertible;
+#endif
+
+namespace WebKit {
+
+// It exists to help transfer the ownership of either OwnPtr or PassOwnPtr from Blink to Chromium.
+//
+// A typical usage is as follows:
+// in Blink side
+// OwnPtr<WebAnimation> animation;
+// WebLayer layer;
+// layer->addAnimation(animation);
+//
+// in Chromium side
+// bool WebAnimation::addAnimation(WebPassOwnPtr<WebAnimation> pop_animation) {
+// scoped_ptr<WebAnimation> animation(pop_animation.leakPtr());
+// ...
+// }
+template <typename T>
+class WebPassOwnPtr {
+public:
+ WebPassOwnPtr() : m_ptr(0) { }
+ ~WebPassOwnPtr() { delete m_ptr; }
jamesr 2013/09/24 17:52:10 you can't do this without ~T(), which will make it
dshwang 2013/09/24 18:23:22 Could you explain why it cannot work in detail or
+ WebPassOwnPtr(const WebPassOwnPtr& o) : m_ptr(o.leakPtr()) { }
+
+ T* leakPtr() const
+ {
+ T* ptr = m_ptr;
+ m_ptr = 0;
+ return ptr;
+ }
+ bool operator!() const { return !m_ptr; }
+
+#if INSIDE_WEBKIT
+ explicit WebPassOwnPtr(T* ptr)
+ : m_ptr(ptr)
+ {
+ COMPILE_ASSERT(sizeof(T) > 0, TypeMustBeComplete);
+ }
+
+ template<typename U> WebPassOwnPtr(const OwnPtr<U>&, EnsurePtrConvertibleArgDecl(U, T));
+ template<typename U> WebPassOwnPtr(const PassOwnPtr<U>&, EnsurePtrConvertibleArgDecl(U, T));
+
+ T* get() const { return m_ptr; }
+ T* operator->() const
+ {
+ WEBKIT_ASSERT(m_ptr);
+ return m_ptr;
+ }
+#endif // INSIDE_WEBKIT
+
+private:
+ WebPassOwnPtr& operator=(const WebPassOwnPtr&);
+
+ mutable T* m_ptr;
+};
+
+#if INSIDE_WEBKIT
+template<typename T> template<typename U> inline WebPassOwnPtr<T>::WebPassOwnPtr(const OwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T))
+ : m_ptr(o.leakPtr())
+{
+}
+
+template<typename T> template<typename U> inline WebPassOwnPtr<T>::WebPassOwnPtr(const PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T))
+ : m_ptr(o.leakPtr())
+{
+}
+#endif
+
+} // namespace WebKit
+
+#endif
« no previous file with comments | « public/platform/WebLayer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698