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

Unified Diff: public/platform/WebPassOwnPtr.h

Issue 1232033004: Introduce WebPassOwnPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 5 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 | « no previous file | 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..fcb2d1ca091ff7d46c6b7a028a42cecc52da2a58
--- /dev/null
+++ b/public/platform/WebPassOwnPtr.h
@@ -0,0 +1,63 @@
+// Copyright 2015 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 WebPassOwnPtr_h
+#define WebPassOwnPtr_h
+
+#include "WebCommon.h"
tkent 2015/07/16 08:17:50 should be "public/platform/WebCommon.h"
yhirano 2015/07/16 08:32:21 Done.
+
+#if INSIDE_BLINK
+#include "wtf/PassOwnPtr.h"
+#endif
+
+namespace blink {
+
+// WebPassOwnPtr<T> is used to pass a T pointer with ownership from chromium
+// side to blink side.
+// WebPassOwnPtr<T> is destructible on chromium side only when it contains
+// nullptr.
+template <typename T>
+class WebPassOwnPtr final {
+public:
+ WebPassOwnPtr() : m_ptr(nullptr) {}
+ WebPassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {}
+ template <typename U>
+ WebPassOwnPtr(const WebPassOwnPtr<U>& o)
+ {
+ m_ptr = o.m_ptr;
+ o.m_ptr = nullptr;
+ }
+ ~WebPassOwnPtr()
+ {
+#if INSIDE_BLINK
+ release();
+#endif
+ BLINK_ASSERT(!m_ptr);
+ }
+ WebPassOwnPtr& operator =(const WebPassOwnPtr&) = delete;
+
+#if INSIDE_BLINK
+ PassOwnPtr<T> release()
+ {
+ T* ptr = m_ptr;
+ m_ptr = nullptr;
+ return adoptPtr(ptr);
+ }
+#endif // INSIDE_BLINK
+
+ template <typename U> friend class WebPassOwnPtr;
+ template <typename U> friend WebPassOwnPtr<U> adoptWebPtr(U*);
+
+private:
+ explicit WebPassOwnPtr(T* ptr) : m_ptr(ptr) {}
+
+ mutable T* m_ptr;
tkent 2015/07/16 08:17:50 Please add a comment about the reason of mutable.
yhirano 2015/07/16 08:32:21 Done.
+};
+
+template <typename T>
+WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); }
+
+} // namespace blink
+
+#endif
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698