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

Side by Side Diff: ppapi/proxy/raw_var_data.h

Issue 1659003003: IPC::Message -> base::Pickle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: export base::Pickle::Attachment Created 4 years, 10 months 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 // 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
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
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 23 matching lines...) Expand all
110 // Create a PP_Var from the raw data contained in this object. 110 // Create a PP_Var from the raw data contained in this object.
111 virtual PP_Var CreatePPVar(PP_Instance instance) = 0; 111 virtual PP_Var CreatePPVar(PP_Instance instance) = 0;
112 // Some PP_Vars may require 2-step initialization. For example, they may 112 // Some PP_Vars may require 2-step initialization. For example, they may
113 // reference other PP_Vars which had not yet been created when |CreatePPVar| 113 // reference other PP_Vars which had not yet been created when |CreatePPVar|
114 // was called. The original var created with |CreatePPVar| is passed back in, 114 // was called. The original var created with |CreatePPVar| is passed back in,
115 // along with the graph it is a part of to be initialized. 115 // along with the graph it is a part of to be initialized.
116 virtual void PopulatePPVar(const PP_Var& var, 116 virtual void PopulatePPVar(const PP_Var& var,
117 const std::vector<PP_Var>& graph) = 0; 117 const std::vector<PP_Var>& graph) = 0;
118 118
119 // Writes the RawVarData to a message. 119 // Writes the RawVarData to a message.
120 virtual void Write(IPC::Message* m, 120 virtual void Write(base::Pickle* m, const HandleWriter& handle_writer) = 0;
121 const HandleWriter& handle_writer) = 0;
122 // Reads the RawVarData from a message. Returns true on success. 121 // Reads the RawVarData from a message. Returns true on success.
123 virtual bool Read(PP_VarType type, 122 virtual bool Read(PP_VarType type,
124 const IPC::Message* m, 123 const base::Pickle* m,
125 base::PickleIterator* iter) = 0; 124 base::PickleIterator* iter) = 0;
126 125
127 // Returns a SerializedHandle associated with this RawVarData or NULL if none 126 // Returns a SerializedHandle associated with this RawVarData or NULL if none
128 // exists. Ownership of the pointer remains with the RawVarData. 127 // exists. Ownership of the pointer remains with the RawVarData.
129 virtual SerializedHandle* GetHandle(); 128 virtual SerializedHandle* GetHandle();
130 129
131 bool initialized() { return initialized_; } 130 bool initialized() { return initialized_; }
132 131
133 protected: 132 protected:
134 bool initialized_; 133 bool initialized_;
135 }; 134 };
136 135
137 // A RawVarData class for PP_Vars which are value types. 136 // A RawVarData class for PP_Vars which are value types.
138 class BasicRawVarData : public RawVarData { 137 class BasicRawVarData : public RawVarData {
139 public: 138 public:
140 BasicRawVarData(); 139 BasicRawVarData();
141 ~BasicRawVarData() override; 140 ~BasicRawVarData() override;
142 141
143 // RawVarData implementation. 142 // RawVarData implementation.
144 PP_VarType Type() override; 143 PP_VarType Type() override;
145 bool Init(const PP_Var& var, PP_Instance instance) override; 144 bool Init(const PP_Var& var, PP_Instance instance) override;
146 PP_Var CreatePPVar(PP_Instance instance) override; 145 PP_Var CreatePPVar(PP_Instance instance) override;
147 void PopulatePPVar(const PP_Var& var, 146 void PopulatePPVar(const PP_Var& var,
148 const std::vector<PP_Var>& graph) override; 147 const std::vector<PP_Var>& graph) override;
149 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; 148 void Write(base::Pickle* m, const HandleWriter& handle_writer) override;
150 bool Read(PP_VarType type, 149 bool Read(PP_VarType type,
151 const IPC::Message* m, 150 const base::Pickle* m,
152 base::PickleIterator* iter) override; 151 base::PickleIterator* iter) override;
153 152
154 private: 153 private:
155 PP_Var var_; 154 PP_Var var_;
156 }; 155 };
157 156
158 // A RawVarData class for string PP_Vars. 157 // A RawVarData class for string PP_Vars.
159 class StringRawVarData : public RawVarData { 158 class StringRawVarData : public RawVarData {
160 public: 159 public:
161 StringRawVarData(); 160 StringRawVarData();
162 ~StringRawVarData() override; 161 ~StringRawVarData() override;
163 162
164 // RawVarData implementation. 163 // RawVarData implementation.
165 PP_VarType Type() override; 164 PP_VarType Type() override;
166 bool Init(const PP_Var& var, PP_Instance instance) override; 165 bool Init(const PP_Var& var, PP_Instance instance) override;
167 PP_Var CreatePPVar(PP_Instance instance) override; 166 PP_Var CreatePPVar(PP_Instance instance) override;
168 void PopulatePPVar(const PP_Var& var, 167 void PopulatePPVar(const PP_Var& var,
169 const std::vector<PP_Var>& graph) override; 168 const std::vector<PP_Var>& graph) override;
170 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; 169 void Write(base::Pickle* m, const HandleWriter& handle_writer) override;
171 bool Read(PP_VarType type, 170 bool Read(PP_VarType type,
172 const IPC::Message* m, 171 const base::Pickle* m,
173 base::PickleIterator* iter) override; 172 base::PickleIterator* iter) override;
174 173
175 private: 174 private:
176 // The data in the string. 175 // The data in the string.
177 std::string data_; 176 std::string data_;
178 }; 177 };
179 178
180 // A RawVarData class for array buffer PP_Vars. 179 // A RawVarData class for array buffer PP_Vars.
181 class ArrayBufferRawVarData : public RawVarData { 180 class ArrayBufferRawVarData : public RawVarData {
182 public: 181 public:
183 // Enum for array buffer message types. 182 // Enum for array buffer message types.
184 enum ShmemType { 183 enum ShmemType {
185 ARRAY_BUFFER_NO_SHMEM, 184 ARRAY_BUFFER_NO_SHMEM,
186 ARRAY_BUFFER_SHMEM_HOST, 185 ARRAY_BUFFER_SHMEM_HOST,
187 ARRAY_BUFFER_SHMEM_PLUGIN, 186 ARRAY_BUFFER_SHMEM_PLUGIN,
188 }; 187 };
189 188
190 ArrayBufferRawVarData(); 189 ArrayBufferRawVarData();
191 ~ArrayBufferRawVarData() override; 190 ~ArrayBufferRawVarData() override;
192 191
193 // RawVarData implementation. 192 // RawVarData implementation.
194 PP_VarType Type() override; 193 PP_VarType Type() override;
195 bool Init(const PP_Var& var, PP_Instance instance) override; 194 bool Init(const PP_Var& var, PP_Instance instance) override;
196 PP_Var CreatePPVar(PP_Instance instance) override; 195 PP_Var CreatePPVar(PP_Instance instance) override;
197 void PopulatePPVar(const PP_Var& var, 196 void PopulatePPVar(const PP_Var& var,
198 const std::vector<PP_Var>& graph) override; 197 const std::vector<PP_Var>& graph) override;
199 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; 198 void Write(base::Pickle* m, const HandleWriter& handle_writer) override;
200 bool Read(PP_VarType type, 199 bool Read(PP_VarType type,
201 const IPC::Message* m, 200 const base::Pickle* m,
202 base::PickleIterator* iter) override; 201 base::PickleIterator* iter) override;
203 SerializedHandle* GetHandle() override; 202 SerializedHandle* GetHandle() override;
204 203
205 private: 204 private:
206 // The type of the storage underlying the array buffer. 205 // The type of the storage underlying the array buffer.
207 ShmemType type_; 206 ShmemType type_;
208 // The data in the buffer. Valid for |type_| == ARRAY_BUFFER_NO_SHMEM. 207 // The data in the buffer. Valid for |type_| == ARRAY_BUFFER_NO_SHMEM.
209 std::string data_; 208 std::string data_;
210 // Host shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_HOST. 209 // Host shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_HOST.
211 int host_shm_handle_id_; 210 int host_shm_handle_id_;
212 // Plugin shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_PLUGIN. 211 // Plugin shmem handle. Valid for |type_| == ARRAY_BUFFER_SHMEM_PLUGIN.
213 SerializedHandle plugin_shm_handle_; 212 SerializedHandle plugin_shm_handle_;
214 }; 213 };
215 214
216 // A RawVarData class for array PP_Vars. 215 // A RawVarData class for array PP_Vars.
217 class ArrayRawVarData : public RawVarData { 216 class ArrayRawVarData : public RawVarData {
218 public: 217 public:
219 ArrayRawVarData(); 218 ArrayRawVarData();
220 ~ArrayRawVarData() override; 219 ~ArrayRawVarData() override;
221 220
222 void AddChild(size_t element); 221 void AddChild(size_t element);
223 222
224 // RawVarData implementation. 223 // RawVarData implementation.
225 PP_VarType Type() override; 224 PP_VarType Type() override;
226 bool Init(const PP_Var& var, PP_Instance instance) override; 225 bool Init(const PP_Var& var, PP_Instance instance) override;
227 PP_Var CreatePPVar(PP_Instance instance) override; 226 PP_Var CreatePPVar(PP_Instance instance) override;
228 void PopulatePPVar(const PP_Var& var, 227 void PopulatePPVar(const PP_Var& var,
229 const std::vector<PP_Var>& graph) override; 228 const std::vector<PP_Var>& graph) override;
230 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; 229 void Write(base::Pickle* m, const HandleWriter& handle_writer) override;
231 bool Read(PP_VarType type, 230 bool Read(PP_VarType type,
232 const IPC::Message* m, 231 const base::Pickle* m,
233 base::PickleIterator* iter) override; 232 base::PickleIterator* iter) override;
234 233
235 private: 234 private:
236 std::vector<size_t> children_; 235 std::vector<size_t> children_;
237 }; 236 };
238 237
239 // A RawVarData class for dictionary PP_Vars. 238 // A RawVarData class for dictionary PP_Vars.
240 class DictionaryRawVarData : public RawVarData { 239 class DictionaryRawVarData : public RawVarData {
241 public: 240 public:
242 DictionaryRawVarData(); 241 DictionaryRawVarData();
243 ~DictionaryRawVarData() override; 242 ~DictionaryRawVarData() override;
244 243
245 void AddChild(const std::string& key, size_t value); 244 void AddChild(const std::string& key, size_t value);
246 245
247 // RawVarData implementation. 246 // RawVarData implementation.
248 PP_VarType Type() override; 247 PP_VarType Type() override;
249 bool Init(const PP_Var& var, PP_Instance instance) override; 248 bool Init(const PP_Var& var, PP_Instance instance) override;
250 PP_Var CreatePPVar(PP_Instance instance) override; 249 PP_Var CreatePPVar(PP_Instance instance) override;
251 void PopulatePPVar(const PP_Var& var, 250 void PopulatePPVar(const PP_Var& var,
252 const std::vector<PP_Var>& graph) override; 251 const std::vector<PP_Var>& graph) override;
253 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; 252 void Write(base::Pickle* m, const HandleWriter& handle_writer) override;
254 bool Read(PP_VarType type, 253 bool Read(PP_VarType type,
255 const IPC::Message* m, 254 const base::Pickle* m,
256 base::PickleIterator* iter) override; 255 base::PickleIterator* iter) override;
257 256
258 private: 257 private:
259 std::vector<std::pair<std::string, size_t> > children_; 258 std::vector<std::pair<std::string, size_t> > children_;
260 }; 259 };
261 260
262 // A RawVarData class for resource PP_Vars. 261 // A RawVarData class for resource PP_Vars.
263 // This class does not hold a reference on the PP_Resource that is being 262 // This class does not hold a reference on the PP_Resource that is being
264 // serialized. If sending a resource from the plugin to the host, the plugin 263 // serialized. If sending a resource from the plugin to the host, the plugin
265 // should not release the ResourceVar before sending the serialized message to 264 // should not release the ResourceVar before sending the serialized message to
266 // the host, and the host should immediately consume the ResourceVar before 265 // the host, and the host should immediately consume the ResourceVar before
267 // processing further messages. 266 // processing further messages.
268 class ResourceRawVarData : public RawVarData { 267 class ResourceRawVarData : public RawVarData {
269 public: 268 public:
270 ResourceRawVarData(); 269 ResourceRawVarData();
271 ~ResourceRawVarData() override; 270 ~ResourceRawVarData() override;
272 271
273 // RawVarData implementation. 272 // RawVarData implementation.
274 PP_VarType Type() override; 273 PP_VarType Type() override;
275 bool Init(const PP_Var& var, PP_Instance instance) override; 274 bool Init(const PP_Var& var, PP_Instance instance) override;
276 PP_Var CreatePPVar(PP_Instance instance) override; 275 PP_Var CreatePPVar(PP_Instance instance) override;
277 void PopulatePPVar(const PP_Var& var, 276 void PopulatePPVar(const PP_Var& var,
278 const std::vector<PP_Var>& graph) override; 277 const std::vector<PP_Var>& graph) override;
279 void Write(IPC::Message* m, const HandleWriter& handle_writer) override; 278 void Write(base::Pickle* m, const HandleWriter& handle_writer) override;
280 bool Read(PP_VarType type, 279 bool Read(PP_VarType type,
281 const IPC::Message* m, 280 const base::Pickle* m,
282 base::PickleIterator* iter) override; 281 base::PickleIterator* iter) override;
283 282
284 private: 283 private:
285 // Resource ID in the plugin. If one has not yet been created, this is 0. 284 // Resource ID in the plugin. If one has not yet been created, this is 0.
286 // This is a borrowed reference; the resource's refcount is not incremented. 285 // This is a borrowed reference; the resource's refcount is not incremented.
287 PP_Resource pp_resource_; 286 PP_Resource pp_resource_;
288 287
289 // Pending resource host ID in the renderer. 288 // Pending resource host ID in the renderer.
290 int pending_renderer_host_id_; 289 int pending_renderer_host_id_;
291 290
292 // Pending resource host ID in the browser. 291 // Pending resource host ID in the browser.
293 int pending_browser_host_id_; 292 int pending_browser_host_id_;
294 293
295 // A message containing information about how to create a plugin-side 294 // A message containing information about how to create a plugin-side
296 // resource. The message type will vary based on the resource type, and will 295 // resource. The message type will vary based on the resource type, and will
297 // usually contain a pending resource host ID, and other required information. 296 // usually contain a pending resource host ID, and other required information.
298 // If the resource was created directly, this is NULL. 297 // If the resource was created directly, this is NULL.
299 scoped_ptr<IPC::Message> creation_message_; 298 scoped_ptr<IPC::Message> creation_message_;
300 }; 299 };
301 300
302 } // namespace proxy 301 } // namespace proxy
303 } // namespace ppapi 302 } // namespace ppapi
304 303
305 #endif // PPAPI_PROXY_RAW_VAR_DATA_H_ 304 #endif // PPAPI_PROXY_RAW_VAR_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698