Chromium Code Reviews| Index: Source/wtf/ArrayBufferContents.h |
| diff --git a/Source/wtf/ArrayBufferContents.h b/Source/wtf/ArrayBufferContents.h |
| index 4bd137f02ce984f0fe9c70f30e1564b269498f7a..727993c16c211e13c089477fe5ab63c6605b648f 100644 |
| --- a/Source/wtf/ArrayBufferContents.h |
| +++ b/Source/wtf/ArrayBufferContents.h |
| @@ -29,6 +29,8 @@ |
| #include "wtf/ArrayBufferDeallocationObserver.h" |
| #include "wtf/Noncopyable.h" |
| +#include "wtf/RefPtr.h" |
| +#include "wtf/ThreadSafeRefCounted.h" |
| #include "wtf/WTFExport.h" |
| namespace WTF { |
| @@ -42,33 +44,36 @@ public: |
| }; |
| ArrayBufferContents(); |
| - ArrayBufferContents(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy); |
| + ArrayBufferContents(unsigned numElements, unsigned elementByteSize, bool isShared, ArrayBufferContents::InitializationPolicy); |
|
Yuki
2015/06/09 06:18:08
Our policy (style guide) prefers enum value to boo
binji
2015/06/10 06:04:39
Done.
|
| // Use with care. data must be allocated with allocateMemory. |
| // ArrayBufferContents will take ownership of the data and free it (using freeMemory) |
| // upon destruction. |
| // This constructor will not call observer->StartObserving(), so it is a responsibility |
| // of the caller to make sure JS knows about external memory. |
| - ArrayBufferContents(void* data, unsigned sizeInBytes, ArrayBufferDeallocationObserver*); |
| + ArrayBufferContents(void* data, unsigned sizeInBytes, bool isShared, ArrayBufferDeallocationObserver*); |
| ~ArrayBufferContents(); |
| void clear(); |
| - void* data() const { return m_data; } |
| - unsigned sizeInBytes() const { return m_sizeInBytes; } |
| + void* data() const { return m_holder ? m_holder->m_data : nullptr; } |
| + unsigned sizeInBytes() const { return m_holder ? m_holder->m_sizeInBytes : 0; } |
| + bool isShared() const { return m_holder ? m_holder->m_isShared : false; } |
| void setDeallocationObserver(ArrayBufferDeallocationObserver& observer) |
| { |
| - if (!m_deallocationObserver) { |
| - m_deallocationObserver = &observer; |
| - m_deallocationObserver->blinkAllocatedMemory(m_sizeInBytes); |
| + ASSERT(m_holder); |
| + if (!m_holder->m_deallocationObserver) { |
| + m_holder->m_deallocationObserver = &observer; |
| + m_holder->m_deallocationObserver->blinkAllocatedMemory(m_holder->m_sizeInBytes); |
| } |
| } |
| void setDeallocationObserverWithoutAllocationNotification(ArrayBufferDeallocationObserver& observer) |
| { |
| - if (!m_deallocationObserver) { |
| - m_deallocationObserver = &observer; |
| + ASSERT(m_holder); |
| + if (!m_holder->m_deallocationObserver) { |
| + m_holder->m_deallocationObserver = &observer; |
| } |
| } |
| @@ -79,9 +84,22 @@ public: |
| static void freeMemory(void*, size_t); |
| private: |
| - void* m_data; |
| - unsigned m_sizeInBytes; |
| - ArrayBufferDeallocationObserver* m_deallocationObserver; |
| + class DataHolder : public ThreadSafeRefCounted<DataHolder> { |
| + WTF_MAKE_NONCOPYABLE(DataHolder); |
| + public: |
| + DataHolder(); |
| + ~DataHolder(); |
| + |
| + void adopt(void* data, unsigned sizeInBytes, bool shared, ArrayBufferDeallocationObserver*); |
| + void copyToWithoutBuffer(DataHolder& other); |
| + |
| + void* m_data; |
|
Yuki
2015/06/09 06:18:08
Maybe you think it's overkilling, but I'd recommen
binji
2015/06/10 06:04:39
Done.
|
| + unsigned m_sizeInBytes; |
| + bool m_isShared; |
| + ArrayBufferDeallocationObserver* m_deallocationObserver; |
| + }; |
| + |
| + RefPtr<DataHolder> m_holder; |
| }; |
| } // namespace WTF |