| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 template <typename T> | 137 template <typename T> |
| 138 struct WebPrivatePtrPersistentStorageType<T, WebPrivatePtrDestructionCrossThread
, WebPrivatePtrStrength::Weak> { | 138 struct WebPrivatePtrPersistentStorageType<T, WebPrivatePtrDestructionCrossThread
, WebPrivatePtrStrength::Weak> { |
| 139 public: | 139 public: |
| 140 using Type = CrossThreadWeakPersistent<T>; | 140 using Type = CrossThreadWeakPersistent<T>; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 template<typename T, WebPrivatePtrDestruction crossThreadDestruction, WebPrivate
PtrStrength strongOrWeak> | 143 template<typename T, WebPrivatePtrDestruction crossThreadDestruction, WebPrivate
PtrStrength strongOrWeak> |
| 144 class PtrStorageImpl<T, crossThreadDestruction, strongOrWeak, GarbageCollectedLi
fetime> { | 144 class PtrStorageImpl<T, crossThreadDestruction, strongOrWeak, GarbageCollectedLi
fetime> { |
| 145 public: | 145 public: |
| 146 void assign(const RawPtr<T>& val) | 146 void assign(T* val) |
| 147 { | 147 { |
| 148 if (!val) { | 148 if (!val) { |
| 149 release(); | 149 release(); |
| 150 return; | 150 return; |
| 151 } | 151 } |
| 152 | 152 |
| 153 if (!m_handle) | 153 if (!m_handle) |
| 154 m_handle = new (typename WebPrivatePtrPersistentStorageType<T, cross
ThreadDestruction, strongOrWeak>::Type)(); | 154 m_handle = new (typename WebPrivatePtrPersistentStorageType<T, cross
ThreadDestruction, strongOrWeak>::Type)(); |
| 155 | 155 |
| 156 (*m_handle) = val; | 156 (*m_handle) = val; |
| 157 } | 157 } |
| 158 | 158 |
| 159 void assign(T* ptr) { assign(RawPtr<T>(ptr)); } | 159 template<typename U> void assign(U* val) { assign(static_cast<T*>(val)); } |
| 160 template<typename U> void assign(const RawPtr<U>& val) { assign(RawPtr<T>(va
l)); } | |
| 161 | 160 |
| 162 void assign(const PtrStorageImpl& other) { assign(other.get()); } | 161 void assign(const PtrStorageImpl& other) { assign(other.get()); } |
| 163 | 162 |
| 164 T* get() const { return m_handle ? m_handle->get() : 0; } | 163 T* get() const { return m_handle ? m_handle->get() : 0; } |
| 165 | 164 |
| 166 void release() | 165 void release() |
| 167 { | 166 { |
| 168 delete m_handle; | 167 delete m_handle; |
| 169 m_handle = 0; | 168 m_handle = 0; |
| 170 } | 169 } |
| 171 | 170 |
| 172 private: | 171 private: |
| 173 typename WebPrivatePtrPersistentStorageType<T, crossThreadDestruction, stron
gOrWeak>::Type* m_handle; | 172 typename WebPrivatePtrPersistentStorageType<T, crossThreadDestruction, stron
gOrWeak>::Type* m_handle; |
| 174 }; | 173 }; |
| 175 | 174 |
| 176 template<typename T, WebPrivatePtrDestruction crossThreadDestruction, WebPrivate
PtrStrength strongOrWeak> | 175 template<typename T, WebPrivatePtrDestruction crossThreadDestruction, WebPrivate
PtrStrength strongOrWeak> |
| 177 class PtrStorageImpl<T, crossThreadDestruction, strongOrWeak, RefCountedGarbageC
ollectedLifetime> : public PtrStorageImpl<T, crossThreadDestruction, strongOrWea
k, GarbageCollectedLifetime> { | 176 class PtrStorageImpl<T, crossThreadDestruction, strongOrWeak, RefCountedGarbageC
ollectedLifetime> : public PtrStorageImpl<T, crossThreadDestruction, strongOrWea
k, GarbageCollectedLifetime> { |
| 178 public: | 177 public: |
| 179 void assign(const RawPtr<T>& val) { PtrStorageImpl<T, crossThreadDestruction
, strongOrWeak, GarbageCollectedLifetime>::assign(val.get()); } | 178 void assign(T* val) { PtrStorageImpl<T, crossThreadDestruction, strongOrWeak
, GarbageCollectedLifetime>::assign(val); } |
| 180 | 179 |
| 181 void assign(const PtrStorageImpl& other) { PtrStorageImpl<T, crossThreadDest
ruction, strongOrWeak, GarbageCollectedLifetime>::assign(other.get()); } | 180 void assign(const PtrStorageImpl& other) { PtrStorageImpl<T, crossThreadDest
ruction, strongOrWeak, GarbageCollectedLifetime>::assign(other.get()); } |
| 182 }; | 181 }; |
| 183 | 182 |
| 184 template<typename T, WebPrivatePtrDestruction crossThreadDestruction, WebPrivate
PtrStrength strongOrWeak> | 183 template<typename T, WebPrivatePtrDestruction crossThreadDestruction, WebPrivate
PtrStrength strongOrWeak> |
| 185 class PtrStorage : public PtrStorageImpl<T, crossThreadDestruction, strongOrWeak
, LifetimeOf<T>::value> { | 184 class PtrStorage : public PtrStorageImpl<T, crossThreadDestruction, strongOrWeak
, LifetimeOf<T>::value> { |
| 186 public: | 185 public: |
| 187 static PtrStorage& fromSlot(void** slot) | 186 static PtrStorage& fromSlot(void** slot) |
| 188 { | 187 { |
| 189 static_assert(sizeof(PtrStorage) == sizeof(void*), "PtrStorage must be t
he size of a pointer"); | 188 static_assert(sizeof(PtrStorage) == sizeof(void*), "PtrStorage must be t
he size of a pointer"); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // Disable the copy constructor; classes that contain a WebPrivatePtr | 307 // Disable the copy constructor; classes that contain a WebPrivatePtr |
| 309 // should implement their copy constructor using assign(). | 308 // should implement their copy constructor using assign(). |
| 310 WebPrivatePtr(const WebPrivatePtr&); | 309 WebPrivatePtr(const WebPrivatePtr&); |
| 311 | 310 |
| 312 void* m_storage; | 311 void* m_storage; |
| 313 }; | 312 }; |
| 314 | 313 |
| 315 } // namespace blink | 314 } // namespace blink |
| 316 | 315 |
| 317 #endif // WebPrivatePtr_h | 316 #endif // WebPrivatePtr_h |
| OLD | NEW |