| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WebPrivatePtr_h | 31 #ifndef WebPrivatePtr_h |
| 32 #define WebPrivatePtr_h | 32 #define WebPrivatePtr_h |
| 33 | 33 |
| 34 #include "WebCommon.h" | 34 #include "WebCommon.h" |
| 35 | 35 |
| 36 #if INSIDE_BLINK | 36 #if INSIDE_BLINK |
| 37 | |
| 38 namespace blink { template<typename T> class TreeShared; } | |
| 39 | |
| 40 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
| 41 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
| 42 #include "wtf/TypeTraits.h" | 39 #include "wtf/TypeTraits.h" |
| 43 #endif | 40 #endif |
| 44 | 41 |
| 45 namespace blink { | 42 namespace blink { |
| 46 | 43 |
| 47 #if INSIDE_BLINK | 44 #if INSIDE_BLINK |
| 48 enum LifetimeManagementType { | 45 enum LifetimeManagementType { |
| 49 RefCountedLifetime, | 46 RefCountedLifetime, |
| 50 GarbageCollectedLifetime, | 47 GarbageCollectedLifetime, |
| 51 RefCountedGarbageCollectedLifetime | 48 RefCountedGarbageCollectedLifetime |
| 52 }; | 49 }; |
| 53 | 50 |
| 54 template<typename T> | 51 template<typename T> |
| 55 class LifetimeOf { | 52 class LifetimeOf { |
| 56 static const bool isGarbageCollected = WTF::IsSubclassOfTemplate<T, blink::G
arbageCollected>::value; | 53 static const bool isGarbageCollected = WTF::IsSubclassOfTemplate<T, GarbageC
ollected>::value; |
| 57 static const bool isRefCountedGarbageCollected = WTF::IsSubclassOfTemplate<T
, blink::RefCountedGarbageCollected>::value; | 54 static const bool isRefCountedGarbageCollected = WTF::IsSubclassOfTemplate<T
, RefCountedGarbageCollected>::value; |
| 58 public: | 55 public: |
| 59 static const LifetimeManagementType value = | 56 static const LifetimeManagementType value = |
| 60 !isGarbageCollected ? RefCountedLifetime : | 57 !isGarbageCollected ? RefCountedLifetime : |
| 61 isRefCountedGarbageCollected ? RefCountedGarbageCollectedLifetime : Garb
ageCollectedLifetime; | 58 isRefCountedGarbageCollected ? RefCountedGarbageCollectedLifetime : Garb
ageCollectedLifetime; |
| 62 }; | 59 }; |
| 63 | 60 |
| 64 template<typename T, LifetimeManagementType lifetime> | 61 template<typename T, LifetimeManagementType lifetime> |
| 65 class PtrStorageImpl; | 62 class PtrStorageImpl; |
| 66 | 63 |
| 67 template<typename T> | 64 template<typename T> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 class PtrStorageImpl<T, GarbageCollectedLifetime> { | 96 class PtrStorageImpl<T, GarbageCollectedLifetime> { |
| 100 public: | 97 public: |
| 101 void assign(const RawPtr<T>& val) | 98 void assign(const RawPtr<T>& val) |
| 102 { | 99 { |
| 103 if (!val) { | 100 if (!val) { |
| 104 release(); | 101 release(); |
| 105 return; | 102 return; |
| 106 } | 103 } |
| 107 | 104 |
| 108 if (!m_handle) | 105 if (!m_handle) |
| 109 m_handle = new blink::Persistent<T>(); | 106 m_handle = new Persistent<T>(); |
| 110 | 107 |
| 111 (*m_handle) = val; | 108 (*m_handle) = val; |
| 112 } | 109 } |
| 113 | 110 |
| 114 void assign(T* ptr) { assign(RawPtr<T>(ptr)); } | 111 void assign(T* ptr) { assign(RawPtr<T>(ptr)); } |
| 115 template<typename U> void assign(const RawPtr<U>& val) { assign(RawPtr<T>(va
l)); } | 112 template<typename U> void assign(const RawPtr<U>& val) { assign(RawPtr<T>(va
l)); } |
| 116 | 113 |
| 117 void assign(const PtrStorageImpl& other) { assign(other.get()); } | 114 void assign(const PtrStorageImpl& other) { assign(other.get()); } |
| 118 | 115 |
| 119 T* get() const { return m_handle ? m_handle->get() : 0; } | 116 T* get() const { return m_handle ? m_handle->get() : 0; } |
| 120 | 117 |
| 121 void release() | 118 void release() |
| 122 { | 119 { |
| 123 delete m_handle; | 120 delete m_handle; |
| 124 m_handle = 0; | 121 m_handle = 0; |
| 125 } | 122 } |
| 126 | 123 |
| 127 private: | 124 private: |
| 128 blink::Persistent<T>* m_handle; | 125 Persistent<T>* m_handle; |
| 129 }; | 126 }; |
| 130 | 127 |
| 131 template<typename T> | 128 template<typename T> |
| 132 class PtrStorageImpl<T, RefCountedGarbageCollectedLifetime> : public PtrStorageI
mpl<T, GarbageCollectedLifetime> { | 129 class PtrStorageImpl<T, RefCountedGarbageCollectedLifetime> : public PtrStorageI
mpl<T, GarbageCollectedLifetime> { |
| 133 public: | 130 public: |
| 134 void assign(const PassRefPtrWillBeRawPtr<T>& val) { PtrStorageImpl<T, Garbag
eCollectedLifetime>::assign(val.get()); } | 131 void assign(const PassRefPtrWillBeRawPtr<T>& val) { PtrStorageImpl<T, Garbag
eCollectedLifetime>::assign(val.get()); } |
| 135 | 132 |
| 136 void assign(const PtrStorageImpl& other) { PtrStorageImpl<T, GarbageCollecte
dLifetime>::assign(other.get()); } | 133 void assign(const PtrStorageImpl& other) { PtrStorageImpl<T, GarbageCollecte
dLifetime>::assign(other.get()); } |
| 137 }; | 134 }; |
| 138 | 135 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // } | 174 // } |
| 178 // BLINK_EXPORT void assign(const WebFoo&); // Implemented in the body. | 175 // BLINK_EXPORT void assign(const WebFoo&); // Implemented in the body. |
| 179 // | 176 // |
| 180 // // Methods that are exposed to Chromium and which are specific to | 177 // // Methods that are exposed to Chromium and which are specific to |
| 181 // // WebFoo go here. | 178 // // WebFoo go here. |
| 182 // BLINK_EXPORT doWebFooThing(); | 179 // BLINK_EXPORT doWebFooThing(); |
| 183 // | 180 // |
| 184 // // Methods that are used only by other Blink classes should only be | 181 // // Methods that are used only by other Blink classes should only be |
| 185 // // declared when INSIDE_BLINK is set. | 182 // // declared when INSIDE_BLINK is set. |
| 186 // #if INSIDE_BLINK | 183 // #if INSIDE_BLINK |
| 187 // WebFoo(const WTF::PassRefPtr<blink::Foo>&); | 184 // WebFoo(const WTF::PassRefPtr<Foo>&); |
| 188 // #endif | 185 // #endif |
| 189 // | 186 // |
| 190 // private: | 187 // private: |
| 191 // WebPrivatePtr<blink::Foo> m_private; | 188 // WebPrivatePtr<Foo> m_private; |
| 192 // }; | 189 // }; |
| 193 // | 190 // |
| 194 // // WebFoo.cpp | 191 // // WebFoo.cpp |
| 195 // WebFoo::~WebFoo() { m_private.reset(); } | 192 // WebFoo::~WebFoo() { m_private.reset(); } |
| 196 // void WebFoo::assign(const WebFoo& other) { ... } | 193 // void WebFoo::assign(const WebFoo& other) { ... } |
| 197 // | 194 // |
| 198 template <typename T> | 195 template <typename T> |
| 199 class WebPrivatePtr { | 196 class WebPrivatePtr { |
| 200 public: | 197 public: |
| 201 WebPrivatePtr() : m_storage(0) { } | 198 WebPrivatePtr() : m_storage(0) { } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 // Disable the copy constructor; classes that contain a WebPrivatePtr | 261 // Disable the copy constructor; classes that contain a WebPrivatePtr |
| 265 // should implement their copy constructor using assign(). | 262 // should implement their copy constructor using assign(). |
| 266 WebPrivatePtr(const WebPrivatePtr<T>&); | 263 WebPrivatePtr(const WebPrivatePtr<T>&); |
| 267 | 264 |
| 268 void* m_storage; | 265 void* m_storage; |
| 269 }; | 266 }; |
| 270 | 267 |
| 271 } // namespace blink | 268 } // namespace blink |
| 272 | 269 |
| 273 #endif | 270 #endif |
| OLD | NEW |