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_ARRAY_WRITER_H_ | 5 #ifndef PPAPI_SHARED_IMPL_ARRAY_WRITER_H_ |
6 #define PPAPI_SHARED_IMPL_ARRAY_WRITER_H_ | 6 #define PPAPI_SHARED_IMPL_ARRAY_WRITER_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "ppapi/c/pp_array_output.h" | 13 #include "ppapi/c/pp_array_output.h" |
14 #include "ppapi/c/pp_resource.h" | 14 #include "ppapi/c/pp_resource.h" |
15 #include "ppapi/c/pp_var.h" | 15 #include "ppapi/c/pp_var.h" |
16 #include "ppapi/shared_impl/ppapi_shared_export.h" | 16 #include "ppapi/shared_impl/ppapi_shared_export.h" |
17 | 17 |
18 namespace ppapi { | 18 namespace ppapi { |
19 | 19 |
20 class Resource; | 20 class Resource; |
| 21 class Var; |
21 | 22 |
22 // Holds a PP_ArrayWriter and provides helper functions for writing arrays | 23 // Holds a PP_ArrayWriter and provides helper functions for writing arrays |
23 // to it. It also handles 0-initialization of the raw C struct and attempts | 24 // to it. It also handles 0-initialization of the raw C struct and attempts |
24 // to prevent you from writing the array twice. | 25 // to prevent you from writing the array twice. |
25 class PPAPI_SHARED_EXPORT ArrayWriter { | 26 class PPAPI_SHARED_EXPORT ArrayWriter { |
26 public: | 27 public: |
27 ArrayWriter(); // Creates an is_null() object | 28 ArrayWriter(); // Creates an is_null() object |
28 ArrayWriter(const PP_ArrayOutput& output); | 29 ArrayWriter(const PP_ArrayOutput& output); |
29 ~ArrayWriter(); | 30 ~ArrayWriter(); |
30 | 31 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // adding one reference to each. | 83 // adding one reference to each. |
83 // | 84 // |
84 // On failure this returns false, nothing will be copied, and the resource | 85 // On failure this returns false, nothing will be copied, and the resource |
85 // refcounts will be unchanged. In either case, the object will become | 86 // refcounts will be unchanged. In either case, the object will become |
86 // is_null() immediately after the call since one output function should only | 87 // is_null() immediately after the call since one output function should only |
87 // be issued once. | 88 // be issued once. |
88 // | 89 // |
89 // Note: potentially this could be a template in case you have a vector of | 90 // Note: potentially this could be a template in case you have a vector of |
90 // FileRef objects, for example. However, this saves code since there's only | 91 // FileRef objects, for example. However, this saves code since there's only |
91 // one instantiation and is sufficient for now. | 92 // one instantiation and is sufficient for now. |
92 bool StoreResourceVector( | 93 bool StoreResourceVector(const std::vector< scoped_refptr<Resource> >& input); |
93 const std::vector< scoped_refptr<Resource> >& input); | |
94 | 94 |
95 // Like the above version but takes an array of AddRed'ed PP_Resources. On | 95 // Like the above version but takes an array of AddRef'ed PP_Resources. On |
96 // storage failure, this will release each resource. | 96 // storage failure, this will release each resource. |
97 bool StoreResourceVector(const std::vector<PP_Resource>& input); | 97 bool StoreResourceVector(const std::vector<PP_Resource>& input); |
98 | 98 |
| 99 // Stores the given vector of vars as PP_Vars to the output vector, |
| 100 // adding one reference to each. |
| 101 // |
| 102 // On failure this returns false, nothing will be copied, and the var |
| 103 // refcounts will be unchanged. In either case, the object will become |
| 104 // is_null() immediately after the call since one output function should only |
| 105 // be issued once. |
| 106 bool StoreVarVector(const std::vector< scoped_refptr<Var> >& input); |
| 107 |
| 108 // Like the above version but takes an array of AddRef'ed PP_Vars. On |
| 109 // storage failure, this will release each var. |
| 110 bool StoreVarVector(const std::vector<PP_Var>& input); |
| 111 |
99 private: | 112 private: |
100 PP_ArrayOutput pp_array_output_; | 113 PP_ArrayOutput pp_array_output_; |
101 | 114 |
102 DISALLOW_COPY_AND_ASSIGN(ArrayWriter); | 115 DISALLOW_COPY_AND_ASSIGN(ArrayWriter); |
103 }; | 116 }; |
104 | 117 |
105 } // namespace ppapi | 118 } // namespace ppapi |
106 | 119 |
107 #endif // PPAPI_SHARED_IMPL_ARRAY_WRITER_H_ | 120 #endif // PPAPI_SHARED_IMPL_ARRAY_WRITER_H_ |
OLD | NEW |