blob: cf267a3466e50bc2992a559ac4fa8cad7dc2bf29 [file] [log] [blame]
Avi Drissmandb497b32022-09-15 19:47:281// Copyright 2012 The Chromium Authors
[email protected]c2932f5e2010-11-03 03:22:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/proxy/ppapi_param_traits.h"
6
avie029c4132015-12-23 06:45:227#include <stddef.h>
8#include <stdint.h>
[email protected]c2932f5e2010-11-03 03:22:339#include <string.h> // For memcpy
10
avie029c4132015-12-23 06:45:2211#include "build/build_config.h"
[email protected]799d1ab2010-11-09 17:16:2812#include "ppapi/c/pp_resource.h"
[email protected]799d1ab2010-11-09 17:16:2813#include "ppapi/proxy/ppapi_messages.h"
avie029c4132015-12-23 06:45:2214#include "ppapi/proxy/serialized_var.h"
[email protected]be0a84b2011-08-13 04:18:4415#include "ppapi/shared_impl/host_resource.h"
[email protected]de2895262012-04-04 17:15:4816#include "ppapi/shared_impl/private/ppb_x509_certificate_private_shared.h"
[email protected]c2932f5e2010-11-03 03:22:3317
18namespace IPC {
19
[email protected]1162a6a2011-04-21 17:28:1620namespace {
21
22// Deserializes a vector from IPC. This special version must be used instead
23// of the default IPC version when the vector contains a SerializedVar, either
24// directly or indirectly (i.e. a vector of objects that have a SerializedVar
25// inside them).
26//
27// The default vector deserializer does resize and then we deserialize into
28// those allocated slots. However, the implementation of vector (at least in
29// GCC's implementation), creates a new empty object using the default
30// constructor, and then sets the rest of the items to that empty one using the
31// copy constructor.
32//
33// Since we allocate the inner class when you call the default constructor and
34// transfer the inner class when you do operator=, the entire vector will end
35// up referring to the same inner class. Deserializing into this will just end
36// up overwriting the same item over and over, since all the SerializedVars
37// will refer to the same thing.
38//
39// The solution is to make a new object for each deserialized item, and then
40// add it to the vector one at a time.
brettwbd4d7112015-06-03 04:29:2541template <typename T>
rockot502c94f2016-02-03 20:20:1642bool ReadVectorWithoutCopy(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:2543 base::PickleIterator* iter,
[email protected]1162a6a2011-04-21 17:28:1644 std::vector<T>* output) {
45 // This part is just a copy of the the default ParamTraits vector Read().
Peter Kasting28b51cf2022-06-28 15:02:4346 size_t size;
avi48fc13b2014-12-28 23:31:4847 if (!iter->ReadLength(&size))
[email protected]1162a6a2011-04-21 17:28:1648 return false;
49 // Resizing beforehand is not safe, see BUG 1006367 for details.
Peter Kasting28b51cf2022-06-28 15:02:4350 if (size > INT_MAX / sizeof(T))
[email protected]1162a6a2011-04-21 17:28:1651 return false;
52
53 output->reserve(size);
Peter Kasting28b51cf2022-06-28 15:02:4354 for (size_t i = 0; i < size; i++) {
[email protected]1162a6a2011-04-21 17:28:1655 T cur;
56 if (!ReadParam(m, iter, &cur))
57 return false;
58 output->push_back(cur);
59 }
60 return true;
61}
62
63// This serializes the vector of items to the IPC message in exactly the same
64// way as the "regular" IPC vector serializer does. But having the code here
65// saves us from having to copy this code into all ParamTraits that use the
66// ReadVectorWithoutCopy function for deserializing.
rockot502c94f2016-02-03 20:20:1667template <typename T>
68void WriteVectorWithoutCopy(base::Pickle* m, const std::vector<T>& p) {
[email protected]1162a6a2011-04-21 17:28:1669 WriteParam(m, static_cast<int>(p.size()));
70 for (size_t i = 0; i < p.size(); i++)
71 WriteParam(m, p[i]);
72}
73
74} // namespace
75
[email protected]799d1ab2010-11-09 17:16:2876// PP_Bool ---------------------------------------------------------------------
77
78// static
rockot502c94f2016-02-03 20:20:1679void ParamTraits<PP_Bool>::Write(base::Pickle* m, const param_type& p) {
bbudge03071f12015-11-02 23:51:2080 WriteParam(m, PP_ToBool(p));
[email protected]799d1ab2010-11-09 17:16:2881}
82
83// static
rockot502c94f2016-02-03 20:20:1684bool ParamTraits<PP_Bool>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:2585 base::PickleIterator* iter,
[email protected]ce208f872012-03-07 20:42:5686 param_type* r) {
[email protected]799d1ab2010-11-09 17:16:2887 // We specifically want to be strict here about what types of input we accept,
88 // which ParamTraits<bool> does for us. We don't want to deserialize "2" into
89 // a PP_Bool, for example.
90 bool result = false;
bbudge03071f12015-11-02 23:51:2091 if (!ReadParam(m, iter, &result))
[email protected]799d1ab2010-11-09 17:16:2892 return false;
[email protected]8a855a02011-07-08 05:22:4593 *r = PP_FromBool(result);
[email protected]799d1ab2010-11-09 17:16:2894 return true;
95}
96
97// static
98void ParamTraits<PP_Bool>::Log(const param_type& p, std::string* l) {
99}
100
[email protected]5a2b68f2011-11-10 00:00:49101// PP_NetAddress_Private -------------------------------------------------------
[email protected]373a95a2011-07-01 16:58:14102
103// static
rockot502c94f2016-02-03 20:20:16104void ParamTraits<PP_NetAddress_Private>::Write(base::Pickle* m,
[email protected]5a2b68f2011-11-10 00:00:49105 const param_type& p) {
[email protected]373a95a2011-07-01 16:58:14106 WriteParam(m, p.size);
Peter Kasting28b51cf2022-06-28 15:02:43107 m->WriteBytes(p.data, p.size);
[email protected]373a95a2011-07-01 16:58:14108}
109
110// static
rockot502c94f2016-02-03 20:20:16111bool ParamTraits<PP_NetAddress_Private>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25112 base::PickleIterator* iter,
[email protected]5a2b68f2011-11-10 00:00:49113 param_type* p) {
avie029c4132015-12-23 06:45:22114 uint16_t size;
[email protected]373a95a2011-07-01 16:58:14115 if (!ReadParam(m, iter, &size))
116 return false;
117 if (size > sizeof(p->data))
118 return false;
119 p->size = size;
120
121 const char* data;
avi48fc13b2014-12-28 23:31:48122 if (!iter->ReadBytes(&data, size))
[email protected]373a95a2011-07-01 16:58:14123 return false;
124 memcpy(p->data, data, size);
125 return true;
126}
127
128// static
[email protected]5a2b68f2011-11-10 00:00:49129void ParamTraits<PP_NetAddress_Private>::Log(const param_type& p,
130 std::string* l) {
131 l->append("<PP_NetAddress_Private (");
[email protected]373a95a2011-07-01 16:58:14132 LogParam(p.size, l);
133 l->append(" bytes)>");
134}
135
[email protected]6761d632012-04-18 17:54:49136// HostResource ----------------------------------------------------------------
137
138// static
rockot502c94f2016-02-03 20:20:16139void ParamTraits<ppapi::HostResource>::Write(base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49140 const param_type& p) {
bbudge03071f12015-11-02 23:51:20141 WriteParam(m, p.instance());
142 WriteParam(m, p.host_resource());
[email protected]6761d632012-04-18 17:54:49143}
144
145// static
rockot502c94f2016-02-03 20:20:16146bool ParamTraits<ppapi::HostResource>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25147 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49148 param_type* r) {
149 PP_Instance instance;
150 PP_Resource resource;
bbudge03071f12015-11-02 23:51:20151 if (!ReadParam(m, iter, &instance) || !ReadParam(m, iter, &resource))
[email protected]6761d632012-04-18 17:54:49152 return false;
153 r->SetHostResource(instance, resource);
154 return true;
155}
156
157// static
158void ParamTraits<ppapi::HostResource>::Log(const param_type& p,
159 std::string* l) {
160}
161
162// SerializedVar ---------------------------------------------------------------
163
164// static
rockot502c94f2016-02-03 20:20:16165void ParamTraits<ppapi::proxy::SerializedVar>::Write(base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49166 const param_type& p) {
167 p.WriteToMessage(m);
168}
169
170// static
rockot502c94f2016-02-03 20:20:16171bool ParamTraits<ppapi::proxy::SerializedVar>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25172 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49173 param_type* r) {
174 return r->ReadFromMessage(m, iter);
175}
176
177// static
178void ParamTraits<ppapi::proxy::SerializedVar>::Log(const param_type& p,
179 std::string* l) {
180}
181
182// std::vector<SerializedVar> --------------------------------------------------
183
rockot502c94f2016-02-03 20:20:16184void ParamTraits<std::vector<ppapi::proxy::SerializedVar>>::Write(
185 base::Pickle* m,
[email protected]6761d632012-04-18 17:54:49186 const param_type& p) {
187 WriteVectorWithoutCopy(m, p);
188}
189
190// static
brettwbd4d7112015-06-03 04:29:25191bool ParamTraits<std::vector<ppapi::proxy::SerializedVar>>::Read(
rockot502c94f2016-02-03 20:20:16192 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25193 base::PickleIterator* iter,
[email protected]6761d632012-04-18 17:54:49194 param_type* r) {
195 return ReadVectorWithoutCopy(m, iter, r);
196}
197
198// static
199void ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Log(
200 const param_type& p,
201 std::string* l) {
202}
203
[email protected]195d4cde2012-10-02 18:12:41204// ppapi::PpapiPermissions -----------------------------------------------------
205
jam3db6b6d2016-05-13 15:09:58206// static
rockot502c94f2016-02-03 20:20:16207void ParamTraits<ppapi::PpapiPermissions>::Write(base::Pickle* m,
[email protected]195d4cde2012-10-02 18:12:41208 const param_type& p) {
bbudge03071f12015-11-02 23:51:20209 WriteParam(m, p.GetBits());
[email protected]195d4cde2012-10-02 18:12:41210}
211
212// static
rockot502c94f2016-02-03 20:20:16213bool ParamTraits<ppapi::PpapiPermissions>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25214 base::PickleIterator* iter,
[email protected]195d4cde2012-10-02 18:12:41215 param_type* r) {
216 uint32_t bits;
bbudge03071f12015-11-02 23:51:20217 if (!ReadParam(m, iter, &bits))
[email protected]195d4cde2012-10-02 18:12:41218 return false;
219 *r = ppapi::PpapiPermissions(bits);
220 return true;
221}
222
223// static
224void ParamTraits<ppapi::PpapiPermissions>::Log(const param_type& p,
225 std::string* l) {
226}
227
[email protected]246fc492012-08-27 20:28:18228// SerializedHandle ------------------------------------------------------------
229
230// static
rockot502c94f2016-02-03 20:20:16231void ParamTraits<ppapi::proxy::SerializedHandle>::Write(base::Pickle* m,
[email protected]246fc492012-08-27 20:28:18232 const param_type& p) {
233 ppapi::proxy::SerializedHandle::WriteHeader(p.header(), m);
234 switch (p.type()) {
Alexandr Ilinebab9da2018-06-01 02:37:47235 case ppapi::proxy::SerializedHandle::SHARED_MEMORY_REGION:
236 WriteParam(m, const_cast<param_type&>(p).TakeSharedMemoryRegion());
237 break;
[email protected]246fc492012-08-27 20:28:18238 case ppapi::proxy::SerializedHandle::SOCKET:
[email protected]0c92b0d2012-12-08 00:46:23239 case ppapi::proxy::SerializedHandle::FILE:
bbudge03071f12015-11-02 23:51:20240 WriteParam(m, p.descriptor());
[email protected]246fc492012-08-27 20:28:18241 break;
242 case ppapi::proxy::SerializedHandle::INVALID:
243 break;
244 // No default so the compiler will warn on new types.
245 }
246}
247
248// static
brettwbd4d7112015-06-03 04:29:25249bool ParamTraits<ppapi::proxy::SerializedHandle>::Read(
rockot502c94f2016-02-03 20:20:16250 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25251 base::PickleIterator* iter,
252 param_type* r) {
[email protected]246fc492012-08-27 20:28:18253 ppapi::proxy::SerializedHandle::Header header;
254 if (!ppapi::proxy::SerializedHandle::ReadHeader(iter, &header))
255 return false;
256 switch (header.type) {
Alexandr Ilinebab9da2018-06-01 02:37:47257 case ppapi::proxy::SerializedHandle::SHARED_MEMORY_REGION: {
258 base::subtle::PlatformSharedMemoryRegion region;
259 if (!ReadParam(m, iter, &region))
260 return false;
261 r->set_shmem_region(std::move(region));
[email protected]246fc492012-08-27 20:28:18262 break;
263 }
264 case ppapi::proxy::SerializedHandle::SOCKET: {
265 IPC::PlatformFileForTransit socket;
Alexandr Ilinebab9da2018-06-01 02:37:47266 if (!ReadParam(m, iter, &socket))
267 return false;
268 r->set_socket(socket);
[email protected]246fc492012-08-27 20:28:18269 break;
270 }
[email protected]0c92b0d2012-12-08 00:46:23271 case ppapi::proxy::SerializedHandle::FILE: {
272 IPC::PlatformFileForTransit desc;
Alexandr Ilinebab9da2018-06-01 02:37:47273 if (!ReadParam(m, iter, &desc))
274 return false;
275 r->set_file_handle(desc, header.open_flags, header.file_io);
[email protected]0c92b0d2012-12-08 00:46:23276 break;
277 }
[email protected]246fc492012-08-27 20:28:18278 case ppapi::proxy::SerializedHandle::INVALID:
Alexandr Ilinebab9da2018-06-01 02:37:47279 break;
280 // No default so the compiler will warn us if a new type is added.
[email protected]246fc492012-08-27 20:28:18281 }
Alexandr Ilinebab9da2018-06-01 02:37:47282 return true;
[email protected]246fc492012-08-27 20:28:18283}
284
285// static
286void ParamTraits<ppapi::proxy::SerializedHandle>::Log(const param_type& p,
287 std::string* l) {
288}
289
[email protected]5a5d9b5322012-10-02 22:20:23290// PPBURLLoader_UpdateProgress_Params ------------------------------------------
291
292// static
293void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Write(
rockot502c94f2016-02-03 20:20:16294 base::Pickle* m,
[email protected]5a5d9b5322012-10-02 22:20:23295 const param_type& p) {
bbudge03071f12015-11-02 23:51:20296 WriteParam(m, p.instance);
297 WriteParam(m, p.resource);
298 WriteParam(m, p.bytes_sent);
299 WriteParam(m, p.total_bytes_to_be_sent);
300 WriteParam(m, p.bytes_received);
301 WriteParam(m, p.total_bytes_to_be_received);
[email protected]5a5d9b5322012-10-02 22:20:23302}
303
304// static
305bool ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Read(
rockot502c94f2016-02-03 20:20:16306 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25307 base::PickleIterator* iter,
[email protected]5a5d9b5322012-10-02 22:20:23308 param_type* r) {
bbudge03071f12015-11-02 23:51:20309 return ReadParam(m, iter, &r->instance) && ReadParam(m, iter, &r->resource) &&
310 ReadParam(m, iter, &r->bytes_sent) &&
311 ReadParam(m, iter, &r->total_bytes_to_be_sent) &&
312 ReadParam(m, iter, &r->bytes_received) &&
313 ReadParam(m, iter, &r->total_bytes_to_be_received);
[email protected]5a5d9b5322012-10-02 22:20:23314}
315
316// static
317void ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Log(
318 const param_type& p,
319 std::string* l) {
320}
321
Xiaohan Wang0fd6e56a2022-01-13 20:26:11322#if !BUILDFLAG(IS_NACL) && !defined(NACL_WIN64)
[email protected]43a40202010-11-12 16:25:01323// SerializedDirEntry ----------------------------------------------------------
324
325// static
rockot502c94f2016-02-03 20:20:16326void ParamTraits<ppapi::proxy::SerializedDirEntry>::Write(base::Pickle* m,
[email protected]4d2efd22011-08-18 21:58:02327 const param_type& p) {
bbudge03071f12015-11-02 23:51:20328 WriteParam(m, p.name);
329 WriteParam(m, p.is_dir);
[email protected]43a40202010-11-12 16:25:01330}
331
332// static
brettwbd4d7112015-06-03 04:29:25333bool ParamTraits<ppapi::proxy::SerializedDirEntry>::Read(
rockot502c94f2016-02-03 20:20:16334 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25335 base::PickleIterator* iter,
336 param_type* r) {
bbudge03071f12015-11-02 23:51:20337 return ReadParam(m, iter, &r->name) && ReadParam(m, iter, &r->is_dir);
[email protected]43a40202010-11-12 16:25:01338}
339
340// static
[email protected]4d2efd22011-08-18 21:58:02341void ParamTraits<ppapi::proxy::SerializedDirEntry>::Log(const param_type& p,
342 std::string* l) {
[email protected]43a40202010-11-12 16:25:01343}
344
[email protected]4d2efd22011-08-18 21:58:02345// ppapi::proxy::SerializedFontDescription -------------------------------------
[email protected]799d1ab2010-11-09 17:16:28346
347// static
[email protected]4d2efd22011-08-18 21:58:02348void ParamTraits<ppapi::proxy::SerializedFontDescription>::Write(
rockot502c94f2016-02-03 20:20:16349 base::Pickle* m,
[email protected]799d1ab2010-11-09 17:16:28350 const param_type& p) {
bbudge03071f12015-11-02 23:51:20351 WriteParam(m, p.face);
352 WriteParam(m, p.family);
353 WriteParam(m, p.size);
354 WriteParam(m, p.weight);
355 WriteParam(m, p.italic);
356 WriteParam(m, p.small_caps);
357 WriteParam(m, p.letter_spacing);
358 WriteParam(m, p.word_spacing);
[email protected]799d1ab2010-11-09 17:16:28359}
360
361// static
[email protected]4d2efd22011-08-18 21:58:02362bool ParamTraits<ppapi::proxy::SerializedFontDescription>::Read(
rockot502c94f2016-02-03 20:20:16363 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25364 base::PickleIterator* iter,
[email protected]799d1ab2010-11-09 17:16:28365 param_type* r) {
bbudge03071f12015-11-02 23:51:20366 return ReadParam(m, iter, &r->face) && ReadParam(m, iter, &r->family) &&
367 ReadParam(m, iter, &r->size) && ReadParam(m, iter, &r->weight) &&
368 ReadParam(m, iter, &r->italic) && ReadParam(m, iter, &r->small_caps) &&
369 ReadParam(m, iter, &r->letter_spacing) &&
370 ReadParam(m, iter, &r->word_spacing);
[email protected]799d1ab2010-11-09 17:16:28371}
372
373// static
[email protected]4d2efd22011-08-18 21:58:02374void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log(
[email protected]799d1ab2010-11-09 17:16:28375 const param_type& p,
376 std::string* l) {
377}
Xiaohan Wang0fd6e56a2022-01-13 20:26:11378#endif // !BUILDFLAG(IS_NACL) && !defined(NACL_WIN64)
[email protected]799d1ab2010-11-09 17:16:28379
Xiaohan Wang0fd6e56a2022-01-13 20:26:11380#if !BUILDFLAG(IS_NACL) && !defined(NACL_WIN64)
[email protected]0c92b0d2012-12-08 00:46:23381// ppapi::PepperFilePath -------------------------------------------------------
382
383// static
rockot502c94f2016-02-03 20:20:16384void ParamTraits<ppapi::PepperFilePath>::Write(base::Pickle* m,
[email protected]0c92b0d2012-12-08 00:46:23385 const param_type& p) {
386 WriteParam(m, static_cast<unsigned>(p.domain()));
387 WriteParam(m, p.path());
388}
389
390// static
rockot502c94f2016-02-03 20:20:16391bool ParamTraits<ppapi::PepperFilePath>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25392 base::PickleIterator* iter,
[email protected]0c92b0d2012-12-08 00:46:23393 param_type* p) {
394 unsigned domain;
[email protected]d30a36f2013-02-07 04:16:26395 base::FilePath path;
[email protected]0c92b0d2012-12-08 00:46:23396 if (!ReadParam(m, iter, &domain) || !ReadParam(m, iter, &path))
397 return false;
398 if (domain > ppapi::PepperFilePath::DOMAIN_MAX_VALID)
399 return false;
400
401 *p = ppapi::PepperFilePath(
402 static_cast<ppapi::PepperFilePath::Domain>(domain), path);
403 return true;
404}
405
406// static
407void ParamTraits<ppapi::PepperFilePath>::Log(const param_type& p,
408 std::string* l) {
409 l->append("(");
410 LogParam(static_cast<unsigned>(p.domain()), l);
411 l->append(", ");
412 LogParam(p.path(), l);
413 l->append(")");
414}
415
Xiaohan Wang0fd6e56a2022-01-13 20:26:11416#endif // !BUILDFLAG(IS_NACL) && !defined(NACL_WIN64)
[email protected]7358d572011-02-15 18:44:40417
[email protected]de2895262012-04-04 17:15:48418// PPB_X509Certificate_Fields --------------------------------------------------
419
420// static
421void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Write(
rockot502c94f2016-02-03 20:20:16422 base::Pickle* m,
[email protected]de2895262012-04-04 17:15:48423 const param_type& p) {
bbudge03071f12015-11-02 23:51:20424 WriteParam(m, p.values_);
[email protected]de2895262012-04-04 17:15:48425}
426
427// static
brettwbd4d7112015-06-03 04:29:25428bool ParamTraits<ppapi::PPB_X509Certificate_Fields>::Read(
rockot502c94f2016-02-03 20:20:16429 const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25430 base::PickleIterator* iter,
431 param_type* r) {
bbudge03071f12015-11-02 23:51:20432 return ReadParam(m, iter, &(r->values_));
[email protected]de2895262012-04-04 17:15:48433}
434
435// static
436void ParamTraits<ppapi::PPB_X509Certificate_Fields>::Log(const param_type& p,
437 std::string* l) {
438}
439
[email protected]64a61fc2013-06-19 13:30:59440// ppapi::SocketOptionData -----------------------------------------------------
441
442// static
rockot502c94f2016-02-03 20:20:16443void ParamTraits<ppapi::SocketOptionData>::Write(base::Pickle* m,
[email protected]64a61fc2013-06-19 13:30:59444 const param_type& p) {
445 ppapi::SocketOptionData::Type type = p.GetType();
bbudge03071f12015-11-02 23:51:20446 WriteParam(m, static_cast<int32_t>(type));
[email protected]64a61fc2013-06-19 13:30:59447 switch (type) {
448 case ppapi::SocketOptionData::TYPE_INVALID: {
449 break;
450 }
451 case ppapi::SocketOptionData::TYPE_BOOL: {
452 bool out_value = false;
453 bool result = p.GetBool(&out_value);
454 // Suppress unused variable warnings.
455 static_cast<void>(result);
456 DCHECK(result);
457
bbudge03071f12015-11-02 23:51:20458 WriteParam(m, out_value);
[email protected]64a61fc2013-06-19 13:30:59459 break;
460 }
461 case ppapi::SocketOptionData::TYPE_INT32: {
462 int32_t out_value = 0;
463 bool result = p.GetInt32(&out_value);
464 // Suppress unused variable warnings.
465 static_cast<void>(result);
466 DCHECK(result);
467
bbudge03071f12015-11-02 23:51:20468 WriteParam(m, out_value);
[email protected]64a61fc2013-06-19 13:30:59469 break;
470 }
471 // No default so the compiler will warn on new types.
472 }
473}
474
475// static
rockot502c94f2016-02-03 20:20:16476bool ParamTraits<ppapi::SocketOptionData>::Read(const base::Pickle* m,
brettwbd4d7112015-06-03 04:29:25477 base::PickleIterator* iter,
[email protected]64a61fc2013-06-19 13:30:59478 param_type* r) {
479 *r = ppapi::SocketOptionData();
480 int32_t type = 0;
bbudge03071f12015-11-02 23:51:20481 if (!ReadParam(m, iter, &type))
[email protected]64a61fc2013-06-19 13:30:59482 return false;
483 if (type != ppapi::SocketOptionData::TYPE_INVALID &&
484 type != ppapi::SocketOptionData::TYPE_BOOL &&
485 type != ppapi::SocketOptionData::TYPE_INT32) {
486 return false;
487 }
488 switch (static_cast<ppapi::SocketOptionData::Type>(type)) {
489 case ppapi::SocketOptionData::TYPE_INVALID: {
490 return true;
491 }
492 case ppapi::SocketOptionData::TYPE_BOOL: {
493 bool value = false;
bbudge03071f12015-11-02 23:51:20494 if (!ReadParam(m, iter, &value))
[email protected]64a61fc2013-06-19 13:30:59495 return false;
496 r->SetBool(value);
497 return true;
498 }
499 case ppapi::SocketOptionData::TYPE_INT32: {
500 int32_t value = 0;
bbudge03071f12015-11-02 23:51:20501 if (!ReadParam(m, iter, &value))
[email protected]64a61fc2013-06-19 13:30:59502 return false;
503 r->SetInt32(value);
504 return true;
505 }
506 // No default so the compiler will warn on new types.
507 }
508 return false;
509}
510
511// static
512void ParamTraits<ppapi::SocketOptionData>::Log(const param_type& p,
513 std::string* l) {
514}
515
[email protected]c2932f5e2010-11-03 03:22:33516} // namespace IPC