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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::Pickle* 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 GetValueSize(base::PickleSizer* sizer, |
| 76 const base::Value* value, |
| 77 int recursion) { |
| 78 if (recursion > kMaxRecursionDepth) { |
| 79 LOG(WARNING) << "Max recursion depth hit in GetValueSize."; |
| 80 return; |
| 81 } |
| 82 |
| 83 sizer->AddInt(); |
| 84 switch (value->GetType()) { |
| 85 case base::Value::TYPE_NULL: |
| 86 break; |
| 87 case base::Value::TYPE_BOOLEAN: |
| 88 sizer->AddBool(); |
| 89 break; |
| 90 case base::Value::TYPE_INTEGER: |
| 91 sizer->AddInt(); |
| 92 break; |
| 93 case base::Value::TYPE_DOUBLE: |
| 94 sizer->AddDouble(); |
| 95 break; |
| 96 case base::Value::TYPE_STRING: { |
| 97 const base::StringValue* result; |
| 98 value->GetAsString(&result); |
| 99 DCHECK(result); |
| 100 GetParamSize(sizer, result->GetString()); |
| 101 break; |
| 102 } |
| 103 case base::Value::TYPE_BINARY: { |
| 104 const base::BinaryValue* binary = |
| 105 static_cast<const base::BinaryValue*>(value); |
| 106 sizer->AddData(static_cast<int>(binary->GetSize())); |
| 107 break; |
| 108 } |
| 109 case base::Value::TYPE_DICTIONARY: { |
| 110 sizer->AddInt(); |
| 111 const base::DictionaryValue* dict = |
| 112 static_cast<const base::DictionaryValue*>(value); |
| 113 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); |
| 114 it.Advance()) { |
| 115 GetParamSize(sizer, it.key()); |
| 116 GetValueSize(sizer, &it.value(), recursion + 1); |
| 117 } |
| 118 break; |
| 119 } |
| 120 case base::Value::TYPE_LIST: { |
| 121 sizer->AddInt(); |
| 122 const base::ListValue* list = static_cast<const base::ListValue*>(value); |
| 123 for (base::ListValue::const_iterator it = list->begin(); |
| 124 it != list->end(); ++it) { |
| 125 GetValueSize(sizer, *it, recursion + 1); |
| 126 } |
| 127 break; |
| 128 } |
| 129 default: |
| 130 NOTREACHED() << "Invalid base::Value type."; |
| 131 } |
| 132 } |
| 133 |
75 void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { | 134 void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { |
76 bool result; | 135 bool result; |
77 if (recursion > kMaxRecursionDepth) { | 136 if (recursion > kMaxRecursionDepth) { |
78 LOG(WARNING) << "Max recursion depth hit in WriteValue."; | 137 LOG(WARNING) << "Max recursion depth hit in WriteValue."; |
79 return; | 138 return; |
80 } | 139 } |
81 | 140 |
82 m->WriteInt(value->GetType()); | 141 m->WriteInt(value->GetType()); |
83 | 142 |
84 switch (value->GetType()) { | 143 switch (value->GetType()) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 dispatch(0) { | 330 dispatch(0) { |
272 } | 331 } |
273 | 332 |
274 LogData::~LogData() { | 333 LogData::~LogData() { |
275 } | 334 } |
276 | 335 |
277 void ParamTraits<bool>::Log(const param_type& p, std::string* l) { | 336 void ParamTraits<bool>::Log(const param_type& p, std::string* l) { |
278 l->append(p ? "true" : "false"); | 337 l->append(p ? "true" : "false"); |
279 } | 338 } |
280 | 339 |
| 340 void ParamTraits<signed char>::GetSize(base::PickleSizer* sizer, |
| 341 const param_type& p) { |
| 342 sizer->AddBytes(sizeof(param_type)); |
| 343 } |
| 344 |
281 void ParamTraits<signed char>::Write(base::Pickle* m, const param_type& p) { | 345 void ParamTraits<signed char>::Write(base::Pickle* m, const param_type& p) { |
282 m->WriteBytes(&p, sizeof(param_type)); | 346 m->WriteBytes(&p, sizeof(param_type)); |
283 } | 347 } |
284 | 348 |
285 bool ParamTraits<signed char>::Read(const base::Pickle* m, | 349 bool ParamTraits<signed char>::Read(const base::Pickle* m, |
286 base::PickleIterator* iter, | 350 base::PickleIterator* iter, |
287 param_type* r) { | 351 param_type* r) { |
288 const char* data; | 352 const char* data; |
289 if (!iter->ReadBytes(&data, sizeof(param_type))) | 353 if (!iter->ReadBytes(&data, sizeof(param_type))) |
290 return false; | 354 return false; |
291 memcpy(r, data, sizeof(param_type)); | 355 memcpy(r, data, sizeof(param_type)); |
292 return true; | 356 return true; |
293 } | 357 } |
294 | 358 |
295 void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { | 359 void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { |
296 l->append(base::IntToString(p)); | 360 l->append(base::IntToString(p)); |
297 } | 361 } |
298 | 362 |
| 363 void ParamTraits<unsigned char>::GetSize(base::PickleSizer* sizer, |
| 364 const param_type& p) { |
| 365 sizer->AddBytes(sizeof(param_type)); |
| 366 } |
| 367 |
299 void ParamTraits<unsigned char>::Write(base::Pickle* m, const param_type& p) { | 368 void ParamTraits<unsigned char>::Write(base::Pickle* m, const param_type& p) { |
300 m->WriteBytes(&p, sizeof(param_type)); | 369 m->WriteBytes(&p, sizeof(param_type)); |
301 } | 370 } |
302 | 371 |
303 bool ParamTraits<unsigned char>::Read(const base::Pickle* m, | 372 bool ParamTraits<unsigned char>::Read(const base::Pickle* m, |
304 base::PickleIterator* iter, | 373 base::PickleIterator* iter, |
305 param_type* r) { | 374 param_type* r) { |
306 const char* data; | 375 const char* data; |
307 if (!iter->ReadBytes(&data, sizeof(param_type))) | 376 if (!iter->ReadBytes(&data, sizeof(param_type))) |
308 return false; | 377 return false; |
309 memcpy(r, data, sizeof(param_type)); | 378 memcpy(r, data, sizeof(param_type)); |
310 return true; | 379 return true; |
311 } | 380 } |
312 | 381 |
313 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { | 382 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { |
314 l->append(base::UintToString(p)); | 383 l->append(base::UintToString(p)); |
315 } | 384 } |
316 | 385 |
| 386 void ParamTraits<unsigned short>::GetSize(base::PickleSizer* sizer, |
| 387 const param_type& p) { |
| 388 sizer->AddBytes(sizeof(param_type)); |
| 389 } |
| 390 |
317 void ParamTraits<unsigned short>::Write(base::Pickle* m, const param_type& p) { | 391 void ParamTraits<unsigned short>::Write(base::Pickle* m, const param_type& p) { |
318 m->WriteBytes(&p, sizeof(param_type)); | 392 m->WriteBytes(&p, sizeof(param_type)); |
319 } | 393 } |
320 | 394 |
321 bool ParamTraits<unsigned short>::Read(const base::Pickle* m, | 395 bool ParamTraits<unsigned short>::Read(const base::Pickle* m, |
322 base::PickleIterator* iter, | 396 base::PickleIterator* iter, |
323 param_type* r) { | 397 param_type* r) { |
324 const char* data; | 398 const char* data; |
325 if (!iter->ReadBytes(&data, sizeof(param_type))) | 399 if (!iter->ReadBytes(&data, sizeof(param_type))) |
326 return false; | 400 return false; |
(...skipping 26 matching lines...) Expand all Loading... |
353 } | 427 } |
354 | 428 |
355 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { | 429 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { |
356 l->append(base::Uint64ToString(p)); | 430 l->append(base::Uint64ToString(p)); |
357 } | 431 } |
358 | 432 |
359 void ParamTraits<float>::Log(const param_type& p, std::string* l) { | 433 void ParamTraits<float>::Log(const param_type& p, std::string* l) { |
360 l->append(base::StringPrintf("%e", p)); | 434 l->append(base::StringPrintf("%e", p)); |
361 } | 435 } |
362 | 436 |
| 437 void ParamTraits<double>::GetSize(base::PickleSizer* sizer, |
| 438 const param_type& p) { |
| 439 sizer->AddBytes(sizeof(param_type)); |
| 440 } |
| 441 |
363 void ParamTraits<double>::Write(base::Pickle* m, const param_type& p) { | 442 void ParamTraits<double>::Write(base::Pickle* m, const param_type& p) { |
364 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); | 443 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); |
365 } | 444 } |
366 | 445 |
367 bool ParamTraits<double>::Read(const base::Pickle* m, | 446 bool ParamTraits<double>::Read(const base::Pickle* m, |
368 base::PickleIterator* iter, | 447 base::PickleIterator* iter, |
369 param_type* r) { | 448 param_type* r) { |
370 const char *data; | 449 const char *data; |
371 if (!iter->ReadBytes(&data, sizeof(*r))) { | 450 if (!iter->ReadBytes(&data, sizeof(*r))) { |
372 NOTREACHED(); | 451 NOTREACHED(); |
373 return false; | 452 return false; |
374 } | 453 } |
375 memcpy(r, data, sizeof(param_type)); | 454 memcpy(r, data, sizeof(param_type)); |
376 return true; | 455 return true; |
377 } | 456 } |
378 | 457 |
379 void ParamTraits<double>::Log(const param_type& p, std::string* l) { | 458 void ParamTraits<double>::Log(const param_type& p, std::string* l) { |
380 l->append(base::StringPrintf("%e", p)); | 459 l->append(base::StringPrintf("%e", p)); |
381 } | 460 } |
382 | 461 |
383 | 462 |
384 void ParamTraits<std::string>::Log(const param_type& p, std::string* l) { | 463 void ParamTraits<std::string>::Log(const param_type& p, std::string* l) { |
385 l->append(p); | 464 l->append(p); |
386 } | 465 } |
387 | 466 |
388 void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { | 467 void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { |
389 l->append(base::UTF16ToUTF8(p)); | 468 l->append(base::UTF16ToUTF8(p)); |
390 } | 469 } |
391 | 470 |
| 471 void ParamTraits<std::vector<char>>::GetSize(base::PickleSizer* sizer, |
| 472 const param_type& p) { |
| 473 sizer->AddData(static_cast<int>(p.size())); |
| 474 } |
| 475 |
392 void ParamTraits<std::vector<char>>::Write(base::Pickle* m, | 476 void ParamTraits<std::vector<char>>::Write(base::Pickle* m, |
393 const param_type& p) { | 477 const param_type& p) { |
394 if (p.empty()) { | 478 if (p.empty()) { |
395 m->WriteData(NULL, 0); | 479 m->WriteData(NULL, 0); |
396 } else { | 480 } else { |
397 m->WriteData(&p.front(), static_cast<int>(p.size())); | 481 m->WriteData(&p.front(), static_cast<int>(p.size())); |
398 } | 482 } |
399 } | 483 } |
400 | 484 |
401 bool ParamTraits<std::vector<char>>::Read(const base::Pickle* m, | 485 bool ParamTraits<std::vector<char>>::Read(const base::Pickle* m, |
402 base::PickleIterator* iter, | 486 base::PickleIterator* iter, |
403 param_type* r) { | 487 param_type* r) { |
404 const char *data; | 488 const char *data; |
405 int data_size = 0; | 489 int data_size = 0; |
406 if (!iter->ReadData(&data, &data_size) || data_size < 0) | 490 if (!iter->ReadData(&data, &data_size) || data_size < 0) |
407 return false; | 491 return false; |
408 r->resize(data_size); | 492 r->resize(data_size); |
409 if (data_size) | 493 if (data_size) |
410 memcpy(&r->front(), data, data_size); | 494 memcpy(&r->front(), data, data_size); |
411 return true; | 495 return true; |
412 } | 496 } |
413 | 497 |
414 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { | 498 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { |
415 LogBytes(p, l); | 499 LogBytes(p, l); |
416 } | 500 } |
417 | 501 |
| 502 void ParamTraits<std::vector<unsigned char>>::GetSize(base::PickleSizer* sizer, |
| 503 const param_type& p) { |
| 504 sizer->AddData(static_cast<int>(p.size())); |
| 505 } |
| 506 |
418 void ParamTraits<std::vector<unsigned char>>::Write(base::Pickle* m, | 507 void ParamTraits<std::vector<unsigned char>>::Write(base::Pickle* m, |
419 const param_type& p) { | 508 const param_type& p) { |
420 if (p.empty()) { | 509 if (p.empty()) { |
421 m->WriteData(NULL, 0); | 510 m->WriteData(NULL, 0); |
422 } else { | 511 } else { |
423 m->WriteData(reinterpret_cast<const char*>(&p.front()), | 512 m->WriteData(reinterpret_cast<const char*>(&p.front()), |
424 static_cast<int>(p.size())); | 513 static_cast<int>(p.size())); |
425 } | 514 } |
426 } | 515 } |
427 | 516 |
428 bool ParamTraits<std::vector<unsigned char>>::Read(const base::Pickle* m, | 517 bool ParamTraits<std::vector<unsigned char>>::Read(const base::Pickle* m, |
429 base::PickleIterator* iter, | 518 base::PickleIterator* iter, |
430 param_type* r) { | 519 param_type* r) { |
431 const char *data; | 520 const char *data; |
432 int data_size = 0; | 521 int data_size = 0; |
433 if (!iter->ReadData(&data, &data_size) || data_size < 0) | 522 if (!iter->ReadData(&data, &data_size) || data_size < 0) |
434 return false; | 523 return false; |
435 r->resize(data_size); | 524 r->resize(data_size); |
436 if (data_size) | 525 if (data_size) |
437 memcpy(&r->front(), data, data_size); | 526 memcpy(&r->front(), data, data_size); |
438 return true; | 527 return true; |
439 } | 528 } |
440 | 529 |
441 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, | 530 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, |
442 std::string* l) { | 531 std::string* l) { |
443 LogBytes(p, l); | 532 LogBytes(p, l); |
444 } | 533 } |
445 | 534 |
| 535 void ParamTraits<std::vector<bool>>::GetSize(base::PickleSizer* sizer, |
| 536 const param_type& p) { |
| 537 GetParamSize(sizer, static_cast<int>(p.size())); |
| 538 for (size_t i = 0; i < p.size(); ++i) |
| 539 GetParamSize(sizer, static_cast<bool>(p[i])); |
| 540 } |
| 541 |
446 void ParamTraits<std::vector<bool>>::Write(base::Pickle* m, | 542 void ParamTraits<std::vector<bool>>::Write(base::Pickle* m, |
447 const param_type& p) { | 543 const param_type& p) { |
448 WriteParam(m, static_cast<int>(p.size())); | 544 WriteParam(m, static_cast<int>(p.size())); |
449 // Cast to bool below is required because libc++'s | 545 // Cast to bool below is required because libc++'s |
450 // vector<bool>::const_reference is different from bool, and we want to avoid | 546 // vector<bool>::const_reference is different from bool, and we want to avoid |
451 // writing an extra specialization of ParamTraits for it. | 547 // writing an extra specialization of ParamTraits for it. |
452 for (size_t i = 0; i < p.size(); i++) | 548 for (size_t i = 0; i < p.size(); i++) |
453 WriteParam(m, static_cast<bool>(p[i])); | 549 WriteParam(m, static_cast<bool>(p[i])); |
454 } | 550 } |
455 | 551 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 return false; | 589 return false; |
494 memcpy(r->nonce, data, BrokerableAttachment::kNonceSize); | 590 memcpy(r->nonce, data, BrokerableAttachment::kNonceSize); |
495 return true; | 591 return true; |
496 } | 592 } |
497 | 593 |
498 void ParamTraits<BrokerableAttachment::AttachmentId>::Log(const param_type& p, | 594 void ParamTraits<BrokerableAttachment::AttachmentId>::Log(const param_type& p, |
499 std::string* l) { | 595 std::string* l) { |
500 l->append(base::HexEncode(p.nonce, BrokerableAttachment::kNonceSize)); | 596 l->append(base::HexEncode(p.nonce, BrokerableAttachment::kNonceSize)); |
501 } | 597 } |
502 | 598 |
| 599 void ParamTraits<base::DictionaryValue>::GetSize(base::PickleSizer* sizer, |
| 600 const param_type& p) { |
| 601 GetValueSize(sizer, &p, 0); |
| 602 } |
| 603 |
503 void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m, | 604 void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m, |
504 const param_type& p) { | 605 const param_type& p) { |
505 WriteValue(m, &p, 0); | 606 WriteValue(m, &p, 0); |
506 } | 607 } |
507 | 608 |
508 bool ParamTraits<base::DictionaryValue>::Read(const base::Pickle* m, | 609 bool ParamTraits<base::DictionaryValue>::Read(const base::Pickle* m, |
509 base::PickleIterator* iter, | 610 base::PickleIterator* iter, |
510 param_type* r) { | 611 param_type* r) { |
511 int type; | 612 int type; |
512 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) | 613 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 806 } |
706 | 807 |
707 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | 808 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
708 std::string* l) { | 809 std::string* l) { |
709 LogParam(p.GetHandle(), l); | 810 LogParam(p.GetHandle(), l); |
710 l->append(" needs brokering: "); | 811 l->append(" needs brokering: "); |
711 LogParam(p.NeedsBrokering(), l); | 812 LogParam(p.NeedsBrokering(), l); |
712 } | 813 } |
713 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 814 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
714 | 815 |
| 816 void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, |
| 817 const param_type& p) { |
| 818 p.GetSizeForPickle(sizer); |
| 819 } |
| 820 |
715 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { | 821 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { |
716 p.WriteToPickle(m); | 822 p.WriteToPickle(m); |
717 } | 823 } |
718 | 824 |
719 bool ParamTraits<base::FilePath>::Read(const base::Pickle* m, | 825 bool ParamTraits<base::FilePath>::Read(const base::Pickle* m, |
720 base::PickleIterator* iter, | 826 base::PickleIterator* iter, |
721 param_type* r) { | 827 param_type* r) { |
722 return r->ReadFromPickle(iter); | 828 return r->ReadFromPickle(iter); |
723 } | 829 } |
724 | 830 |
725 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { | 831 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { |
726 ParamTraits<base::FilePath::StringType>::Log(p.value(), l); | 832 ParamTraits<base::FilePath::StringType>::Log(p.value(), l); |
727 } | 833 } |
728 | 834 |
| 835 void ParamTraits<base::ListValue>::GetSize(base::PickleSizer* sizer, |
| 836 const param_type& p) { |
| 837 GetValueSize(sizer, &p, 0); |
| 838 } |
| 839 |
729 void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) { | 840 void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) { |
730 WriteValue(m, &p, 0); | 841 WriteValue(m, &p, 0); |
731 } | 842 } |
732 | 843 |
733 bool ParamTraits<base::ListValue>::Read(const base::Pickle* m, | 844 bool ParamTraits<base::ListValue>::Read(const base::Pickle* m, |
734 base::PickleIterator* iter, | 845 base::PickleIterator* iter, |
735 param_type* r) { | 846 param_type* r) { |
736 int type; | 847 int type; |
737 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) | 848 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) |
738 return false; | 849 return false; |
739 | 850 |
740 return ReadListValue(m, iter, r, 0); | 851 return ReadListValue(m, iter, r, 0); |
741 } | 852 } |
742 | 853 |
743 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { | 854 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { |
744 std::string json; | 855 std::string json; |
745 base::JSONWriter::Write(p, &json); | 856 base::JSONWriter::Write(p, &json); |
746 l->append(json); | 857 l->append(json); |
747 } | 858 } |
748 | 859 |
| 860 void ParamTraits<base::NullableString16>::GetSize(base::PickleSizer* sizer, |
| 861 const param_type& p) { |
| 862 GetParamSize(sizer, p.string()); |
| 863 GetParamSize(sizer, p.is_null()); |
| 864 } |
| 865 |
749 void ParamTraits<base::NullableString16>::Write(base::Pickle* m, | 866 void ParamTraits<base::NullableString16>::Write(base::Pickle* m, |
750 const param_type& p) { | 867 const param_type& p) { |
751 WriteParam(m, p.string()); | 868 WriteParam(m, p.string()); |
752 WriteParam(m, p.is_null()); | 869 WriteParam(m, p.is_null()); |
753 } | 870 } |
754 | 871 |
755 bool ParamTraits<base::NullableString16>::Read(const base::Pickle* m, | 872 bool ParamTraits<base::NullableString16>::Read(const base::Pickle* m, |
756 base::PickleIterator* iter, | 873 base::PickleIterator* iter, |
757 param_type* r) { | 874 param_type* r) { |
758 base::string16 string; | 875 base::string16 string; |
759 if (!ReadParam(m, iter, &string)) | 876 if (!ReadParam(m, iter, &string)) |
760 return false; | 877 return false; |
761 bool is_null; | 878 bool is_null; |
762 if (!ReadParam(m, iter, &is_null)) | 879 if (!ReadParam(m, iter, &is_null)) |
763 return false; | 880 return false; |
764 *r = base::NullableString16(string, is_null); | 881 *r = base::NullableString16(string, is_null); |
765 return true; | 882 return true; |
766 } | 883 } |
767 | 884 |
768 void ParamTraits<base::NullableString16>::Log(const param_type& p, | 885 void ParamTraits<base::NullableString16>::Log(const param_type& p, |
769 std::string* l) { | 886 std::string* l) { |
770 l->append("("); | 887 l->append("("); |
771 LogParam(p.string(), l); | 888 LogParam(p.string(), l); |
772 l->append(", "); | 889 l->append(", "); |
773 LogParam(p.is_null(), l); | 890 LogParam(p.is_null(), l); |
774 l->append(")"); | 891 l->append(")"); |
775 } | 892 } |
776 | 893 |
| 894 void ParamTraits<base::File::Info>::GetSize(base::PickleSizer* sizer, |
| 895 const param_type& p) { |
| 896 GetParamSize(sizer, p.size); |
| 897 GetParamSize(sizer, p.is_directory); |
| 898 GetParamSize(sizer, p.last_modified.ToDoubleT()); |
| 899 GetParamSize(sizer, p.last_accessed.ToDoubleT()); |
| 900 GetParamSize(sizer, p.creation_time.ToDoubleT()); |
| 901 } |
| 902 |
777 void ParamTraits<base::File::Info>::Write(base::Pickle* m, | 903 void ParamTraits<base::File::Info>::Write(base::Pickle* m, |
778 const param_type& p) { | 904 const param_type& p) { |
779 WriteParam(m, p.size); | 905 WriteParam(m, p.size); |
780 WriteParam(m, p.is_directory); | 906 WriteParam(m, p.is_directory); |
781 WriteParam(m, p.last_modified.ToDoubleT()); | 907 WriteParam(m, p.last_modified.ToDoubleT()); |
782 WriteParam(m, p.last_accessed.ToDoubleT()); | 908 WriteParam(m, p.last_accessed.ToDoubleT()); |
783 WriteParam(m, p.creation_time.ToDoubleT()); | 909 WriteParam(m, p.creation_time.ToDoubleT()); |
784 } | 910 } |
785 | 911 |
786 bool ParamTraits<base::File::Info>::Read(const base::Pickle* m, | 912 bool ParamTraits<base::File::Info>::Read(const base::Pickle* m, |
(...skipping 20 matching lines...) Expand all Loading... |
807 LogParam(p.is_directory, l); | 933 LogParam(p.is_directory, l); |
808 l->append(","); | 934 l->append(","); |
809 LogParam(p.last_modified.ToDoubleT(), l); | 935 LogParam(p.last_modified.ToDoubleT(), l); |
810 l->append(","); | 936 l->append(","); |
811 LogParam(p.last_accessed.ToDoubleT(), l); | 937 LogParam(p.last_accessed.ToDoubleT(), l); |
812 l->append(","); | 938 l->append(","); |
813 LogParam(p.creation_time.ToDoubleT(), l); | 939 LogParam(p.creation_time.ToDoubleT(), l); |
814 l->append(")"); | 940 l->append(")"); |
815 } | 941 } |
816 | 942 |
| 943 void ParamTraits<base::Time>::GetSize(base::PickleSizer* sizer, |
| 944 const param_type& p) { |
| 945 sizer->AddInt64(); |
| 946 } |
| 947 |
817 void ParamTraits<base::Time>::Write(base::Pickle* m, const param_type& p) { | 948 void ParamTraits<base::Time>::Write(base::Pickle* m, const param_type& p) { |
818 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 949 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
819 } | 950 } |
820 | 951 |
821 bool ParamTraits<base::Time>::Read(const base::Pickle* m, | 952 bool ParamTraits<base::Time>::Read(const base::Pickle* m, |
822 base::PickleIterator* iter, | 953 base::PickleIterator* iter, |
823 param_type* r) { | 954 param_type* r) { |
824 int64_t value; | 955 int64_t value; |
825 if (!ParamTraits<int64_t>::Read(m, iter, &value)) | 956 if (!ParamTraits<int64_t>::Read(m, iter, &value)) |
826 return false; | 957 return false; |
827 *r = base::Time::FromInternalValue(value); | 958 *r = base::Time::FromInternalValue(value); |
828 return true; | 959 return true; |
829 } | 960 } |
830 | 961 |
831 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { | 962 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { |
832 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 963 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
833 } | 964 } |
834 | 965 |
| 966 void ParamTraits<base::TimeDelta>::GetSize(base::PickleSizer* sizer, |
| 967 const param_type& p) { |
| 968 sizer->AddInt64(); |
| 969 } |
| 970 |
835 void ParamTraits<base::TimeDelta>::Write(base::Pickle* m, const param_type& p) { | 971 void ParamTraits<base::TimeDelta>::Write(base::Pickle* m, const param_type& p) { |
836 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 972 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
837 } | 973 } |
838 | 974 |
839 bool ParamTraits<base::TimeDelta>::Read(const base::Pickle* m, | 975 bool ParamTraits<base::TimeDelta>::Read(const base::Pickle* m, |
840 base::PickleIterator* iter, | 976 base::PickleIterator* iter, |
841 param_type* r) { | 977 param_type* r) { |
842 int64_t value; | 978 int64_t value; |
843 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); | 979 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
844 if (ret) | 980 if (ret) |
845 *r = base::TimeDelta::FromInternalValue(value); | 981 *r = base::TimeDelta::FromInternalValue(value); |
846 | 982 |
847 return ret; | 983 return ret; |
848 } | 984 } |
849 | 985 |
850 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { | 986 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { |
851 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 987 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
852 } | 988 } |
853 | 989 |
| 990 void ParamTraits<base::TimeTicks>::GetSize(base::PickleSizer* sizer, |
| 991 const param_type& p) { |
| 992 sizer->AddInt64(); |
| 993 } |
| 994 |
854 void ParamTraits<base::TimeTicks>::Write(base::Pickle* m, const param_type& p) { | 995 void ParamTraits<base::TimeTicks>::Write(base::Pickle* m, const param_type& p) { |
855 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 996 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
856 } | 997 } |
857 | 998 |
858 bool ParamTraits<base::TimeTicks>::Read(const base::Pickle* m, | 999 bool ParamTraits<base::TimeTicks>::Read(const base::Pickle* m, |
859 base::PickleIterator* iter, | 1000 base::PickleIterator* iter, |
860 param_type* r) { | 1001 param_type* r) { |
861 int64_t value; | 1002 int64_t value; |
862 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); | 1003 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
863 if (ret) | 1004 if (ret) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, | 1036 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, |
896 std::string* l) { | 1037 std::string* l) { |
897 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); | 1038 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); |
898 #if defined(OS_POSIX) | 1039 #if defined(OS_POSIX) |
899 l->append(", "); | 1040 l->append(", "); |
900 ParamTraits<base::FileDescriptor>::Log(p.socket, l); | 1041 ParamTraits<base::FileDescriptor>::Log(p.socket, l); |
901 #endif | 1042 #endif |
902 l->append(")"); | 1043 l->append(")"); |
903 } | 1044 } |
904 | 1045 |
| 1046 void ParamTraits<LogData>::GetSize(base::PickleSizer* sizer, |
| 1047 const param_type& p) { |
| 1048 GetParamSize(sizer, p.channel); |
| 1049 GetParamSize(sizer, p.routing_id); |
| 1050 GetParamSize(sizer, p.type); |
| 1051 GetParamSize(sizer, p.flags); |
| 1052 GetParamSize(sizer, p.sent); |
| 1053 GetParamSize(sizer, p.receive); |
| 1054 GetParamSize(sizer, p.dispatch); |
| 1055 GetParamSize(sizer, p.message_name); |
| 1056 GetParamSize(sizer, p.params); |
| 1057 } |
| 1058 |
905 void ParamTraits<LogData>::Write(base::Pickle* m, const param_type& p) { | 1059 void ParamTraits<LogData>::Write(base::Pickle* m, const param_type& p) { |
906 WriteParam(m, p.channel); | 1060 WriteParam(m, p.channel); |
907 WriteParam(m, p.routing_id); | 1061 WriteParam(m, p.routing_id); |
908 WriteParam(m, p.type); | 1062 WriteParam(m, p.type); |
909 WriteParam(m, p.flags); | 1063 WriteParam(m, p.flags); |
910 WriteParam(m, p.sent); | 1064 WriteParam(m, p.sent); |
911 WriteParam(m, p.receive); | 1065 WriteParam(m, p.receive); |
912 WriteParam(m, p.dispatch); | 1066 WriteParam(m, p.dispatch); |
913 WriteParam(m, p.message_name); | 1067 WriteParam(m, p.message_name); |
914 WriteParam(m, p.params); | 1068 WriteParam(m, p.params); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 | 1126 |
973 r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); | 1127 r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); |
974 return r->WriteBytes(payload, payload_size); | 1128 return r->WriteBytes(payload, payload_size); |
975 } | 1129 } |
976 | 1130 |
977 void ParamTraits<Message>::Log(const Message& p, std::string* l) { | 1131 void ParamTraits<Message>::Log(const Message& p, std::string* l) { |
978 l->append("<IPC::Message>"); | 1132 l->append("<IPC::Message>"); |
979 } | 1133 } |
980 | 1134 |
981 #if defined(OS_WIN) | 1135 #if defined(OS_WIN) |
| 1136 void ParamTraits<HANDLE>::GetSize(base::PickleSizer* sizer, |
| 1137 const param_type& p) { |
| 1138 sizer->AddInt(); |
| 1139 } |
| 1140 |
982 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 | 1141 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 |
983 // bit systems. That's why we use the Windows macros to convert to 32 bits. | 1142 // bit systems. That's why we use the Windows macros to convert to 32 bits. |
984 void ParamTraits<HANDLE>::Write(base::Pickle* m, const param_type& p) { | 1143 void ParamTraits<HANDLE>::Write(base::Pickle* m, const param_type& p) { |
985 m->WriteInt(HandleToLong(p)); | 1144 m->WriteInt(HandleToLong(p)); |
986 } | 1145 } |
987 | 1146 |
988 bool ParamTraits<HANDLE>::Read(const base::Pickle* m, | 1147 bool ParamTraits<HANDLE>::Read(const base::Pickle* m, |
989 base::PickleIterator* iter, | 1148 base::PickleIterator* iter, |
990 param_type* r) { | 1149 param_type* r) { |
991 int32_t temp; | 1150 int32_t temp; |
992 if (!iter->ReadInt(&temp)) | 1151 if (!iter->ReadInt(&temp)) |
993 return false; | 1152 return false; |
994 *r = LongToHandle(temp); | 1153 *r = LongToHandle(temp); |
995 return true; | 1154 return true; |
996 } | 1155 } |
997 | 1156 |
998 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { | 1157 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { |
999 l->append(base::StringPrintf("0x%p", p)); | 1158 l->append(base::StringPrintf("0x%p", p)); |
1000 } | 1159 } |
1001 | 1160 |
| 1161 void ParamTraits<LOGFONT>::GetSize(base::PickleSizer* sizer, |
| 1162 const param_type& p) { |
| 1163 sizer->AddData(sizeof(LOGFONT)); |
| 1164 } |
| 1165 |
1002 void ParamTraits<LOGFONT>::Write(base::Pickle* m, const param_type& p) { | 1166 void ParamTraits<LOGFONT>::Write(base::Pickle* m, const param_type& p) { |
1003 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); | 1167 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); |
1004 } | 1168 } |
1005 | 1169 |
1006 bool ParamTraits<LOGFONT>::Read(const base::Pickle* m, | 1170 bool ParamTraits<LOGFONT>::Read(const base::Pickle* m, |
1007 base::PickleIterator* iter, | 1171 base::PickleIterator* iter, |
1008 param_type* r) { | 1172 param_type* r) { |
1009 const char *data; | 1173 const char *data; |
1010 int data_size = 0; | 1174 int data_size = 0; |
1011 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { | 1175 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { |
1012 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); | 1176 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); |
1013 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { | 1177 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { |
1014 memcpy(r, data, sizeof(LOGFONT)); | 1178 memcpy(r, data, sizeof(LOGFONT)); |
1015 return true; | 1179 return true; |
1016 } | 1180 } |
1017 } | 1181 } |
1018 | 1182 |
1019 NOTREACHED(); | 1183 NOTREACHED(); |
1020 return false; | 1184 return false; |
1021 } | 1185 } |
1022 | 1186 |
1023 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { | 1187 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { |
1024 l->append(base::StringPrintf("<LOGFONT>")); | 1188 l->append(base::StringPrintf("<LOGFONT>")); |
1025 } | 1189 } |
1026 | 1190 |
| 1191 void ParamTraits<MSG>::GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 1192 sizer->AddData(sizeof(MSG)); |
| 1193 } |
| 1194 |
1027 void ParamTraits<MSG>::Write(base::Pickle* m, const param_type& p) { | 1195 void ParamTraits<MSG>::Write(base::Pickle* m, const param_type& p) { |
1028 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); | 1196 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); |
1029 } | 1197 } |
1030 | 1198 |
1031 bool ParamTraits<MSG>::Read(const base::Pickle* m, | 1199 bool ParamTraits<MSG>::Read(const base::Pickle* m, |
1032 base::PickleIterator* iter, | 1200 base::PickleIterator* iter, |
1033 param_type* r) { | 1201 param_type* r) { |
1034 const char *data; | 1202 const char *data; |
1035 int data_size = 0; | 1203 int data_size = 0; |
1036 bool result = iter->ReadData(&data, &data_size); | 1204 bool result = iter->ReadData(&data, &data_size); |
1037 if (result && data_size == sizeof(MSG)) { | 1205 if (result && data_size == sizeof(MSG)) { |
1038 memcpy(r, data, sizeof(MSG)); | 1206 memcpy(r, data, sizeof(MSG)); |
1039 } else { | 1207 } else { |
1040 result = false; | 1208 result = false; |
1041 NOTREACHED(); | 1209 NOTREACHED(); |
1042 } | 1210 } |
1043 | 1211 |
1044 return result; | 1212 return result; |
1045 } | 1213 } |
1046 | 1214 |
1047 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1215 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1048 l->append("<MSG>"); | 1216 l->append("<MSG>"); |
1049 } | 1217 } |
1050 | 1218 |
1051 #endif // OS_WIN | 1219 #endif // OS_WIN |
1052 | 1220 |
1053 } // namespace IPC | 1221 } // namespace IPC |
OLD | NEW |