Chromium Code Reviews| 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" | |
|
tkent
2015/07/16 08:17:50
should be "public/platform/WebCommon.h"
yhirano
2015/07/16 08:32:21
Done.
| |
| 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. | |
| 18 // WebPassOwnPtr<T> is destructible on chromium side only when it contains | |
| 19 // nullptr. | |
| 20 template <typename T> | |
| 21 class WebPassOwnPtr final { | |
| 22 public: | |
| 23 WebPassOwnPtr() : m_ptr(nullptr) {} | |
| 24 WebPassOwnPtr(decltype(nullptr)) : m_ptr(nullptr) {} | |
| 25 template <typename U> | |
| 26 WebPassOwnPtr(const WebPassOwnPtr<U>& o) | |
| 27 { | |
| 28 m_ptr = o.m_ptr; | |
| 29 o.m_ptr = nullptr; | |
| 30 } | |
| 31 ~WebPassOwnPtr() | |
| 32 { | |
| 33 #if INSIDE_BLINK | |
| 34 release(); | |
| 35 #endif | |
| 36 BLINK_ASSERT(!m_ptr); | |
| 37 } | |
| 38 WebPassOwnPtr& operator =(const WebPassOwnPtr&) = delete; | |
| 39 | |
| 40 #if INSIDE_BLINK | |
| 41 PassOwnPtr<T> release() | |
| 42 { | |
| 43 T* ptr = m_ptr; | |
| 44 m_ptr = nullptr; | |
| 45 return adoptPtr(ptr); | |
| 46 } | |
| 47 #endif // INSIDE_BLINK | |
| 48 | |
| 49 template <typename U> friend class WebPassOwnPtr; | |
| 50 template <typename U> friend WebPassOwnPtr<U> adoptWebPtr(U*); | |
| 51 | |
| 52 private: | |
| 53 explicit WebPassOwnPtr(T* ptr) : m_ptr(ptr) {} | |
| 54 | |
| 55 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.
| |
| 56 }; | |
| 57 | |
| 58 template <typename T> | |
| 59 WebPassOwnPtr<T> adoptWebPtr(T* p) { return WebPassOwnPtr<T>(p); } | |
| 60 | |
| 61 } // namespace blink | |
| 62 | |
| 63 #endif | |
| OLD | NEW |