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 #include "ipc/ipc_message_utils.h" | 5 #include "ipc/ipc_message_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 base::StringPrintf("[%02X]", static_cast<unsigned char>(data[i]))); | 60 base::StringPrintf("[%02X]", static_cast<unsigned char>(data[i]))); |
61 } | 61 } |
62 if (data.size() > kMaxBytesToLog) { | 62 if (data.size() > kMaxBytesToLog) { |
63 out->append(base::StringPrintf( | 63 out->append(base::StringPrintf( |
64 " and %u more bytes", | 64 " and %u more bytes", |
65 static_cast<unsigned>(data.size() - kMaxBytesToLog))); | 65 static_cast<unsigned>(data.size() - kMaxBytesToLog))); |
66 } | 66 } |
67 #endif | 67 #endif |
68 } | 68 } |
69 | 69 |
70 bool ReadValue(const Message* m, | 70 bool ReadValue(const base::Pickle* m, |
71 base::PickleIterator* iter, | 71 base::PickleIterator* iter, |
72 base::Value** value, | 72 base::Value** value, |
73 int recursion); | 73 int recursion); |
74 | 74 |
75 void WriteValue(Message* m, const base::Value* value, int recursion) { | 75 void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { |
76 bool result; | 76 bool result; |
77 if (recursion > kMaxRecursionDepth) { | 77 if (recursion > kMaxRecursionDepth) { |
78 LOG(WARNING) << "Max recursion depth hit in WriteValue."; | 78 LOG(WARNING) << "Max recursion depth hit in WriteValue."; |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 m->WriteInt(value->GetType()); | 82 m->WriteInt(value->GetType()); |
83 | 83 |
84 switch (value->GetType()) { | 84 switch (value->GetType()) { |
85 case base::Value::TYPE_NULL: | 85 case base::Value::TYPE_NULL: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 it != list->end(); ++it) { | 138 it != list->end(); ++it) { |
139 WriteValue(m, *it, recursion + 1); | 139 WriteValue(m, *it, recursion + 1); |
140 } | 140 } |
141 break; | 141 break; |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 // Helper for ReadValue that reads a DictionaryValue into a pre-allocated | 146 // Helper for ReadValue that reads a DictionaryValue into a pre-allocated |
147 // object. | 147 // object. |
148 bool ReadDictionaryValue(const Message* m, | 148 bool ReadDictionaryValue(const base::Pickle* m, |
149 base::PickleIterator* iter, | 149 base::PickleIterator* iter, |
150 base::DictionaryValue* value, | 150 base::DictionaryValue* value, |
151 int recursion) { | 151 int recursion) { |
152 int size; | 152 int size; |
153 if (!ReadParam(m, iter, &size)) | 153 if (!ReadParam(m, iter, &size)) |
154 return false; | 154 return false; |
155 | 155 |
156 for (int i = 0; i < size; ++i) { | 156 for (int i = 0; i < size; ++i) { |
157 std::string key; | 157 std::string key; |
158 base::Value* subval; | 158 base::Value* subval; |
159 if (!ReadParam(m, iter, &key) || | 159 if (!ReadParam(m, iter, &key) || |
160 !ReadValue(m, iter, &subval, recursion + 1)) | 160 !ReadValue(m, iter, &subval, recursion + 1)) |
161 return false; | 161 return false; |
162 value->SetWithoutPathExpansion(key, subval); | 162 value->SetWithoutPathExpansion(key, subval); |
163 } | 163 } |
164 | 164 |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 // Helper for ReadValue that reads a ReadListValue into a pre-allocated | 168 // Helper for ReadValue that reads a ReadListValue into a pre-allocated |
169 // object. | 169 // object. |
170 bool ReadListValue(const Message* m, | 170 bool ReadListValue(const base::Pickle* m, |
171 base::PickleIterator* iter, | 171 base::PickleIterator* iter, |
172 base::ListValue* value, | 172 base::ListValue* value, |
173 int recursion) { | 173 int recursion) { |
174 int size; | 174 int size; |
175 if (!ReadParam(m, iter, &size)) | 175 if (!ReadParam(m, iter, &size)) |
176 return false; | 176 return false; |
177 | 177 |
178 for (int i = 0; i < size; ++i) { | 178 for (int i = 0; i < size; ++i) { |
179 base::Value* subval; | 179 base::Value* subval; |
180 if (!ReadValue(m, iter, &subval, recursion + 1)) | 180 if (!ReadValue(m, iter, &subval, recursion + 1)) |
181 return false; | 181 return false; |
182 value->Set(i, subval); | 182 value->Set(i, subval); |
183 } | 183 } |
184 | 184 |
185 return true; | 185 return true; |
186 } | 186 } |
187 | 187 |
188 bool ReadValue(const Message* m, | 188 bool ReadValue(const base::Pickle* m, |
189 base::PickleIterator* iter, | 189 base::PickleIterator* iter, |
190 base::Value** value, | 190 base::Value** value, |
191 int recursion) { | 191 int recursion) { |
192 if (recursion > kMaxRecursionDepth) { | 192 if (recursion > kMaxRecursionDepth) { |
193 LOG(WARNING) << "Max recursion depth hit in ReadValue."; | 193 LOG(WARNING) << "Max recursion depth hit in ReadValue."; |
194 return false; | 194 return false; |
195 } | 195 } |
196 | 196 |
197 int type; | 197 int type; |
198 if (!ReadParam(m, iter, &type)) | 198 if (!ReadParam(m, iter, &type)) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 dispatch(0) { | 271 dispatch(0) { |
272 } | 272 } |
273 | 273 |
274 LogData::~LogData() { | 274 LogData::~LogData() { |
275 } | 275 } |
276 | 276 |
277 void ParamTraits<bool>::Log(const param_type& p, std::string* l) { | 277 void ParamTraits<bool>::Log(const param_type& p, std::string* l) { |
278 l->append(p ? "true" : "false"); | 278 l->append(p ? "true" : "false"); |
279 } | 279 } |
280 | 280 |
281 void ParamTraits<signed char>::Write(Message* m, const param_type& p) { | 281 void ParamTraits<signed char>::Write(base::Pickle* m, const param_type& p) { |
282 m->WriteBytes(&p, sizeof(param_type)); | 282 m->WriteBytes(&p, sizeof(param_type)); |
283 } | 283 } |
284 | 284 |
285 bool ParamTraits<signed char>::Read(const Message* m, | 285 bool ParamTraits<signed char>::Read(const base::Pickle* m, |
286 base::PickleIterator* iter, | 286 base::PickleIterator* iter, |
287 param_type* r) { | 287 param_type* r) { |
288 const char* data; | 288 const char* data; |
289 if (!iter->ReadBytes(&data, sizeof(param_type))) | 289 if (!iter->ReadBytes(&data, sizeof(param_type))) |
290 return false; | 290 return false; |
291 memcpy(r, data, sizeof(param_type)); | 291 memcpy(r, data, sizeof(param_type)); |
292 return true; | 292 return true; |
293 } | 293 } |
294 | 294 |
295 void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { | 295 void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { |
296 l->append(base::IntToString(p)); | 296 l->append(base::IntToString(p)); |
297 } | 297 } |
298 | 298 |
299 void ParamTraits<unsigned char>::Write(Message* m, const param_type& p) { | 299 void ParamTraits<unsigned char>::Write(base::Pickle* m, const param_type& p) { |
300 m->WriteBytes(&p, sizeof(param_type)); | 300 m->WriteBytes(&p, sizeof(param_type)); |
301 } | 301 } |
302 | 302 |
303 bool ParamTraits<unsigned char>::Read(const Message* m, | 303 bool ParamTraits<unsigned char>::Read(const base::Pickle* m, |
304 base::PickleIterator* iter, | 304 base::PickleIterator* iter, |
305 param_type* r) { | 305 param_type* r) { |
306 const char* data; | 306 const char* data; |
307 if (!iter->ReadBytes(&data, sizeof(param_type))) | 307 if (!iter->ReadBytes(&data, sizeof(param_type))) |
308 return false; | 308 return false; |
309 memcpy(r, data, sizeof(param_type)); | 309 memcpy(r, data, sizeof(param_type)); |
310 return true; | 310 return true; |
311 } | 311 } |
312 | 312 |
313 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { | 313 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { |
314 l->append(base::UintToString(p)); | 314 l->append(base::UintToString(p)); |
315 } | 315 } |
316 | 316 |
317 void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) { | 317 void ParamTraits<unsigned short>::Write(base::Pickle* m, const param_type& p) { |
318 m->WriteBytes(&p, sizeof(param_type)); | 318 m->WriteBytes(&p, sizeof(param_type)); |
319 } | 319 } |
320 | 320 |
321 bool ParamTraits<unsigned short>::Read(const Message* m, | 321 bool ParamTraits<unsigned short>::Read(const base::Pickle* m, |
322 base::PickleIterator* iter, | 322 base::PickleIterator* iter, |
323 param_type* r) { | 323 param_type* r) { |
324 const char* data; | 324 const char* data; |
325 if (!iter->ReadBytes(&data, sizeof(param_type))) | 325 if (!iter->ReadBytes(&data, sizeof(param_type))) |
326 return false; | 326 return false; |
327 memcpy(r, data, sizeof(param_type)); | 327 memcpy(r, data, sizeof(param_type)); |
328 return true; | 328 return true; |
329 } | 329 } |
330 | 330 |
331 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { | 331 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { |
(...skipping 21 matching lines...) Expand all Loading... |
353 } | 353 } |
354 | 354 |
355 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { | 355 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { |
356 l->append(base::Uint64ToString(p)); | 356 l->append(base::Uint64ToString(p)); |
357 } | 357 } |
358 | 358 |
359 void ParamTraits<float>::Log(const param_type& p, std::string* l) { | 359 void ParamTraits<float>::Log(const param_type& p, std::string* l) { |
360 l->append(base::StringPrintf("%e", p)); | 360 l->append(base::StringPrintf("%e", p)); |
361 } | 361 } |
362 | 362 |
363 void ParamTraits<double>::Write(Message* m, const param_type& p) { | 363 void ParamTraits<double>::Write(base::Pickle* m, const param_type& p) { |
364 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); | 364 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); |
365 } | 365 } |
366 | 366 |
367 bool ParamTraits<double>::Read(const Message* m, | 367 bool ParamTraits<double>::Read(const base::Pickle* m, |
368 base::PickleIterator* iter, | 368 base::PickleIterator* iter, |
369 param_type* r) { | 369 param_type* r) { |
370 const char *data; | 370 const char *data; |
371 if (!iter->ReadBytes(&data, sizeof(*r))) { | 371 if (!iter->ReadBytes(&data, sizeof(*r))) { |
372 NOTREACHED(); | 372 NOTREACHED(); |
373 return false; | 373 return false; |
374 } | 374 } |
375 memcpy(r, data, sizeof(param_type)); | 375 memcpy(r, data, sizeof(param_type)); |
376 return true; | 376 return true; |
377 } | 377 } |
378 | 378 |
379 void ParamTraits<double>::Log(const param_type& p, std::string* l) { | 379 void ParamTraits<double>::Log(const param_type& p, std::string* l) { |
380 l->append(base::StringPrintf("%e", p)); | 380 l->append(base::StringPrintf("%e", p)); |
381 } | 381 } |
382 | 382 |
383 | 383 |
384 void ParamTraits<std::string>::Log(const param_type& p, std::string* l) { | 384 void ParamTraits<std::string>::Log(const param_type& p, std::string* l) { |
385 l->append(p); | 385 l->append(p); |
386 } | 386 } |
387 | 387 |
388 void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { | 388 void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { |
389 l->append(base::UTF16ToUTF8(p)); | 389 l->append(base::UTF16ToUTF8(p)); |
390 } | 390 } |
391 | 391 |
392 void ParamTraits<std::vector<char> >::Write(Message* m, const param_type& p) { | 392 void ParamTraits<std::vector<char>>::Write(base::Pickle* m, |
| 393 const param_type& p) { |
393 if (p.empty()) { | 394 if (p.empty()) { |
394 m->WriteData(NULL, 0); | 395 m->WriteData(NULL, 0); |
395 } else { | 396 } else { |
396 m->WriteData(&p.front(), static_cast<int>(p.size())); | 397 m->WriteData(&p.front(), static_cast<int>(p.size())); |
397 } | 398 } |
398 } | 399 } |
399 | 400 |
400 bool ParamTraits<std::vector<char>>::Read(const Message* m, | 401 bool ParamTraits<std::vector<char>>::Read(const base::Pickle* m, |
401 base::PickleIterator* iter, | 402 base::PickleIterator* iter, |
402 param_type* r) { | 403 param_type* r) { |
403 const char *data; | 404 const char *data; |
404 int data_size = 0; | 405 int data_size = 0; |
405 if (!iter->ReadData(&data, &data_size) || data_size < 0) | 406 if (!iter->ReadData(&data, &data_size) || data_size < 0) |
406 return false; | 407 return false; |
407 r->resize(data_size); | 408 r->resize(data_size); |
408 if (data_size) | 409 if (data_size) |
409 memcpy(&r->front(), data, data_size); | 410 memcpy(&r->front(), data, data_size); |
410 return true; | 411 return true; |
411 } | 412 } |
412 | 413 |
413 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { | 414 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { |
414 LogBytes(p, l); | 415 LogBytes(p, l); |
415 } | 416 } |
416 | 417 |
417 void ParamTraits<std::vector<unsigned char> >::Write(Message* m, | 418 void ParamTraits<std::vector<unsigned char>>::Write(base::Pickle* m, |
418 const param_type& p) { | 419 const param_type& p) { |
419 if (p.empty()) { | 420 if (p.empty()) { |
420 m->WriteData(NULL, 0); | 421 m->WriteData(NULL, 0); |
421 } else { | 422 } else { |
422 m->WriteData(reinterpret_cast<const char*>(&p.front()), | 423 m->WriteData(reinterpret_cast<const char*>(&p.front()), |
423 static_cast<int>(p.size())); | 424 static_cast<int>(p.size())); |
424 } | 425 } |
425 } | 426 } |
426 | 427 |
427 bool ParamTraits<std::vector<unsigned char>>::Read(const Message* m, | 428 bool ParamTraits<std::vector<unsigned char>>::Read(const base::Pickle* m, |
428 base::PickleIterator* iter, | 429 base::PickleIterator* iter, |
429 param_type* r) { | 430 param_type* r) { |
430 const char *data; | 431 const char *data; |
431 int data_size = 0; | 432 int data_size = 0; |
432 if (!iter->ReadData(&data, &data_size) || data_size < 0) | 433 if (!iter->ReadData(&data, &data_size) || data_size < 0) |
433 return false; | 434 return false; |
434 r->resize(data_size); | 435 r->resize(data_size); |
435 if (data_size) | 436 if (data_size) |
436 memcpy(&r->front(), data, data_size); | 437 memcpy(&r->front(), data, data_size); |
437 return true; | 438 return true; |
438 } | 439 } |
439 | 440 |
440 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, | 441 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, |
441 std::string* l) { | 442 std::string* l) { |
442 LogBytes(p, l); | 443 LogBytes(p, l); |
443 } | 444 } |
444 | 445 |
445 void ParamTraits<std::vector<bool> >::Write(Message* m, const param_type& p) { | 446 void ParamTraits<std::vector<bool>>::Write(base::Pickle* m, |
| 447 const param_type& p) { |
446 WriteParam(m, static_cast<int>(p.size())); | 448 WriteParam(m, static_cast<int>(p.size())); |
447 // Cast to bool below is required because libc++'s | 449 // Cast to bool below is required because libc++'s |
448 // vector<bool>::const_reference is different from bool, and we want to avoid | 450 // vector<bool>::const_reference is different from bool, and we want to avoid |
449 // writing an extra specialization of ParamTraits for it. | 451 // writing an extra specialization of ParamTraits for it. |
450 for (size_t i = 0; i < p.size(); i++) | 452 for (size_t i = 0; i < p.size(); i++) |
451 WriteParam(m, static_cast<bool>(p[i])); | 453 WriteParam(m, static_cast<bool>(p[i])); |
452 } | 454 } |
453 | 455 |
454 bool ParamTraits<std::vector<bool>>::Read(const Message* m, | 456 bool ParamTraits<std::vector<bool>>::Read(const base::Pickle* m, |
455 base::PickleIterator* iter, | 457 base::PickleIterator* iter, |
456 param_type* r) { | 458 param_type* r) { |
457 int size; | 459 int size; |
458 // ReadLength() checks for < 0 itself. | 460 // ReadLength() checks for < 0 itself. |
459 if (!iter->ReadLength(&size)) | 461 if (!iter->ReadLength(&size)) |
460 return false; | 462 return false; |
461 r->resize(size); | 463 r->resize(size); |
462 for (int i = 0; i < size; i++) { | 464 for (int i = 0; i < size; i++) { |
463 bool value; | 465 bool value; |
464 if (!ReadParam(m, iter, &value)) | 466 if (!ReadParam(m, iter, &value)) |
465 return false; | 467 return false; |
466 (*r)[i] = value; | 468 (*r)[i] = value; |
467 } | 469 } |
468 return true; | 470 return true; |
469 } | 471 } |
470 | 472 |
471 void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) { | 473 void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) { |
472 for (size_t i = 0; i < p.size(); ++i) { | 474 for (size_t i = 0; i < p.size(); ++i) { |
473 if (i != 0) | 475 if (i != 0) |
474 l->push_back(' '); | 476 l->push_back(' '); |
475 LogParam(static_cast<bool>(p[i]), l); | 477 LogParam(static_cast<bool>(p[i]), l); |
476 } | 478 } |
477 } | 479 } |
478 | 480 |
479 void ParamTraits<BrokerableAttachment::AttachmentId>::Write( | 481 void ParamTraits<BrokerableAttachment::AttachmentId>::Write( |
480 Message* m, | 482 base::Pickle* m, |
481 const param_type& p) { | 483 const param_type& p) { |
482 m->WriteBytes(p.nonce, BrokerableAttachment::kNonceSize); | 484 m->WriteBytes(p.nonce, BrokerableAttachment::kNonceSize); |
483 } | 485 } |
484 | 486 |
485 bool ParamTraits<BrokerableAttachment::AttachmentId>::Read( | 487 bool ParamTraits<BrokerableAttachment::AttachmentId>::Read( |
486 const Message* m, | 488 const base::Pickle* m, |
487 base::PickleIterator* iter, | 489 base::PickleIterator* iter, |
488 param_type* r) { | 490 param_type* r) { |
489 const char* data; | 491 const char* data; |
490 if (!iter->ReadBytes(&data, BrokerableAttachment::kNonceSize)) | 492 if (!iter->ReadBytes(&data, BrokerableAttachment::kNonceSize)) |
491 return false; | 493 return false; |
492 memcpy(r->nonce, data, BrokerableAttachment::kNonceSize); | 494 memcpy(r->nonce, data, BrokerableAttachment::kNonceSize); |
493 return true; | 495 return true; |
494 } | 496 } |
495 | 497 |
496 void ParamTraits<BrokerableAttachment::AttachmentId>::Log(const param_type& p, | 498 void ParamTraits<BrokerableAttachment::AttachmentId>::Log(const param_type& p, |
497 std::string* l) { | 499 std::string* l) { |
498 l->append(base::HexEncode(p.nonce, BrokerableAttachment::kNonceSize)); | 500 l->append(base::HexEncode(p.nonce, BrokerableAttachment::kNonceSize)); |
499 } | 501 } |
500 | 502 |
501 void ParamTraits<base::DictionaryValue>::Write(Message* m, | 503 void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m, |
502 const param_type& p) { | 504 const param_type& p) { |
503 WriteValue(m, &p, 0); | 505 WriteValue(m, &p, 0); |
504 } | 506 } |
505 | 507 |
506 bool ParamTraits<base::DictionaryValue>::Read(const Message* m, | 508 bool ParamTraits<base::DictionaryValue>::Read(const base::Pickle* m, |
507 base::PickleIterator* iter, | 509 base::PickleIterator* iter, |
508 param_type* r) { | 510 param_type* r) { |
509 int type; | 511 int type; |
510 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) | 512 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) |
511 return false; | 513 return false; |
512 | 514 |
513 return ReadDictionaryValue(m, iter, r, 0); | 515 return ReadDictionaryValue(m, iter, r, 0); |
514 } | 516 } |
515 | 517 |
516 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, | 518 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, |
517 std::string* l) { | 519 std::string* l) { |
518 std::string json; | 520 std::string json; |
519 base::JSONWriter::Write(p, &json); | 521 base::JSONWriter::Write(p, &json); |
520 l->append(json); | 522 l->append(json); |
521 } | 523 } |
522 | 524 |
523 #if defined(OS_POSIX) | 525 #if defined(OS_POSIX) |
524 void ParamTraits<base::FileDescriptor>::Write(Message* m, const param_type& p) { | 526 void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m, |
| 527 const param_type& p) { |
525 const bool valid = p.fd >= 0; | 528 const bool valid = p.fd >= 0; |
526 WriteParam(m, valid); | 529 WriteParam(m, valid); |
527 | 530 |
528 if (!valid) | 531 if (!valid) |
529 return; | 532 return; |
530 | 533 |
531 if (p.auto_close) { | 534 if (p.auto_close) { |
532 if (!m->WriteAttachment( | 535 if (!m->WriteAttachment( |
533 new internal::PlatformFileAttachment(base::ScopedFD(p.fd)))) | 536 new internal::PlatformFileAttachment(base::ScopedFD(p.fd)))) |
534 NOTREACHED(); | 537 NOTREACHED(); |
535 } else { | 538 } else { |
536 if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd))) | 539 if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd))) |
537 NOTREACHED(); | 540 NOTREACHED(); |
538 } | 541 } |
539 } | 542 } |
540 | 543 |
541 bool ParamTraits<base::FileDescriptor>::Read(const Message* m, | 544 bool ParamTraits<base::FileDescriptor>::Read(const base::Pickle* m, |
542 base::PickleIterator* iter, | 545 base::PickleIterator* iter, |
543 param_type* r) { | 546 param_type* r) { |
544 *r = base::FileDescriptor(); | 547 *r = base::FileDescriptor(); |
545 | 548 |
546 bool valid; | 549 bool valid; |
547 if (!ReadParam(m, iter, &valid)) | 550 if (!ReadParam(m, iter, &valid)) |
548 return false; | 551 return false; |
549 | 552 |
550 // TODO(morrita): Seems like this should return false. | 553 // TODO(morrita): Seems like this should return false. |
551 if (!valid) | 554 if (!valid) |
552 return true; | 555 return true; |
553 | 556 |
554 scoped_refptr<MessageAttachment> attachment; | 557 scoped_refptr<base::Pickle::Attachment> attachment; |
555 if (!m->ReadAttachment(iter, &attachment)) | 558 if (!m->ReadAttachment(iter, &attachment)) |
556 return false; | 559 return false; |
557 | 560 |
558 *r = base::FileDescriptor(attachment->TakePlatformFile(), true); | 561 *r = base::FileDescriptor( |
| 562 static_cast<MessageAttachment*>(attachment.get())->TakePlatformFile(), |
| 563 true); |
559 return true; | 564 return true; |
560 } | 565 } |
561 | 566 |
562 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, | 567 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
563 std::string* l) { | 568 std::string* l) { |
564 if (p.auto_close) { | 569 if (p.auto_close) { |
565 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); | 570 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
566 } else { | 571 } else { |
567 l->append(base::StringPrintf("FD(%d)", p.fd)); | 572 l->append(base::StringPrintf("FD(%d)", p.fd)); |
568 } | 573 } |
569 } | 574 } |
570 #endif // defined(OS_POSIX) | 575 #endif // defined(OS_POSIX) |
571 | 576 |
572 #if defined(OS_MACOSX) && !defined(OS_IOS) | 577 #if defined(OS_MACOSX) && !defined(OS_IOS) |
573 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m, | 578 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
574 const param_type& p) { | 579 const param_type& p) { |
575 m->WriteInt(p.GetType()); | 580 m->WriteInt(p.GetType()); |
576 | 581 |
577 switch (p.GetType()) { | 582 switch (p.GetType()) { |
578 case base::SharedMemoryHandle::POSIX: | 583 case base::SharedMemoryHandle::POSIX: |
579 ParamTraits<base::FileDescriptor>::Write(m, p.GetFileDescriptor()); | 584 ParamTraits<base::FileDescriptor>::Write(m, p.GetFileDescriptor()); |
580 break; | 585 break; |
581 case base::SharedMemoryHandle::MACH: | 586 case base::SharedMemoryHandle::MACH: |
582 MachPortMac mach_port_mac(p.GetMemoryObject()); | 587 MachPortMac mach_port_mac(p.GetMemoryObject()); |
583 ParamTraits<MachPortMac>::Write(m, mach_port_mac); | 588 ParamTraits<MachPortMac>::Write(m, mach_port_mac); |
584 size_t size = 0; | 589 size_t size = 0; |
585 bool result = p.GetSize(&size); | 590 bool result = p.GetSize(&size); |
586 DCHECK(result); | 591 DCHECK(result); |
587 ParamTraits<size_t>::Write(m, size); | 592 ParamTraits<size_t>::Write(m, size); |
588 | 593 |
589 // If the caller intended to pass ownership to the IPC stack, release a | 594 // If the caller intended to pass ownership to the IPC stack, release a |
590 // reference. | 595 // reference. |
591 if (p.OwnershipPassesToIPC()) | 596 if (p.OwnershipPassesToIPC()) |
592 p.Close(); | 597 p.Close(); |
593 | 598 |
594 break; | 599 break; |
595 } | 600 } |
596 } | 601 } |
597 | 602 |
598 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, | 603 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
599 base::PickleIterator* iter, | 604 base::PickleIterator* iter, |
600 param_type* r) { | 605 param_type* r) { |
601 base::SharedMemoryHandle::TypeWireFormat type; | 606 base::SharedMemoryHandle::TypeWireFormat type; |
602 if (!iter->ReadInt(&type)) | 607 if (!iter->ReadInt(&type)) |
603 return false; | 608 return false; |
604 | 609 |
605 base::SharedMemoryHandle::Type shm_type = base::SharedMemoryHandle::POSIX; | 610 base::SharedMemoryHandle::Type shm_type = base::SharedMemoryHandle::POSIX; |
606 switch (type) { | 611 switch (type) { |
607 case base::SharedMemoryHandle::POSIX: | 612 case base::SharedMemoryHandle::POSIX: |
608 case base::SharedMemoryHandle::MACH: { | 613 case base::SharedMemoryHandle::MACH: { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l); | 656 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l); |
652 break; | 657 break; |
653 case base::SharedMemoryHandle::MACH: | 658 case base::SharedMemoryHandle::MACH: |
654 l->append("Mach port: "); | 659 l->append("Mach port: "); |
655 LogParam(p.GetMemoryObject(), l); | 660 LogParam(p.GetMemoryObject(), l); |
656 break; | 661 break; |
657 } | 662 } |
658 } | 663 } |
659 | 664 |
660 #elif defined(OS_WIN) | 665 #elif defined(OS_WIN) |
661 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m, | 666 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
662 const param_type& p) { | 667 const param_type& p) { |
663 m->WriteBool(p.NeedsBrokering()); | 668 m->WriteBool(p.NeedsBrokering()); |
664 | 669 |
665 if (p.NeedsBrokering()) { | 670 if (p.NeedsBrokering()) { |
666 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); | 671 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); |
667 ParamTraits<HandleWin>::Write(m, handle_win); | 672 ParamTraits<HandleWin>::Write(m, handle_win); |
668 | 673 |
669 // If the caller intended to pass ownership to the IPC stack, release a | 674 // If the caller intended to pass ownership to the IPC stack, release a |
670 // reference. | 675 // reference. |
671 if (p.OwnershipPassesToIPC()) | 676 if (p.OwnershipPassesToIPC()) |
672 p.Close(); | 677 p.Close(); |
673 } else { | 678 } else { |
674 m->WriteInt(HandleToLong(p.GetHandle())); | 679 m->WriteInt(HandleToLong(p.GetHandle())); |
675 } | 680 } |
676 } | 681 } |
677 | 682 |
678 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, | 683 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
679 base::PickleIterator* iter, | 684 base::PickleIterator* iter, |
680 param_type* r) { | 685 param_type* r) { |
681 bool needs_brokering; | 686 bool needs_brokering; |
682 if (!iter->ReadBool(&needs_brokering)) | 687 if (!iter->ReadBool(&needs_brokering)) |
683 return false; | 688 return false; |
684 | 689 |
685 if (needs_brokering) { | 690 if (needs_brokering) { |
686 HandleWin handle_win; | 691 HandleWin handle_win; |
687 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win)) | 692 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win)) |
688 return false; | 693 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
700 } | 705 } |
701 | 706 |
702 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | 707 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
703 std::string* l) { | 708 std::string* l) { |
704 LogParam(p.GetHandle(), l); | 709 LogParam(p.GetHandle(), l); |
705 l->append(" needs brokering: "); | 710 l->append(" needs brokering: "); |
706 LogParam(p.NeedsBrokering(), l); | 711 LogParam(p.NeedsBrokering(), l); |
707 } | 712 } |
708 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 713 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
709 | 714 |
710 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { | 715 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { |
711 p.WriteToPickle(m); | 716 p.WriteToPickle(m); |
712 } | 717 } |
713 | 718 |
714 bool ParamTraits<base::FilePath>::Read(const Message* m, | 719 bool ParamTraits<base::FilePath>::Read(const base::Pickle* m, |
715 base::PickleIterator* iter, | 720 base::PickleIterator* iter, |
716 param_type* r) { | 721 param_type* r) { |
717 return r->ReadFromPickle(iter); | 722 return r->ReadFromPickle(iter); |
718 } | 723 } |
719 | 724 |
720 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { | 725 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { |
721 ParamTraits<base::FilePath::StringType>::Log(p.value(), l); | 726 ParamTraits<base::FilePath::StringType>::Log(p.value(), l); |
722 } | 727 } |
723 | 728 |
724 void ParamTraits<base::ListValue>::Write(Message* m, const param_type& p) { | 729 void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) { |
725 WriteValue(m, &p, 0); | 730 WriteValue(m, &p, 0); |
726 } | 731 } |
727 | 732 |
728 bool ParamTraits<base::ListValue>::Read(const Message* m, | 733 bool ParamTraits<base::ListValue>::Read(const base::Pickle* m, |
729 base::PickleIterator* iter, | 734 base::PickleIterator* iter, |
730 param_type* r) { | 735 param_type* r) { |
731 int type; | 736 int type; |
732 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) | 737 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) |
733 return false; | 738 return false; |
734 | 739 |
735 return ReadListValue(m, iter, r, 0); | 740 return ReadListValue(m, iter, r, 0); |
736 } | 741 } |
737 | 742 |
738 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { | 743 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { |
739 std::string json; | 744 std::string json; |
740 base::JSONWriter::Write(p, &json); | 745 base::JSONWriter::Write(p, &json); |
741 l->append(json); | 746 l->append(json); |
742 } | 747 } |
743 | 748 |
744 void ParamTraits<base::NullableString16>::Write(Message* m, | 749 void ParamTraits<base::NullableString16>::Write(base::Pickle* m, |
745 const param_type& p) { | 750 const param_type& p) { |
746 WriteParam(m, p.string()); | 751 WriteParam(m, p.string()); |
747 WriteParam(m, p.is_null()); | 752 WriteParam(m, p.is_null()); |
748 } | 753 } |
749 | 754 |
750 bool ParamTraits<base::NullableString16>::Read(const Message* m, | 755 bool ParamTraits<base::NullableString16>::Read(const base::Pickle* m, |
751 base::PickleIterator* iter, | 756 base::PickleIterator* iter, |
752 param_type* r) { | 757 param_type* r) { |
753 base::string16 string; | 758 base::string16 string; |
754 if (!ReadParam(m, iter, &string)) | 759 if (!ReadParam(m, iter, &string)) |
755 return false; | 760 return false; |
756 bool is_null; | 761 bool is_null; |
757 if (!ReadParam(m, iter, &is_null)) | 762 if (!ReadParam(m, iter, &is_null)) |
758 return false; | 763 return false; |
759 *r = base::NullableString16(string, is_null); | 764 *r = base::NullableString16(string, is_null); |
760 return true; | 765 return true; |
761 } | 766 } |
762 | 767 |
763 void ParamTraits<base::NullableString16>::Log(const param_type& p, | 768 void ParamTraits<base::NullableString16>::Log(const param_type& p, |
764 std::string* l) { | 769 std::string* l) { |
765 l->append("("); | 770 l->append("("); |
766 LogParam(p.string(), l); | 771 LogParam(p.string(), l); |
767 l->append(", "); | 772 l->append(", "); |
768 LogParam(p.is_null(), l); | 773 LogParam(p.is_null(), l); |
769 l->append(")"); | 774 l->append(")"); |
770 } | 775 } |
771 | 776 |
772 void ParamTraits<base::File::Info>::Write(Message* m, | 777 void ParamTraits<base::File::Info>::Write(base::Pickle* m, |
773 const param_type& p) { | 778 const param_type& p) { |
774 WriteParam(m, p.size); | 779 WriteParam(m, p.size); |
775 WriteParam(m, p.is_directory); | 780 WriteParam(m, p.is_directory); |
776 WriteParam(m, p.last_modified.ToDoubleT()); | 781 WriteParam(m, p.last_modified.ToDoubleT()); |
777 WriteParam(m, p.last_accessed.ToDoubleT()); | 782 WriteParam(m, p.last_accessed.ToDoubleT()); |
778 WriteParam(m, p.creation_time.ToDoubleT()); | 783 WriteParam(m, p.creation_time.ToDoubleT()); |
779 } | 784 } |
780 | 785 |
781 bool ParamTraits<base::File::Info>::Read(const Message* m, | 786 bool ParamTraits<base::File::Info>::Read(const base::Pickle* m, |
782 base::PickleIterator* iter, | 787 base::PickleIterator* iter, |
783 param_type* p) { | 788 param_type* p) { |
784 double last_modified, last_accessed, creation_time; | 789 double last_modified, last_accessed, creation_time; |
785 if (!ReadParam(m, iter, &p->size) || | 790 if (!ReadParam(m, iter, &p->size) || |
786 !ReadParam(m, iter, &p->is_directory) || | 791 !ReadParam(m, iter, &p->is_directory) || |
787 !ReadParam(m, iter, &last_modified) || | 792 !ReadParam(m, iter, &last_modified) || |
788 !ReadParam(m, iter, &last_accessed) || | 793 !ReadParam(m, iter, &last_accessed) || |
789 !ReadParam(m, iter, &creation_time)) | 794 !ReadParam(m, iter, &creation_time)) |
790 return false; | 795 return false; |
791 p->last_modified = base::Time::FromDoubleT(last_modified); | 796 p->last_modified = base::Time::FromDoubleT(last_modified); |
(...skipping 10 matching lines...) Expand all Loading... |
802 LogParam(p.is_directory, l); | 807 LogParam(p.is_directory, l); |
803 l->append(","); | 808 l->append(","); |
804 LogParam(p.last_modified.ToDoubleT(), l); | 809 LogParam(p.last_modified.ToDoubleT(), l); |
805 l->append(","); | 810 l->append(","); |
806 LogParam(p.last_accessed.ToDoubleT(), l); | 811 LogParam(p.last_accessed.ToDoubleT(), l); |
807 l->append(","); | 812 l->append(","); |
808 LogParam(p.creation_time.ToDoubleT(), l); | 813 LogParam(p.creation_time.ToDoubleT(), l); |
809 l->append(")"); | 814 l->append(")"); |
810 } | 815 } |
811 | 816 |
812 void ParamTraits<base::Time>::Write(Message* m, const param_type& p) { | 817 void ParamTraits<base::Time>::Write(base::Pickle* m, const param_type& p) { |
813 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 818 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
814 } | 819 } |
815 | 820 |
816 bool ParamTraits<base::Time>::Read(const Message* m, | 821 bool ParamTraits<base::Time>::Read(const base::Pickle* m, |
817 base::PickleIterator* iter, | 822 base::PickleIterator* iter, |
818 param_type* r) { | 823 param_type* r) { |
819 int64_t value; | 824 int64_t value; |
820 if (!ParamTraits<int64_t>::Read(m, iter, &value)) | 825 if (!ParamTraits<int64_t>::Read(m, iter, &value)) |
821 return false; | 826 return false; |
822 *r = base::Time::FromInternalValue(value); | 827 *r = base::Time::FromInternalValue(value); |
823 return true; | 828 return true; |
824 } | 829 } |
825 | 830 |
826 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { | 831 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { |
827 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 832 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
828 } | 833 } |
829 | 834 |
830 void ParamTraits<base::TimeDelta>::Write(Message* m, const param_type& p) { | 835 void ParamTraits<base::TimeDelta>::Write(base::Pickle* m, const param_type& p) { |
831 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 836 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
832 } | 837 } |
833 | 838 |
834 bool ParamTraits<base::TimeDelta>::Read(const Message* m, | 839 bool ParamTraits<base::TimeDelta>::Read(const base::Pickle* m, |
835 base::PickleIterator* iter, | 840 base::PickleIterator* iter, |
836 param_type* r) { | 841 param_type* r) { |
837 int64_t value; | 842 int64_t value; |
838 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); | 843 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
839 if (ret) | 844 if (ret) |
840 *r = base::TimeDelta::FromInternalValue(value); | 845 *r = base::TimeDelta::FromInternalValue(value); |
841 | 846 |
842 return ret; | 847 return ret; |
843 } | 848 } |
844 | 849 |
845 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { | 850 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { |
846 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 851 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
847 } | 852 } |
848 | 853 |
849 void ParamTraits<base::TimeTicks>::Write(Message* m, const param_type& p) { | 854 void ParamTraits<base::TimeTicks>::Write(base::Pickle* m, const param_type& p) { |
850 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 855 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
851 } | 856 } |
852 | 857 |
853 bool ParamTraits<base::TimeTicks>::Read(const Message* m, | 858 bool ParamTraits<base::TimeTicks>::Read(const base::Pickle* m, |
854 base::PickleIterator* iter, | 859 base::PickleIterator* iter, |
855 param_type* r) { | 860 param_type* r) { |
856 int64_t value; | 861 int64_t value; |
857 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); | 862 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
858 if (ret) | 863 if (ret) |
859 *r = base::TimeTicks::FromInternalValue(value); | 864 *r = base::TimeTicks::FromInternalValue(value); |
860 | 865 |
861 return ret; | 866 return ret; |
862 } | 867 } |
863 | 868 |
864 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { | 869 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { |
865 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 870 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
866 } | 871 } |
867 | 872 |
868 void ParamTraits<IPC::ChannelHandle>::Write(Message* m, const param_type& p) { | 873 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, |
| 874 const param_type& p) { |
869 #if defined(OS_WIN) | 875 #if defined(OS_WIN) |
870 // On Windows marshalling pipe handle is not supported. | 876 // On Windows marshalling pipe handle is not supported. |
871 DCHECK(p.pipe.handle == NULL); | 877 DCHECK(p.pipe.handle == NULL); |
872 #endif // defined (OS_WIN) | 878 #endif // defined (OS_WIN) |
873 WriteParam(m, p.name); | 879 WriteParam(m, p.name); |
874 #if defined(OS_POSIX) | 880 #if defined(OS_POSIX) |
875 WriteParam(m, p.socket); | 881 WriteParam(m, p.socket); |
876 #endif | 882 #endif |
877 } | 883 } |
878 | 884 |
879 bool ParamTraits<IPC::ChannelHandle>::Read(const Message* m, | 885 bool ParamTraits<IPC::ChannelHandle>::Read(const base::Pickle* m, |
880 base::PickleIterator* iter, | 886 base::PickleIterator* iter, |
881 param_type* r) { | 887 param_type* r) { |
882 return ReadParam(m, iter, &r->name) | 888 return ReadParam(m, iter, &r->name) |
883 #if defined(OS_POSIX) | 889 #if defined(OS_POSIX) |
884 && ReadParam(m, iter, &r->socket) | 890 && ReadParam(m, iter, &r->socket) |
885 #endif | 891 #endif |
886 ; | 892 ; |
887 } | 893 } |
888 | 894 |
889 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, | 895 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, |
890 std::string* l) { | 896 std::string* l) { |
891 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); | 897 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); |
892 #if defined(OS_POSIX) | 898 #if defined(OS_POSIX) |
893 l->append(", "); | 899 l->append(", "); |
894 ParamTraits<base::FileDescriptor>::Log(p.socket, l); | 900 ParamTraits<base::FileDescriptor>::Log(p.socket, l); |
895 #endif | 901 #endif |
896 l->append(")"); | 902 l->append(")"); |
897 } | 903 } |
898 | 904 |
899 void ParamTraits<LogData>::Write(Message* m, const param_type& p) { | 905 void ParamTraits<LogData>::Write(base::Pickle* m, const param_type& p) { |
900 WriteParam(m, p.channel); | 906 WriteParam(m, p.channel); |
901 WriteParam(m, p.routing_id); | 907 WriteParam(m, p.routing_id); |
902 WriteParam(m, p.type); | 908 WriteParam(m, p.type); |
903 WriteParam(m, p.flags); | 909 WriteParam(m, p.flags); |
904 WriteParam(m, p.sent); | 910 WriteParam(m, p.sent); |
905 WriteParam(m, p.receive); | 911 WriteParam(m, p.receive); |
906 WriteParam(m, p.dispatch); | 912 WriteParam(m, p.dispatch); |
907 WriteParam(m, p.message_name); | 913 WriteParam(m, p.message_name); |
908 WriteParam(m, p.params); | 914 WriteParam(m, p.params); |
909 } | 915 } |
910 | 916 |
911 bool ParamTraits<LogData>::Read(const Message* m, | 917 bool ParamTraits<LogData>::Read(const base::Pickle* m, |
912 base::PickleIterator* iter, | 918 base::PickleIterator* iter, |
913 param_type* r) { | 919 param_type* r) { |
914 return | 920 return |
915 ReadParam(m, iter, &r->channel) && | 921 ReadParam(m, iter, &r->channel) && |
916 ReadParam(m, iter, &r->routing_id) && | 922 ReadParam(m, iter, &r->routing_id) && |
917 ReadParam(m, iter, &r->type) && | 923 ReadParam(m, iter, &r->type) && |
918 ReadParam(m, iter, &r->flags) && | 924 ReadParam(m, iter, &r->flags) && |
919 ReadParam(m, iter, &r->sent) && | 925 ReadParam(m, iter, &r->sent) && |
920 ReadParam(m, iter, &r->receive) && | 926 ReadParam(m, iter, &r->receive) && |
921 ReadParam(m, iter, &r->dispatch) && | 927 ReadParam(m, iter, &r->dispatch) && |
922 ReadParam(m, iter, &r->message_name) && | 928 ReadParam(m, iter, &r->message_name) && |
923 ReadParam(m, iter, &r->params); | 929 ReadParam(m, iter, &r->params); |
924 } | 930 } |
925 | 931 |
926 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { | 932 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { |
927 // Doesn't make sense to implement this! | 933 // Doesn't make sense to implement this! |
928 } | 934 } |
929 | 935 |
930 void ParamTraits<Message>::Write(Message* m, const Message& p) { | 936 void ParamTraits<Message>::Write(base::Pickle* m, const Message& p) { |
931 #if defined(OS_POSIX) | 937 #if defined(OS_POSIX) |
932 // We don't serialize the file descriptors in the nested message, so there | 938 // We don't serialize the file descriptors in the nested message, so there |
933 // better not be any. | 939 // better not be any. |
934 DCHECK(!p.HasAttachments()); | 940 DCHECK(!p.HasAttachments()); |
935 #endif | 941 #endif |
936 | 942 |
937 // Don't just write out the message. This is used to send messages between | 943 // Don't just write out the message. This is used to send messages between |
938 // NaCl (Posix environment) and the browser (could be on Windows). The message | 944 // NaCl (Posix environment) and the browser (could be on Windows). The message |
939 // header formats differ between these systems (so does handle sharing, but | 945 // header formats differ between these systems (so does handle sharing, but |
940 // we already asserted we don't have any handles). So just write out the | 946 // we already asserted we don't have any handles). So just write out the |
941 // parts of the header we use. | 947 // parts of the header we use. |
942 // | 948 // |
943 // Be careful also to use only explicitly-sized types. The NaCl environment | 949 // Be careful also to use only explicitly-sized types. The NaCl environment |
944 // could be 64-bit and the host browser could be 32-bits. The nested message | 950 // could be 64-bit and the host browser could be 32-bits. The nested message |
945 // may or may not be safe to send between 32-bit and 64-bit systems, but we | 951 // may or may not be safe to send between 32-bit and 64-bit systems, but we |
946 // leave that up to the code sending the message to ensure. | 952 // leave that up to the code sending the message to ensure. |
947 m->WriteUInt32(static_cast<uint32_t>(p.routing_id())); | 953 m->WriteUInt32(static_cast<uint32_t>(p.routing_id())); |
948 m->WriteUInt32(p.type()); | 954 m->WriteUInt32(p.type()); |
949 m->WriteUInt32(p.flags()); | 955 m->WriteUInt32(p.flags()); |
950 m->WriteData(p.payload(), static_cast<uint32_t>(p.payload_size())); | 956 m->WriteData(p.payload(), static_cast<uint32_t>(p.payload_size())); |
951 } | 957 } |
952 | 958 |
953 bool ParamTraits<Message>::Read(const Message* m, | 959 bool ParamTraits<Message>::Read(const base::Pickle* m, |
954 base::PickleIterator* iter, | 960 base::PickleIterator* iter, |
955 Message* r) { | 961 Message* r) { |
956 uint32_t routing_id, type, flags; | 962 uint32_t routing_id, type, flags; |
957 if (!iter->ReadUInt32(&routing_id) || | 963 if (!iter->ReadUInt32(&routing_id) || |
958 !iter->ReadUInt32(&type) || | 964 !iter->ReadUInt32(&type) || |
959 !iter->ReadUInt32(&flags)) | 965 !iter->ReadUInt32(&flags)) |
960 return false; | 966 return false; |
961 | 967 |
962 int payload_size; | 968 int payload_size; |
963 const char* payload; | 969 const char* payload; |
964 if (!iter->ReadData(&payload, &payload_size)) | 970 if (!iter->ReadData(&payload, &payload_size)) |
965 return false; | 971 return false; |
966 | 972 |
967 r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); | 973 r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); |
968 return r->WriteBytes(payload, payload_size); | 974 return r->WriteBytes(payload, payload_size); |
969 } | 975 } |
970 | 976 |
971 void ParamTraits<Message>::Log(const Message& p, std::string* l) { | 977 void ParamTraits<Message>::Log(const Message& p, std::string* l) { |
972 l->append("<IPC::Message>"); | 978 l->append("<IPC::Message>"); |
973 } | 979 } |
974 | 980 |
975 #if defined(OS_WIN) | 981 #if defined(OS_WIN) |
976 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 | 982 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 |
977 // bit systems. That's why we use the Windows macros to convert to 32 bits. | 983 // bit systems. That's why we use the Windows macros to convert to 32 bits. |
978 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) { | 984 void ParamTraits<HANDLE>::Write(base::Pickle* m, const param_type& p) { |
979 m->WriteInt(HandleToLong(p)); | 985 m->WriteInt(HandleToLong(p)); |
980 } | 986 } |
981 | 987 |
982 bool ParamTraits<HANDLE>::Read(const Message* m, | 988 bool ParamTraits<HANDLE>::Read(const base::Pickle* m, |
983 base::PickleIterator* iter, | 989 base::PickleIterator* iter, |
984 param_type* r) { | 990 param_type* r) { |
985 int32_t temp; | 991 int32_t temp; |
986 if (!iter->ReadInt(&temp)) | 992 if (!iter->ReadInt(&temp)) |
987 return false; | 993 return false; |
988 *r = LongToHandle(temp); | 994 *r = LongToHandle(temp); |
989 return true; | 995 return true; |
990 } | 996 } |
991 | 997 |
992 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { | 998 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { |
993 l->append(base::StringPrintf("0x%p", p)); | 999 l->append(base::StringPrintf("0x%p", p)); |
994 } | 1000 } |
995 | 1001 |
996 void ParamTraits<LOGFONT>::Write(Message* m, const param_type& p) { | 1002 void ParamTraits<LOGFONT>::Write(base::Pickle* m, const param_type& p) { |
997 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); | 1003 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); |
998 } | 1004 } |
999 | 1005 |
1000 bool ParamTraits<LOGFONT>::Read(const Message* m, | 1006 bool ParamTraits<LOGFONT>::Read(const base::Pickle* m, |
1001 base::PickleIterator* iter, | 1007 base::PickleIterator* iter, |
1002 param_type* r) { | 1008 param_type* r) { |
1003 const char *data; | 1009 const char *data; |
1004 int data_size = 0; | 1010 int data_size = 0; |
1005 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { | 1011 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { |
1006 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); | 1012 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); |
1007 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { | 1013 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { |
1008 memcpy(r, data, sizeof(LOGFONT)); | 1014 memcpy(r, data, sizeof(LOGFONT)); |
1009 return true; | 1015 return true; |
1010 } | 1016 } |
1011 } | 1017 } |
1012 | 1018 |
1013 NOTREACHED(); | 1019 NOTREACHED(); |
1014 return false; | 1020 return false; |
1015 } | 1021 } |
1016 | 1022 |
1017 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { | 1023 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { |
1018 l->append(base::StringPrintf("<LOGFONT>")); | 1024 l->append(base::StringPrintf("<LOGFONT>")); |
1019 } | 1025 } |
1020 | 1026 |
1021 void ParamTraits<MSG>::Write(Message* m, const param_type& p) { | 1027 void ParamTraits<MSG>::Write(base::Pickle* m, const param_type& p) { |
1022 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); | 1028 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); |
1023 } | 1029 } |
1024 | 1030 |
1025 bool ParamTraits<MSG>::Read(const Message* m, | 1031 bool ParamTraits<MSG>::Read(const base::Pickle* m, |
1026 base::PickleIterator* iter, | 1032 base::PickleIterator* iter, |
1027 param_type* r) { | 1033 param_type* r) { |
1028 const char *data; | 1034 const char *data; |
1029 int data_size = 0; | 1035 int data_size = 0; |
1030 bool result = iter->ReadData(&data, &data_size); | 1036 bool result = iter->ReadData(&data, &data_size); |
1031 if (result && data_size == sizeof(MSG)) { | 1037 if (result && data_size == sizeof(MSG)) { |
1032 memcpy(r, data, sizeof(MSG)); | 1038 memcpy(r, data, sizeof(MSG)); |
1033 } else { | 1039 } else { |
1034 result = false; | 1040 result = false; |
1035 NOTREACHED(); | 1041 NOTREACHED(); |
1036 } | 1042 } |
1037 | 1043 |
1038 return result; | 1044 return result; |
1039 } | 1045 } |
1040 | 1046 |
1041 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1047 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1042 l->append("<MSG>"); | 1048 l->append("<MSG>"); |
1043 } | 1049 } |
1044 | 1050 |
1045 #endif // OS_WIN | 1051 #endif // OS_WIN |
1046 | 1052 |
1047 } // namespace IPC | 1053 } // namespace IPC |
OLD | NEW |