| Index: public/platform/WebPassOwnPtr.h
|
| diff --git a/public/platform/WebPassOwnPtr.h b/public/platform/WebPassOwnPtr.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3a4b315b3cd295594181879a42d786a75d7c74ee
|
| --- /dev/null
|
| +++ b/public/platform/WebPassOwnPtr.h
|
| @@ -0,0 +1,68 @@
|
| +// 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 "public/platform/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.
|
| +// WebPassOwnPtr<T> is destructible on chromium side only when it contains
|
| +// nullptr.
|
| +// TODO(yhirano): Migrate to scoped_ptr or std::unique_ptr once the repository
|
| +// merge is done or C++11 std library is allowed.
|
| +template <typename T>
|
| +class WebPassOwnPtr final {
|
| +public:
|
| + WebPassOwnPtr() : m_ptr(nullptr) {}
|
| + WebPassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {}
|
| + // We need |const| to bind an rvalue. As a result, |m_ptr| needs to be
|
| + // mutable because we manipulate it.
|
| + 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) {}
|
| +
|
| + // See the constructor comment to see why |mutable| is needed.
|
| + mutable T* m_ptr;
|
| +};
|
| +
|
| +template <typename T>
|
| +WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); }
|
| +
|
| +} // namespace blink
|
| +
|
| +#endif
|
|
|