1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef WebPassOwnPtr_h
6 #define WebPassOwnPtr_h
8 #include "public/platform/WebCommon.h"
11 #include "wtf/PassOwnPtr.h"
16 // WebPassOwnPtr<T> is used to pass a T pointer with ownership from chromium
17 // side to blink side. T's definition must be shared among all users
18 // (especially between chromium and blink).
19 // TODO(yhirano): Migrate to scoped_ptr or std::unique_ptr once the repository
20 // merge is done or C++11 std library is allowed.
22 class WebPassOwnPtr final
{
24 WebPassOwnPtr() : m_ptr(nullptr) {}
25 WebPassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {}
26 // We need |const| to bind an rvalue. As a result, |m_ptr| needs to be
27 // mutable because we manipulate it.
29 WebPassOwnPtr(const WebPassOwnPtr
<U
>& o
)
34 WebPassOwnPtr(const WebPassOwnPtr
& o
)
43 WebPassOwnPtr
& operator =(const WebPassOwnPtr
&) = delete;
46 PassOwnPtr
<T
> release()
52 #endif // INSIDE_BLINK
54 template <typename U
> friend class WebPassOwnPtr
;
55 template <typename U
> friend WebPassOwnPtr
<U
> adoptWebPtr(U
*);
58 explicit WebPassOwnPtr(T
* ptr
) : m_ptr(ptr
) {}
60 // See the constructor comment to see why |mutable| is needed.
65 WebPassOwnPtr
<T
> adoptWebPtr(T
* p
) { return WebPassOwnPtr
<T
>(p
); }