OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_PROXY_RAW_VAR_DATA_H_ | 5 #ifndef PPAPI_PROXY_RAW_VAR_DATA_H_ |
6 #define PPAPI_PROXY_RAW_VAR_DATA_H_ | 6 #define PPAPI_PROXY_RAW_VAR_DATA_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 namespace IPC { | 27 namespace IPC { |
28 class Message; | 28 class Message; |
29 } | 29 } |
30 | 30 |
31 namespace ppapi { | 31 namespace ppapi { |
32 namespace proxy { | 32 namespace proxy { |
33 | 33 |
34 class RawVarData; | 34 class RawVarData; |
35 | 35 |
36 typedef base::Callback<void(IPC::Message*, const SerializedHandle&)> | 36 typedef base::Callback<void(base::Pickle*, const SerializedHandle&)> |
37 HandleWriter; | 37 HandleWriter; |
38 | 38 |
39 // Contains the data associated with a graph of connected PP_Vars. Useful for | 39 // Contains the data associated with a graph of connected PP_Vars. Useful for |
40 // serializing/deserializing a graph of PP_Vars. First we compute the transitive | 40 // serializing/deserializing a graph of PP_Vars. First we compute the transitive |
41 // closure of the given PP_Var to find all PP_Vars which are referenced by that | 41 // closure of the given PP_Var to find all PP_Vars which are referenced by that |
42 // var. A RawVarData object is created for each of these vars. We then write | 42 // var. A RawVarData object is created for each of these vars. We then write |
43 // data contained in each RawVarData to the message. The format looks like this: | 43 // data contained in each RawVarData to the message. The format looks like this: |
44 // idx | size | (number of vars in the graph) | 44 // idx | size | (number of vars in the graph) |
45 // 0 | var type | | 45 // 0 | var type | |
46 // | var data | | 46 // | var data | |
(...skipping 16 matching lines...) Expand all Loading... |
63 RawVarDataGraph(); | 63 RawVarDataGraph(); |
64 ~RawVarDataGraph(); | 64 ~RawVarDataGraph(); |
65 | 65 |
66 // Construct a new PP_Var from the graph. All of the PP_Vars referenced by | 66 // Construct a new PP_Var from the graph. All of the PP_Vars referenced by |
67 // the returned PP_Var are also constructed. Each PP_Var created has a | 67 // the returned PP_Var are also constructed. Each PP_Var created has a |
68 // ref-count equal to the number of references it has in the graph of vars. | 68 // ref-count equal to the number of references it has in the graph of vars. |
69 // The returned var (the "root") has one additional reference. | 69 // The returned var (the "root") has one additional reference. |
70 PP_Var CreatePPVar(PP_Instance instance); | 70 PP_Var CreatePPVar(PP_Instance instance); |
71 | 71 |
72 // Write the graph to a message using the given HandleWriter. | 72 // Write the graph to a message using the given HandleWriter. |
73 void Write(IPC::Message* m, const HandleWriter& handle_writer); | 73 void Write(base::Pickle* m, const HandleWriter& handle_writer); |
74 | 74 |
75 // Create a RawVarDataGraph from the given message. | 75 // Create a RawVarDataGraph from the given message. |
76 static scoped_ptr<RawVarDataGraph> Read(const IPC::Message* m, | 76 static scoped_ptr<RawVarDataGraph> Read(const base::Pickle* m, |
77 base::PickleIterator* iter); | 77 base::PickleIterator* iter); |
78 | 78 |
79 // Returns a vector of SerializedHandles associated with this RawVarDataGraph. | 79 // Returns a vector of SerializedHandles associated with this RawVarDataGraph. |
80 // Ownership of the pointers remains with the elements of the RawVarDataGraph. | 80 // Ownership of the pointers remains with the elements of the RawVarDataGraph. |
81 std::vector<SerializedHandle*> GetHandles(); | 81 std::vector<SerializedHandle*> GetHandles(); |
82 | 82 |
83 // Sets the threshold size at which point we switch from transmitting | 83 // Sets the threshold size at which point we switch from transmitting |
84 // array buffers in IPC messages to using shared memory. This is only used | 84 // array buffers in IPC messages to using shared memory. This is only used |
85 // for testing purposes where we need to transmit small buffers using shmem | 85 // for testing purposes where we need to transmit small buffers using shmem |
86 // (in order to have fast tests). | 86 // (in order to have fast tests). |
(...skipping 20 matching lines...) Expand all Loading... |
107 // Create a PP_Var from the raw data contained in this object. | 107 // Create a PP_Var from the raw data contained in this object. |
108 virtual PP_Var CreatePPVar(PP_Instance instance) = 0; | 108 virtual PP_Var CreatePPVar(PP_Instance instance) = 0; |
109 // Some PP_Vars may require 2-step initialization. For example, they may | 109 // Some PP_Vars may require 2-step initialization. For example, they may |
110 // reference other PP_Vars which had not yet been created when |CreatePPVar| | 110 // reference other PP_Vars which had not yet been created when |CreatePPVar| |
111 // was called. The original var created with |CreatePPVar| is passed back in, | 111 // was called. The original var created with |CreatePPVar| is passed back in, |
112 // along with the graph it is a part of to be initialized. | 112 // along with the graph it is a part of to be initialized. |
113 virtual void PopulatePPVar(const PP_Var& var, | 113 virtual void PopulatePPVar(const PP_Var& var, |
114 const std::vector<PP_Var>& graph) = 0; | 114 const std::vector<PP_Var>& graph) = 0; |
115 | 115 |
116 // Writes the RawVarData to a message. | 116 // Writes the RawVarData to a message. |
117 virtual void Write(IPC::Message* m, | 117 virtual void Write(base::Pickle* m, const HandleWriter& handle_writer) = 0; |
118 const HandleWriter& handle_writer) = 0; | |
119 // Reads the RawVarData from a message. Returns true on success. | 118 // Reads the RawVarData from a message. Returns true on success. |
120 virtual bool Read(PP_VarType type, | 119 virtual bool Read(PP_VarType type, |
121 const IPC::Message* m, | 120 const base::Pickle* m, |
122 base::PickleIterator* iter) = 0; | 121 base::PickleIterator* iter) = 0; |
123 | 122 |
124 // Returns a SerializedHandle associated with this RawVarData or NULL if none | 123 // Returns a SerializedHandle associated with this RawVarData or NULL if none |
125 // exists. Ownership of the pointer remains with the RawVarData. | 124 // exists. Ownership of the pointer remains with the RawVarData. |
126 virtual SerializedHandle* GetHandle(); | 125 virtual SerializedHandle* GetHandle(); |
127 | 126 |
128 bool initialized() { return initialized_; } | 127 bool initialized() { return initialized_; } |
129 | 128 |
130 protected: | 129 protected: |
131 bool initialized_; | 130 bool initialized_; |
132 }; | 131 }; |
133 | 132 |
134 // A RawVarData class for PP_Vars which are value types. | 133 // A RawVarData class for PP_Vars which are value types. |
135 class BasicRawVarData : public RawVarData { | 134 class BasicRawVarData : public RawVarData { |
136 public: | 135 public: |
137 BasicRawVarData(); | 136 BasicRawVarData(); |
138 ~BasicRawVarData() override; | 137 ~BasicRawVarData() override; |
139 | 138 |
140 // RawVarData implementation. | 139 // RawVarData implementation. |
141 PP_VarType Type() override; | 140 PP_VarType Type() override; |
142 bool Init(const PP_Var& var, PP_Instance instance) override; | 141 bool Init(const PP_Var& var, PP_Instance instance) override; |
143 PP_Var CreatePPVar(PP_Instance instance) override; | 142 PP_Var CreatePPVar(PP_Instance instance) override; |
144 void PopulatePPVar(const PP_Var& var, | 143 void PopulatePPVar(const PP_Var& var, |
145 const std::vector<PP_Var>& graph) override; | 144 const std::vector<PP_Var>& graph) override; |
146 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 145 void Write(base::Pickle* m, const HandleWriter& handle_writer) override; |
147 bool Read(PP_VarType type, | 146 bool Read(PP_VarType type, |
148 const IPC::Message* m, | 147 const base::Pickle* m, |
149 base::PickleIterator* iter) override; | 148 base::PickleIterator* iter) override; |
150 | 149 |
151 private: | 150 private: |
152 PP_Var var_; | 151 PP_Var var_; |
153 }; | 152 }; |
154 | 153 |
155 // A RawVarData class for string PP_Vars. | 154 // A RawVarData class for string PP_Vars. |
156 class StringRawVarData : public RawVarData { | 155 class StringRawVarData : public RawVarData { |
157 public: | 156 public: |
158 StringRawVarData(); | 157 StringRawVarData(); |
159 ~StringRawVarData() override; | 158 ~StringRawVarData() override; |
160 | 159 |
161 // RawVarData implementation. | 160 // RawVarData implementation. |
162 PP_VarType Type() override; | 161 PP_VarType Type() override; |
163 bool Init(const PP_Var& var, PP_Instance instance) override; | 162 bool Init(const PP_Var& var, PP_Instance instance) override; |
164 PP_Var CreatePPVar(PP_Instance instance) override; | 163 PP_Var CreatePPVar(PP_Instance instance) override; |
165 void PopulatePPVar(const PP_Var& var, | 164 void PopulatePPVar(const PP_Var& var, |
166 const std::vector<PP_Var>& graph) override; | 165 const std::vector<PP_Var>& graph) override; |
167 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 166 void Write(base::Pickle* m, const HandleWriter& handle_writer) override; |
168 bool Read(PP_VarType type, | 167 bool Read(PP_VarType type, |
169 const IPC::Message* m, | 168 const base::Pickle* m, |
170 base::PickleIterator* iter) override; | 169 base::PickleIterator* iter) override; |
171 | 170 |
172 private: | 171 private: |
173 // The data in the string. | 172 // The data in the string. |
174 std::string data_; | 173 std::string data_; |
175 }; | 174 }; |
176 | 175 |
177 // A RawVarData class for array buffer PP_Vars. | 176 // A RawVarData class for array buffer PP_Vars. |
178 class ArrayBufferRawVarData : public RawVarData { | 177 class ArrayBufferRawVarData : public RawVarData { |
179 public: | 178 public: |
180 // Enum for array buffer message types. | 179 // Enum for array buffer message types. |
181 enum ShmemType { | 180 enum ShmemType { |
182 ARRAY_BUFFER_NO_SHMEM, | 181 ARRAY_BUFFER_NO_SHMEM, |
183 ARRAY_BUFFER_SHMEM_HOST, | 182 ARRAY_BUFFER_SHMEM_HOST, |
184 ARRAY_BUFFER_SHMEM_PLUGIN, | 183 ARRAY_BUFFER_SHMEM_PLUGIN, |
185 }; | 184 }; |
186 | 185 |
187 ArrayBufferRawVarData(); | 186 ArrayBufferRawVarData(); |
188 ~ArrayBufferRawVarData() override; | 187 ~ArrayBufferRawVarData() override; |
189 | 188 |
190 // RawVarData implementation. | 189 // RawVarData implementation. |
191 PP_VarType Type() override; | 190 PP_VarType Type() override; |
192 bool Init(const PP_Var& var, PP_Instance instance) override; | 191 bool Init(const PP_Var& var, PP_Instance instance) override; |
193 PP_Var CreatePPVar(PP_Instance instance) override; | 192 PP_Var CreatePPVar(PP_Instance instance) override; |
194 void PopulatePPVar(const PP_Var& var, | 193 void PopulatePPVar(const PP_Var& var, |
195 const std::vector<PP_Var>& graph) override; | 194 const std::vector<PP_Var>& graph) override; |
196 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 195 void Write(base::Pickle* m, const HandleWriter& handle_writer) override; |
197 bool Read(PP_VarType type, | 196 bool Read(PP_VarType type, |
198 const IPC::Message* m, | 197 const base::Pickle* m, |
199 base::PickleIterator* iter) override; | 198 base::PickleIterator* iter) override; |
200 SerializedHandle* GetHandle() override; | 199 SerializedHandle* GetHandle() override; |
201 | 200 |
202 private: | 201 private: |
203 // The type of the storage underlying the array buffer. | 202 // The type of the storage underlying the array buffer. |
204 ShmemType type_; | 203 ShmemType type_; |
205 // The data in the buffer. Valid for |type_| == ARRAY_BUFFER_NO_SHMEM. | 204 // The data in the buffer. Valid for |type_| == ARRAY_BUFFER_NO_SHMEM. |
206 std::string data_; | 205 std::string data_; |
207 // Host shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_HOST. | 206 // Host shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_HOST. |
208 int host_shm_handle_id_; | 207 int host_shm_handle_id_; |
209 // Plugin shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_PLUGIN. | 208 // Plugin shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_PLUGIN. |
210 SerializedHandle plugin_shm_handle_; | 209 SerializedHandle plugin_shm_handle_; |
211 }; | 210 }; |
212 | 211 |
213 // A RawVarData class for array PP_Vars. | 212 // A RawVarData class for array PP_Vars. |
214 class ArrayRawVarData : public RawVarData { | 213 class ArrayRawVarData : public RawVarData { |
215 public: | 214 public: |
216 ArrayRawVarData(); | 215 ArrayRawVarData(); |
217 ~ArrayRawVarData() override; | 216 ~ArrayRawVarData() override; |
218 | 217 |
219 void AddChild(size_t element); | 218 void AddChild(size_t element); |
220 | 219 |
221 // RawVarData implementation. | 220 // RawVarData implementation. |
222 PP_VarType Type() override; | 221 PP_VarType Type() override; |
223 bool Init(const PP_Var& var, PP_Instance instance) override; | 222 bool Init(const PP_Var& var, PP_Instance instance) override; |
224 PP_Var CreatePPVar(PP_Instance instance) override; | 223 PP_Var CreatePPVar(PP_Instance instance) override; |
225 void PopulatePPVar(const PP_Var& var, | 224 void PopulatePPVar(const PP_Var& var, |
226 const std::vector<PP_Var>& graph) override; | 225 const std::vector<PP_Var>& graph) override; |
227 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 226 void Write(base::Pickle* m, const HandleWriter& handle_writer) override; |
228 bool Read(PP_VarType type, | 227 bool Read(PP_VarType type, |
229 const IPC::Message* m, | 228 const base::Pickle* m, |
230 base::PickleIterator* iter) override; | 229 base::PickleIterator* iter) override; |
231 | 230 |
232 private: | 231 private: |
233 std::vector<size_t> children_; | 232 std::vector<size_t> children_; |
234 }; | 233 }; |
235 | 234 |
236 // A RawVarData class for dictionary PP_Vars. | 235 // A RawVarData class for dictionary PP_Vars. |
237 class DictionaryRawVarData : public RawVarData { | 236 class DictionaryRawVarData : public RawVarData { |
238 public: | 237 public: |
239 DictionaryRawVarData(); | 238 DictionaryRawVarData(); |
240 ~DictionaryRawVarData() override; | 239 ~DictionaryRawVarData() override; |
241 | 240 |
242 void AddChild(const std::string& key, size_t value); | 241 void AddChild(const std::string& key, size_t value); |
243 | 242 |
244 // RawVarData implementation. | 243 // RawVarData implementation. |
245 PP_VarType Type() override; | 244 PP_VarType Type() override; |
246 bool Init(const PP_Var& var, PP_Instance instance) override; | 245 bool Init(const PP_Var& var, PP_Instance instance) override; |
247 PP_Var CreatePPVar(PP_Instance instance) override; | 246 PP_Var CreatePPVar(PP_Instance instance) override; |
248 void PopulatePPVar(const PP_Var& var, | 247 void PopulatePPVar(const PP_Var& var, |
249 const std::vector<PP_Var>& graph) override; | 248 const std::vector<PP_Var>& graph) override; |
250 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 249 void Write(base::Pickle* m, const HandleWriter& handle_writer) override; |
251 bool Read(PP_VarType type, | 250 bool Read(PP_VarType type, |
252 const IPC::Message* m, | 251 const base::Pickle* m, |
253 base::PickleIterator* iter) override; | 252 base::PickleIterator* iter) override; |
254 | 253 |
255 private: | 254 private: |
256 std::vector<std::pair<std::string, size_t> > children_; | 255 std::vector<std::pair<std::string, size_t> > children_; |
257 }; | 256 }; |
258 | 257 |
259 // A RawVarData class for resource PP_Vars. | 258 // A RawVarData class for resource PP_Vars. |
260 // This class does not hold a reference on the PP_Resource that is being | 259 // This class does not hold a reference on the PP_Resource that is being |
261 // serialized. If sending a resource from the plugin to the host, the plugin | 260 // serialized. If sending a resource from the plugin to the host, the plugin |
262 // should not release the ResourceVar before sending the serialized message to | 261 // should not release the ResourceVar before sending the serialized message to |
263 // the host, and the host should immediately consume the ResourceVar before | 262 // the host, and the host should immediately consume the ResourceVar before |
264 // processing further messages. | 263 // processing further messages. |
265 class ResourceRawVarData : public RawVarData { | 264 class ResourceRawVarData : public RawVarData { |
266 public: | 265 public: |
267 ResourceRawVarData(); | 266 ResourceRawVarData(); |
268 ~ResourceRawVarData() override; | 267 ~ResourceRawVarData() override; |
269 | 268 |
270 // RawVarData implementation. | 269 // RawVarData implementation. |
271 PP_VarType Type() override; | 270 PP_VarType Type() override; |
272 bool Init(const PP_Var& var, PP_Instance instance) override; | 271 bool Init(const PP_Var& var, PP_Instance instance) override; |
273 PP_Var CreatePPVar(PP_Instance instance) override; | 272 PP_Var CreatePPVar(PP_Instance instance) override; |
274 void PopulatePPVar(const PP_Var& var, | 273 void PopulatePPVar(const PP_Var& var, |
275 const std::vector<PP_Var>& graph) override; | 274 const std::vector<PP_Var>& graph) override; |
276 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; | 275 void Write(base::Pickle* m, const HandleWriter& handle_writer) override; |
277 bool Read(PP_VarType type, | 276 bool Read(PP_VarType type, |
278 const IPC::Message* m, | 277 const base::Pickle* m, |
279 base::PickleIterator* iter) override; | 278 base::PickleIterator* iter) override; |
280 | 279 |
281 private: | 280 private: |
282 // Resource ID in the plugin. If one has not yet been created, this is 0. | 281 // Resource ID in the plugin. If one has not yet been created, this is 0. |
283 // This is a borrowed reference; the resource's refcount is not incremented. | 282 // This is a borrowed reference; the resource's refcount is not incremented. |
284 PP_Resource pp_resource_; | 283 PP_Resource pp_resource_; |
285 | 284 |
286 // Pending resource host ID in the renderer. | 285 // Pending resource host ID in the renderer. |
287 int pending_renderer_host_id_; | 286 int pending_renderer_host_id_; |
288 | 287 |
289 // Pending resource host ID in the browser. | 288 // Pending resource host ID in the browser. |
290 int pending_browser_host_id_; | 289 int pending_browser_host_id_; |
291 | 290 |
292 // A message containing information about how to create a plugin-side | 291 // A message containing information about how to create a plugin-side |
293 // resource. The message type will vary based on the resource type, and will | 292 // resource. The message type will vary based on the resource type, and will |
294 // usually contain a pending resource host ID, and other required information. | 293 // usually contain a pending resource host ID, and other required information. |
295 // If the resource was created directly, this is NULL. | 294 // If the resource was created directly, this is NULL. |
296 scoped_ptr<IPC::Message> creation_message_; | 295 scoped_ptr<IPC::Message> creation_message_; |
297 }; | 296 }; |
298 | 297 |
299 } // namespace proxy | 298 } // namespace proxy |
300 } // namespace ppapi | 299 } // namespace ppapi |
301 | 300 |
302 #endif // PPAPI_PROXY_RAW_VAR_DATA_H_ | 301 #endif // PPAPI_PROXY_RAW_VAR_DATA_H_ |
OLD | NEW |