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

Side by Side Diff: third_party/WebKit/Source/wtf/ArrayBufferContents.h

Issue 1436153002: Apply clang-format with Chromium-style without column limit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 19 matching lines...) Expand all
30 #include "wtf/Assertions.h" 30 #include "wtf/Assertions.h"
31 #include "wtf/Noncopyable.h" 31 #include "wtf/Noncopyable.h"
32 #include "wtf/RefPtr.h" 32 #include "wtf/RefPtr.h"
33 #include "wtf/ThreadSafeRefCounted.h" 33 #include "wtf/ThreadSafeRefCounted.h"
34 #include "wtf/WTF.h" 34 #include "wtf/WTF.h"
35 #include "wtf/WTFExport.h" 35 #include "wtf/WTFExport.h"
36 36
37 namespace WTF { 37 namespace WTF {
38 38
39 class WTF_EXPORT ArrayBufferContents { 39 class WTF_EXPORT ArrayBufferContents {
40 WTF_MAKE_NONCOPYABLE(ArrayBufferContents); 40 WTF_MAKE_NONCOPYABLE(ArrayBufferContents);
41 public:
42 enum InitializationPolicy {
43 ZeroInitialize,
44 DontInitialize
45 };
46 41
47 enum SharingType { 42 public:
48 NotShared, 43 enum InitializationPolicy {
49 Shared, 44 ZeroInitialize,
50 }; 45 DontInitialize
46 };
51 47
52 ArrayBufferContents(); 48 enum SharingType {
53 ArrayBufferContents(unsigned numElements, unsigned elementByteSize, SharingT ype isShared, ArrayBufferContents::InitializationPolicy); 49 NotShared,
50 Shared,
51 };
54 52
55 // Use with care. data must be allocated with allocateMemory. 53 ArrayBufferContents();
56 // ArrayBufferContents will take ownership of the data and free it (using fr eeMemory) 54 ArrayBufferContents(unsigned numElements, unsigned elementByteSize, SharingTyp e isShared, ArrayBufferContents::InitializationPolicy);
57 // upon destruction.
58 // This constructor will not call observer->StartObserving(), so it is a res ponsibility
59 // of the caller to make sure JS knows about external memory.
60 ArrayBufferContents(void* data, unsigned sizeInBytes, SharingType isShared);
61 55
62 ~ArrayBufferContents(); 56 // Use with care. data must be allocated with allocateMemory.
57 // ArrayBufferContents will take ownership of the data and free it (using free Memory)
58 // upon destruction.
59 // This constructor will not call observer->StartObserving(), so it is a respo nsibility
60 // of the caller to make sure JS knows about external memory.
61 ArrayBufferContents(void* data, unsigned sizeInBytes, SharingType isShared);
63 62
64 void neuter(); 63 ~ArrayBufferContents();
65 64
66 void* data() const { return m_holder ? m_holder->data() : nullptr; } 65 void neuter();
67 unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0 ; }
68 bool isShared() const { return m_holder ? m_holder->isShared() : false; }
69 66
70 void transfer(ArrayBufferContents& other); 67 void* data() const { return m_holder ? m_holder->data() : nullptr; }
71 void shareWith(ArrayBufferContents& other); 68 unsigned sizeInBytes() const { return m_holder ? m_holder->sizeInBytes() : 0; }
72 void copyTo(ArrayBufferContents& other); 69 bool isShared() const { return m_holder ? m_holder->isShared() : false; }
73 70
74 static void allocateMemory(size_t, InitializationPolicy, void*&); 71 void transfer(ArrayBufferContents& other);
75 static void freeMemory(void*, size_t); 72 void shareWith(ArrayBufferContents& other);
76 static void setAdjustAmoutOfExternalAllocatedMemoryFunction(AdjustAmountOfEx ternalAllocatedMemoryFunction function) 73 void copyTo(ArrayBufferContents& other);
77 {
78 ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction);
79 s_adjustAmountOfExternalAllocatedMemoryFunction = function;
80 }
81 74
82 private: 75 static void allocateMemory(size_t, InitializationPolicy, void*&);
83 class DataHolder : public ThreadSafeRefCounted<DataHolder> { 76 static void freeMemory(void*, size_t);
84 WTF_MAKE_NONCOPYABLE(DataHolder); 77 static void setAdjustAmoutOfExternalAllocatedMemoryFunction(AdjustAmountOfExte rnalAllocatedMemoryFunction function) {
85 public: 78 ASSERT(!s_adjustAmountOfExternalAllocatedMemoryFunction);
86 DataHolder(); 79 s_adjustAmountOfExternalAllocatedMemoryFunction = function;
87 ~DataHolder(); 80 }
88 81
89 void allocateNew(unsigned sizeInBytes, SharingType isShared, Initializat ionPolicy); 82 private:
90 void adopt(void* data, unsigned sizeInBytes, SharingType isShared); 83 class DataHolder : public ThreadSafeRefCounted<DataHolder> {
91 void copyMemoryTo(DataHolder& other); 84 WTF_MAKE_NONCOPYABLE(DataHolder);
92 85
93 void* data() const { return m_data; } 86 public:
94 unsigned sizeInBytes() const { return m_sizeInBytes; } 87 DataHolder();
95 bool isShared() const { return m_isShared == Shared; } 88 ~DataHolder();
96 89
97 private: 90 void allocateNew(unsigned sizeInBytes, SharingType isShared, InitializationP olicy);
98 void* m_data; 91 void adopt(void* data, unsigned sizeInBytes, SharingType isShared);
99 unsigned m_sizeInBytes; 92 void copyMemoryTo(DataHolder& other);
100 SharingType m_isShared;
101 };
102 93
103 RefPtr<DataHolder> m_holder; 94 void* data() const { return m_data; }
104 static AdjustAmountOfExternalAllocatedMemoryFunction s_adjustAmountOfExterna lAllocatedMemoryFunction; 95 unsigned sizeInBytes() const { return m_sizeInBytes; }
96 bool isShared() const { return m_isShared == Shared; }
97
98 private:
99 void* m_data;
100 unsigned m_sizeInBytes;
101 SharingType m_isShared;
102 };
103
104 RefPtr<DataHolder> m_holder;
105 static AdjustAmountOfExternalAllocatedMemoryFunction s_adjustAmountOfExternalA llocatedMemoryFunction;
105 }; 106 };
106 107
107 } // namespace WTF 108 } // namespace WTF
108 109
109 #endif // ArrayBufferContents_h 110 #endif // ArrayBufferContents_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ArrayBufferBuilderTest.cpp ('k') | third_party/WebKit/Source/wtf/ArrayBufferContents.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698