Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
| diff --git a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
| index 2bd5903ddf6eacff831c5f022c7e37eaa8c5709c..28f4babf46a09a80efcae27acb37b4b16612180a 100644 |
| --- a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
| +++ b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h |
| @@ -102,27 +102,14 @@ class WTF_EXPORT ArrayBufferContents { |
| s_adjustAmountOfExternalAllocatedMemoryFunction = function; |
| } |
| - enum LeaveOrEnter { |
| - Leave, |
| - Enter, |
| - }; |
| + void registerExternalAllocationWithCurrentContext() { |
| + if (m_holder) |
| + m_holder->registerExternalAllocationWithCurrentContext(); |
| + } |
| - // Externally allocated memory is kept track of per context (isolate), |
| - // hence when moving ArrayBufferContents to another context, its |
| - // externally allocated memory needs to be registered with its |
| - // destination context. |
| - // |
| - // Expose |adjustExternalAllocatedMemoryUponContextTransfer| in order to do |
| - // so, which postMessage() implementations make use of when transferring |
| - // array buffers. |
| - void adjustExternalAllocatedMemoryUponContextTransfer( |
| - LeaveOrEnter direction) { |
| - int64_t diff = static_cast<int64_t>(sizeInBytes()); |
| - if (!diff) |
| - return; |
| - if (direction == Leave) |
| - diff = -diff; |
| - m_holder->adjustAmountOfExternalAllocatedMemory(diff); |
| + void unregisterExternalAllocationWithCurrentContext() { |
| + if (m_holder) |
| + m_holder->unregisterExternalAllocationWithCurrentContext(); |
| } |
| private: |
| @@ -149,12 +136,16 @@ class WTF_EXPORT ArrayBufferContents { |
| unsigned sizeInBytes() const { return m_sizeInBytes; } |
| bool isShared() const { return m_isShared == Shared; } |
| + void registerExternalAllocationWithCurrentContext(); |
| + void unregisterExternalAllocationWithCurrentContext(); |
| + |
| + private: |
| void adjustAmountOfExternalAllocatedMemory(int64_t diff) { |
| + m_hasRegisteredExternalAllocation = !m_hasRegisteredExternalAllocation; |
|
jbroman
2017/03/14 15:43:33
nit: sanity DCHECK that this is becoming true if d
sof
2017/03/14 16:51:39
Done.
|
| checkIfAdjustAmountOfExternalAllocatedMemoryIsConsistent(); |
| s_adjustAmountOfExternalAllocatedMemoryFunction(diff); |
| } |
| - private: |
| void adjustAmountOfExternalAllocatedMemory(unsigned diff) { |
| adjustAmountOfExternalAllocatedMemory(static_cast<int64_t>(diff)); |
| } |
| @@ -177,6 +168,7 @@ class WTF_EXPORT ArrayBufferContents { |
| DataHandle m_data; |
| unsigned m_sizeInBytes; |
| SharingType m_isShared; |
| + bool m_hasRegisteredExternalAllocation; |
| }; |
| RefPtr<DataHolder> m_holder; |