OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef WebPassOwnPtr_h | |
6 #define WebPassOwnPtr_h | |
7 | |
8 #include "WebCommon.h" | |
9 | |
10 #if INSIDE_BLINK | |
11 #include "wtf/PassOwnPtr.h" | |
12 #endif | |
13 | |
14 namespace blink { | |
15 | |
16 // WebPassOwnPtr<T> is used to pass a T pointer with ownership from chromium | |
17 // 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
| |
18 template <typename T> | |
19 class WebPassOwnPtr { | |
20 public: | |
21 WebPassOwnPtr() : m_ptr(nullptr) {} | |
22 WebPassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {} | |
23 template <typename U> | |
24 WebPassOwnPtr(const WebPassOwnPtr<U>& o) | |
25 { | |
26 m_ptr = o.m_ptr; | |
27 o.m_ptr = nullptr; | |
28 } | |
29 ~WebPassOwnPtr() { BLINK_ASSERT(!m_ptr); } | |
30 WebPassOwnPtr& operator =(const WebPassOwnPtr&) = delete; | |
31 | |
32 #if INSIDE_BLINK | |
33 PassOwnPtr<T> release() | |
34 { | |
35 T* ptr = m_ptr; | |
36 m_ptr = nullptr; | |
37 return adoptPtr(ptr); | |
38 } | |
39 #endif // INSIDE_BLINK | |
40 | |
41 template <typename U> friend class WebPassOwnPtr; | |
42 template <typename U> friend WebPassOwnPtr<U> adoptWebPtr(U*); | |
43 | |
44 private: | |
45 explicit WebPassOwnPtr(T* ptr) : m_ptr(ptr) {} | |
46 | |
47 mutable T* m_ptr; | |
48 }; | |
49 | |
50 template <typename T> | |
51 WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); } | |
52 | |
53 } // namespace blink | |
54 | |
55 #endif | |
OLD | NEW |