Remove duplicate includes from chromeos/
[chromium-blink-merge.git] / gin / array_buffer.h
blobfe3fae28153e37e4c80c2fc4b2457a45ad567623
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GIN_ARRAY_BUFFER_H_
6 #define GIN_ARRAY_BUFFER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "gin/converter.h"
12 #include "gin/gin_export.h"
13 #include "v8/include/v8.h"
15 namespace gin {
17 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
18 public:
19 void* Allocate(size_t length) override;
20 void* AllocateUninitialized(size_t length) override;
21 void Free(void* data, size_t length) override;
23 GIN_EXPORT static ArrayBufferAllocator* SharedInstance();
26 class GIN_EXPORT ArrayBuffer {
27 public:
28 ArrayBuffer();
29 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer);
30 ~ArrayBuffer();
31 ArrayBuffer& operator=(const ArrayBuffer& other);
33 void* bytes() const { return bytes_; }
34 size_t num_bytes() const { return num_bytes_; }
36 private:
37 class Private;
39 scoped_refptr<Private> private_;
40 void* bytes_;
41 size_t num_bytes_;
43 DISALLOW_COPY(ArrayBuffer);
46 template<>
47 struct GIN_EXPORT Converter<ArrayBuffer> {
48 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
49 ArrayBuffer* out);
52 class GIN_EXPORT ArrayBufferView {
53 public:
54 ArrayBufferView();
55 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view);
56 ~ArrayBufferView();
57 ArrayBufferView& operator=(const ArrayBufferView& other);
59 void* bytes() const {
60 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_;
62 size_t num_bytes() const { return num_bytes_; }
64 private:
65 ArrayBuffer array_buffer_;
66 size_t offset_;
67 size_t num_bytes_;
69 DISALLOW_COPY(ArrayBufferView);
72 template<>
73 struct GIN_EXPORT Converter<ArrayBufferView> {
74 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
75 ArrayBufferView* out);
78 } // namespace gin
80 #endif // GIN_ARRAY_BUFFER_H_