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

Unified Diff: third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h

Issue 2719883004: Adds support for ArrayBufferContents with external buffer. (Closed)
Patch Set: renames ScopedData -> DataHandle Created 3 years, 10 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: 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 6c5b54af6ccaca9b1ed15abfbb3f9af9c06074a9..6984c552981a1df8e54a9de95aa1398bece46161 100644
--- a/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
+++ b/third_party/WebKit/Source/wtf/typed_arrays/ArrayBufferContents.h
@@ -43,6 +43,15 @@ class WTF_EXPORT ArrayBufferContents {
public:
using AdjustAmountOfExternalAllocatedMemoryFunction = void (*)(int64_t diff);
+ // Types that need to be used when injecting external memory.
+ // DataHandle allows specifying a deleter which will be invoked when
+ // DataHandle instance goes out of scope. If the data memory is allocated
+ // using ArrayBufferContents::allocateMemoryOrNull, it is necessary to
+ // specify ArrayBufferContents::freeMemory as the DataDeleter.
+ // Most clients would want to use ArrayBufferContents::createData, which
+ // allocates memory and specifies the correct deleter.
+ using DataDeleter = void (*)(void* data);
+ using DataHandle = std::unique_ptr<void, DataDeleter>;
enum InitializationPolicy { ZeroInitialize, DontInitialize };
@@ -56,13 +65,7 @@ class WTF_EXPORT ArrayBufferContents {
unsigned elementByteSize,
SharingType isShared,
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, SharingType isShared);
+ ArrayBufferContents(DataHandle, unsigned sizeInBytes, SharingType isShared);
~ArrayBufferContents();
@@ -88,9 +91,9 @@ class WTF_EXPORT ArrayBufferContents {
void shareWith(ArrayBufferContents& other);
void copyTo(ArrayBufferContents& other);
- static void allocateMemory(size_t, InitializationPolicy, void*&);
- static void allocateMemoryOrNull(size_t, InitializationPolicy, void*&);
- static void freeMemory(void*, size_t);
+ static void* allocateMemoryOrNull(size_t, InitializationPolicy);
+ static void freeMemory(void*);
+ static DataHandle createDataHandle(size_t, InitializationPolicy);
static void initialize(
AdjustAmountOfExternalAllocatedMemoryFunction function) {
DCHECK(isMainThread());
@@ -100,10 +103,7 @@ class WTF_EXPORT ArrayBufferContents {
}
private:
- static void allocateMemoryWithFlags(size_t,
- InitializationPolicy,
- int,
- void*&);
+ static void* allocateMemoryWithFlags(size_t, InitializationPolicy, int);
static void defaultAdjustAmountOfExternalAllocatedMemoryFunction(
int64_t diff);
@@ -118,11 +118,11 @@ class WTF_EXPORT ArrayBufferContents {
void allocateNew(unsigned sizeInBytes,
SharingType isShared,
InitializationPolicy);
- void adopt(void* data, unsigned sizeInBytes, SharingType isShared);
+ void adopt(DataHandle, unsigned sizeInBytes, SharingType isShared);
void copyMemoryFrom(const DataHolder& source);
- const void* data() const { return m_data; }
- void* data() { return m_data; }
+ const void* data() const { return m_data.get(); }
+ void* data() { return m_data.get(); }
unsigned sizeInBytes() const { return m_sizeInBytes; }
bool isShared() const { return m_isShared == Shared; }
@@ -150,7 +150,7 @@ class WTF_EXPORT ArrayBufferContents {
#endif
}
- void* m_data;
+ DataHandle m_data;
unsigned m_sizeInBytes;
SharingType m_isShared;
};

Powered by Google App Engine
This is Rietveld 408576698