Chromium Code Reviews| Index: public/platform/WebPassOwnPtr.h |
| diff --git a/public/platform/WebPassOwnPtr.h b/public/platform/WebPassOwnPtr.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8f7f90a57174b081f9dc016be04855ba27f289d6 |
| --- /dev/null |
| +++ b/public/platform/WebPassOwnPtr.h |
| @@ -0,0 +1,55 @@ |
| +// 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" |
| + |
| +#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. |
|
kinuko
2015/07/16 06:49:35
Add a comment to note that the ownership must be t
yhirano
2015/07/16 07:27:02
I think implicit release is useful inside blink. W
|
| +template <typename T> |
| +class WebPassOwnPtr { |
| +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() { 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; |
| +}; |
| + |
| +template <typename T> |
| +WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); } |
| + |
| +} // namespace blink |
| + |
| +#endif |