Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1278)

Unified Diff: Source/wtf/ArrayBufferContents.h

Issue 1097773004: Sharing of SharedArrayBuffer via PostMessage transfer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: . Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/wtf/ArrayBufferContents.h
diff --git a/Source/wtf/ArrayBufferContents.h b/Source/wtf/ArrayBufferContents.h
index 4bd137f02ce984f0fe9c70f30e1564b269498f7a..b6476aa56c0ee3ddd2b8957907d2c81ff5484995 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 {
@@ -41,35 +43,38 @@ public:
DontInitialize
};
+ enum SharingType {
+ NotShared,
+ Shared,
+ };
+
ArrayBufferContents();
- ArrayBufferContents(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
+ ArrayBufferContents(unsigned numElements, unsigned elementByteSize, SharingType isShared, ArrayBufferContents::InitializationPolicy);
// 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, SharingType 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->data() : nullptr; }
haraken 2015/06/11 05:59:29 Is it a valid thing to access these fields after t
+ unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0; }
+ bool isShared() const { return m_holder ? m_holder->isShared() : false; }
void setDeallocationObserver(ArrayBufferDeallocationObserver& observer)
{
- if (!m_deallocationObserver) {
- m_deallocationObserver = &observer;
- m_deallocationObserver->blinkAllocatedMemory(m_sizeInBytes);
- }
+ ASSERT(m_holder);
+ m_holder->setDeallocationObserver(observer);
}
void setDeallocationObserverWithoutAllocationNotification(ArrayBufferDeallocationObserver& observer)
{
- if (!m_deallocationObserver) {
- m_deallocationObserver = &observer;
- }
+ ASSERT(m_holder);
+ m_holder->setDeallocationObserverWithoutAllocationNotification(observer);
}
void transfer(ArrayBufferContents& other);
@@ -79,9 +84,30 @@ 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 allocateNew(unsigned sizeInBytes, SharingType isShared, InitializationPolicy, ArrayBufferDeallocationObserver*);
+ void adopt(void* data, unsigned sizeInBytes, SharingType isShared, ArrayBufferDeallocationObserver*);
+ void copyMemoryTo(DataHolder& other);
+
+ void* data() const { return m_data; }
+ unsigned sizeInBytes() const { return m_sizeInBytes; }
+ bool isShared() const { return m_isShared == Shared; }
+ void setDeallocationObserver(ArrayBufferDeallocationObserver&);
+ void setDeallocationObserverWithoutAllocationNotification(ArrayBufferDeallocationObserver&);
+
+ private:
+ void* m_data;
+ unsigned m_sizeInBytes;
+ SharingType m_isShared;
+ ArrayBufferDeallocationObserver* m_deallocationObserver;
+ };
+
+ RefPtr<DataHolder> m_holder;
};
} // namespace WTF

Powered by Google App Engine
This is Rietveld 408576698