| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef WebPrivateOwnPtr_h | 27 #ifndef WebPrivateOwnPtr_h |
| 28 #define WebPrivateOwnPtr_h | 28 #define WebPrivateOwnPtr_h |
| 29 | 29 |
| 30 #include "WebCommon.h" | 30 #include "WebCommon.h" |
| 31 #include "WebNonCopyable.h" | 31 #include "WebNonCopyable.h" |
| 32 #include "base/logging.h" |
| 32 #include <cstddef> | 33 #include <cstddef> |
| 33 | 34 |
| 34 #if INSIDE_BLINK | 35 #if INSIDE_BLINK |
| 35 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 // This class is an implementation detail of the WebKit API. It exists | 41 // This class is an implementation detail of the WebKit API. It exists |
| 41 // to help simplify the implementation of WebKit interfaces that merely | 42 // to help simplify the implementation of WebKit interfaces that merely |
| 42 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it | 43 // wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it |
| 43 // wraps a naked pointer rather than a reference counted. | 44 // wraps a naked pointer rather than a reference counted. |
| 44 // Note: you must call reset(0) on the implementation side in order to delete | 45 // Note: you must call reset(0) on the implementation side in order to delete |
| 45 // the WebCore pointer. | 46 // the WebCore pointer. |
| 46 template <typename T> | 47 template <typename T> |
| 47 class WebPrivateOwnPtr : public WebNonCopyable { | 48 class WebPrivateOwnPtr : public WebNonCopyable { |
| 48 public: | 49 public: |
| 49 WebPrivateOwnPtr() : m_ptr(nullptr) {} | 50 WebPrivateOwnPtr() : m_ptr(nullptr) {} |
| 50 WebPrivateOwnPtr(std::nullptr_t) : m_ptr(nullptr) {} | 51 WebPrivateOwnPtr(std::nullptr_t) : m_ptr(nullptr) {} |
| 51 ~WebPrivateOwnPtr() { BLINK_ASSERT(!m_ptr); } | 52 ~WebPrivateOwnPtr() { DCHECK(!m_ptr); } |
| 52 | 53 |
| 53 explicit WebPrivateOwnPtr(T* ptr) | 54 explicit WebPrivateOwnPtr(T* ptr) |
| 54 : m_ptr(ptr) | 55 : m_ptr(ptr) |
| 55 { | 56 { |
| 56 } | 57 } |
| 57 | 58 |
| 58 T* get() const { return m_ptr; } | 59 T* get() const { return m_ptr; } |
| 59 | 60 |
| 60 #if INSIDE_BLINK | 61 #if INSIDE_BLINK |
| 61 template<typename U> WebPrivateOwnPtr(const PassOwnPtr<U>&, EnsurePtrConvert
ibleArgDecl(U, T)); | 62 template<typename U> WebPrivateOwnPtr(const PassOwnPtr<U>&, EnsurePtrConvert
ibleArgDecl(U, T)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 73 | 74 |
| 74 PassOwnPtr<T> release() | 75 PassOwnPtr<T> release() |
| 75 { | 76 { |
| 76 T* ptr = m_ptr; | 77 T* ptr = m_ptr; |
| 77 m_ptr = nullptr; | 78 m_ptr = nullptr; |
| 78 return adoptPtr(ptr); | 79 return adoptPtr(ptr); |
| 79 } | 80 } |
| 80 | 81 |
| 81 T& operator*() const | 82 T& operator*() const |
| 82 { | 83 { |
| 83 BLINK_ASSERT(m_ptr); | 84 DCHECK(m_ptr); |
| 84 return *m_ptr; | 85 return *m_ptr; |
| 85 } | 86 } |
| 86 | 87 |
| 87 T* operator->() const | 88 T* operator->() const |
| 88 { | 89 { |
| 89 BLINK_ASSERT(m_ptr); | 90 DCHECK(m_ptr); |
| 90 return m_ptr; | 91 return m_ptr; |
| 91 } | 92 } |
| 92 #endif // INSIDE_BLINK | 93 #endif // INSIDE_BLINK |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 T* m_ptr; | 96 T* m_ptr; |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 #if INSIDE_BLINK | 99 #if INSIDE_BLINK |
| 99 template<typename T> template<typename U> inline WebPrivateOwnPtr<T>::WebPrivate
OwnPtr(const PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) | 100 template<typename T> template<typename U> inline WebPrivateOwnPtr<T>::WebPrivate
OwnPtr(const PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) |
| 100 : m_ptr(o.leakPtr()) | 101 : m_ptr(o.leakPtr()) |
| 101 { | 102 { |
| 102 static_assert(!std::is_array<T>::value, "Pointers to array must never be con
verted"); | 103 static_assert(!std::is_array<T>::value, "Pointers to array must never be con
verted"); |
| 103 } | 104 } |
| 104 #endif | 105 #endif |
| 105 | 106 |
| 106 } // namespace blink | 107 } // namespace blink |
| 107 | 108 |
| 108 #endif | 109 #endif |
| OLD | NEW |