OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ | 5 #ifndef PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ |
6 #define PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ | 6 #define PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // TODO(raymes): Add compatibility for arrays allocated with C++ "new". | 56 // TODO(raymes): Add compatibility for arrays allocated with C++ "new". |
57 ScopedPPVarArray(const PassPPBMemoryAllocatedArray&, | 57 ScopedPPVarArray(const PassPPBMemoryAllocatedArray&, |
58 PP_Var* array, | 58 PP_Var* array, |
59 size_t size); | 59 size_t size); |
60 | 60 |
61 explicit ScopedPPVarArray(size_t size); | 61 explicit ScopedPPVarArray(size_t size); |
62 ~ScopedPPVarArray(); | 62 ~ScopedPPVarArray(); |
63 | 63 |
64 // Passes ownership of the vars and the underlying array memory to the caller. | 64 // Passes ownership of the vars and the underlying array memory to the caller. |
65 // Note that the memory has been allocated with PPB_Memory_Dev. | 65 // Note that the memory has been allocated with PPB_Memory_Dev. |
66 PP_Var* Release(const PassPPBMemoryAllocatedArray&, size_t* size); | 66 PP_Var* Release(const PassPPBMemoryAllocatedArray&); |
67 | 67 |
68 PP_Var* get() { return array_; } | 68 PP_Var* get() { return array_; } |
69 size_t size() { return size_; } | 69 size_t size() { return size_; } |
70 | 70 |
71 // Adds a ref to |var|. The refcount of the existing var will be decremented. | 71 // Takes a ref to |var|. The refcount of the existing var will be decremented. |
72 void Set(size_t index, PP_Var var); | 72 void Set(size_t index, const ScopedPPVar& var); |
73 const PP_Var& operator[](size_t index) { return array_[index]; } | 73 const PP_Var& operator[](size_t index) { return array_[index]; } |
74 | 74 |
75 private: | 75 private: |
76 // TODO(raymes): Consider supporting copy/assign. | 76 // TODO(raymes): Consider supporting copy/assign. |
77 DISALLOW_COPY_AND_ASSIGN(ScopedPPVarArray); | 77 DISALLOW_COPY_AND_ASSIGN(ScopedPPVarArray); |
78 | 78 |
79 PP_Var* array_; | 79 PP_Var* array_; |
80 size_t size_; | 80 size_t size_; |
81 }; | 81 }; |
82 | 82 |
83 } // namespace ppapi | 83 } // namespace ppapi |
84 | 84 |
85 #endif // PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ | 85 #endif // PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ |
OLD | NEW |