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> |
| 9 |
| 10 #include "base/macros.h" |
8 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
9 #include "ppapi/shared_impl/ppapi_shared_export.h" | 12 #include "ppapi/shared_impl/ppapi_shared_export.h" |
10 | 13 |
11 namespace ppapi { | 14 namespace ppapi { |
12 | 15 |
13 class PPAPI_SHARED_EXPORT ScopedPPVar { | 16 class PPAPI_SHARED_EXPORT ScopedPPVar { |
14 public: | 17 public: |
15 struct PassRef {}; | 18 struct PassRef {}; |
16 | 19 |
17 ScopedPPVar(); | 20 ScopedPPVar(); |
(...skipping 17 matching lines...) Expand all Loading... |
35 const PP_Var& get() const { return var_; } | 38 const PP_Var& get() const { return var_; } |
36 | 39 |
37 // Returns the PP_Var, passing the reference to the caller. This class | 40 // Returns the PP_Var, passing the reference to the caller. This class |
38 // will no longer hold the var. | 41 // will no longer hold the var. |
39 PP_Var Release(); | 42 PP_Var Release(); |
40 | 43 |
41 private: | 44 private: |
42 PP_Var var_; | 45 PP_Var var_; |
43 }; | 46 }; |
44 | 47 |
| 48 // An array of PP_Vars which will be deallocated and have their references |
| 49 // decremented when they go out of scope. |
| 50 class ScopedPPVarArray { |
| 51 public: |
| 52 struct PassPPBMemoryAllocatedRef {}; |
| 53 |
| 54 // Assumes responsibility for one ref of each of the vars in the array as |
| 55 // well as the array memory allocated by PPB_Memory_Dev. |
| 56 // TODO(raymes): Add compatibility for arrays allocated with C++ "new". |
| 57 ScopedPPVarArray(const PassPPBMemoryAllocatedRef&, |
| 58 PP_Var* array, |
| 59 size_t size); |
| 60 |
| 61 explicit ScopedPPVarArray(size_t size); |
| 62 ~ScopedPPVarArray(); |
| 63 |
| 64 PP_Var* Release(size_t* size); |
| 65 |
| 66 PP_Var* get() { return array_; } |
| 67 size_t size() { return size_; } |
| 68 |
| 69 // Assumes responsibility for one ref. The existing var at the index will be |
| 70 // released. |
| 71 void Set(size_t index, PP_Var var); |
| 72 const PP_Var& operator[](size_t index) { return array_[index]; } |
| 73 |
| 74 private: |
| 75 // TODO(raymes): Consider supporting copy/assign. |
| 76 DISALLOW_COPY_AND_ASSIGN(ScopedPPVarArray); |
| 77 |
| 78 PP_Var* array_; |
| 79 size_t size_; |
| 80 }; |
| 81 |
45 } // namespace ppapi | 82 } // namespace ppapi |
46 | 83 |
47 #endif // PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ | 84 #endif // PPAPI_SHARED_IMPL_SCOPED_PP_VAR_H_ |
OLD | NEW |