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 15 matching lines...) Expand all Loading... |
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 "base/logging.h" |
33 #include <cstddef> | 33 #include <cstddef> |
34 | 34 |
35 #if INSIDE_BLINK | 35 #if INSIDE_BLINK |
36 #include "wtf/PtrUtil.h" | 36 #include "wtf/PassOwnPtr.h" |
37 #include <memory> | |
38 #endif | 37 #endif |
39 | 38 |
40 namespace blink { | 39 namespace blink { |
41 | 40 |
42 // 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 |
43 // to help simplify the implementation of WebKit interfaces that merely | 42 // to help simplify the implementation of WebKit interfaces that merely |
44 // 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 |
45 // wraps a naked pointer rather than a reference counted. | 44 // wraps a naked pointer rather than a reference counted. |
46 // 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 |
47 // the WebCore pointer. | 46 // the WebCore pointer. |
48 template <typename T> | 47 template <typename T> |
49 class WebPrivateOwnPtr : public WebNonCopyable { | 48 class WebPrivateOwnPtr : public WebNonCopyable { |
50 public: | 49 public: |
51 WebPrivateOwnPtr() : m_ptr(nullptr) {} | 50 WebPrivateOwnPtr() : m_ptr(nullptr) {} |
52 WebPrivateOwnPtr(std::nullptr_t) : m_ptr(nullptr) {} | 51 WebPrivateOwnPtr(std::nullptr_t) : m_ptr(nullptr) {} |
53 ~WebPrivateOwnPtr() { DCHECK(!m_ptr); } | 52 ~WebPrivateOwnPtr() { DCHECK(!m_ptr); } |
54 | 53 |
55 explicit WebPrivateOwnPtr(T* ptr) | 54 explicit WebPrivateOwnPtr(T* ptr) |
56 : m_ptr(ptr) | 55 : m_ptr(ptr) |
57 { | 56 { |
58 } | 57 } |
59 | 58 |
60 T* get() const { return m_ptr; } | 59 T* get() const { return m_ptr; } |
61 | 60 |
62 #if INSIDE_BLINK | 61 #if INSIDE_BLINK |
63 template <typename U> | 62 template <typename U> |
64 WebPrivateOwnPtr(std::unique_ptr<U>, EnsurePtrConvertibleArgDecl(U, T)); | 63 WebPrivateOwnPtr(PassOwnPtr<U>, EnsurePtrConvertibleArgDecl(U, T)); |
65 | 64 |
66 void reset(T* ptr) | 65 void reset(T* ptr) |
67 { | 66 { |
68 delete m_ptr; | 67 delete m_ptr; |
69 m_ptr = ptr; | 68 m_ptr = ptr; |
70 } | 69 } |
71 | 70 |
72 void reset(std::unique_ptr<T> o) | 71 void reset(PassOwnPtr<T> o) |
73 { | 72 { |
74 reset(o.release()); | 73 reset(o.leakPtr()); |
75 } | 74 } |
76 | 75 |
77 std::unique_ptr<T> release() | 76 PassOwnPtr<T> release() |
78 { | 77 { |
79 T* ptr = m_ptr; | 78 T* ptr = m_ptr; |
80 m_ptr = nullptr; | 79 m_ptr = nullptr; |
81 return wrapUnique(ptr); | 80 return adoptPtr(ptr); |
82 } | 81 } |
83 | 82 |
84 T& operator*() const | 83 T& operator*() const |
85 { | 84 { |
86 DCHECK(m_ptr); | 85 DCHECK(m_ptr); |
87 return *m_ptr; | 86 return *m_ptr; |
88 } | 87 } |
89 | 88 |
90 T* operator->() const | 89 T* operator->() const |
91 { | 90 { |
92 DCHECK(m_ptr); | 91 DCHECK(m_ptr); |
93 return m_ptr; | 92 return m_ptr; |
94 } | 93 } |
95 #endif // INSIDE_BLINK | 94 #endif // INSIDE_BLINK |
96 | 95 |
97 private: | 96 private: |
98 T* m_ptr; | 97 T* m_ptr; |
99 }; | 98 }; |
100 | 99 |
101 #if INSIDE_BLINK | 100 #if INSIDE_BLINK |
102 template <typename T> | 101 template <typename T> |
103 template <typename U> | 102 template <typename U> |
104 inline WebPrivateOwnPtr<T>::WebPrivateOwnPtr(std::unique_ptr<U> o, EnsurePtrConv
ertibleArgDefn(U, T)) | 103 inline WebPrivateOwnPtr<T>::WebPrivateOwnPtr(PassOwnPtr<U> o, EnsurePtrConvertib
leArgDefn(U, T)) |
105 : m_ptr(o.release()) | 104 : m_ptr(o.leakPtr()) |
106 { | 105 { |
107 static_assert(!std::is_array<T>::value, "Pointers to array must never be con
verted"); | 106 static_assert(!std::is_array<T>::value, "Pointers to array must never be con
verted"); |
108 } | 107 } |
109 #endif | 108 #endif |
110 | 109 |
111 } // namespace blink | 110 } // namespace blink |
112 | 111 |
113 #endif | 112 #endif |
OLD | NEW |