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..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 |