| 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 #ifndef IPC_IPC_MESSAGE_UTILS_H_ | 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_ |
| 6 #define IPC_IPC_MESSAGE_UTILS_H_ | 6 #define IPC_IPC_MESSAGE_UTILS_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 std::string params; | 69 std::string params; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 //----------------------------------------------------------------------------- | 72 //----------------------------------------------------------------------------- |
| 73 | 73 |
| 74 // A dummy struct to place first just to allow leading commas for all | 74 // A dummy struct to place first just to allow leading commas for all |
| 75 // members in the macro-generated constructor initializer lists. | 75 // members in the macro-generated constructor initializer lists. |
| 76 struct NoParams { | 76 struct NoParams { |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Specializations are checked by 'IPC checker' Clang plugin |
| 80 // (see WriteParam() below for the list of allowed types). |
| 81 template <typename... Ts> |
| 82 struct CheckedTuple { |
| 83 typedef base::Tuple<Ts...> Tuple; |
| 84 }; |
| 85 |
| 79 template <class P> | 86 template <class P> |
| 80 static inline void GetParamSize(base::PickleSizer* sizer, const P& p) { | 87 static inline void GetParamSize(base::PickleSizer* sizer, const P& p) { |
| 81 typedef typename SimilarTypeTraits<P>::Type Type; | 88 typedef typename SimilarTypeTraits<P>::Type Type; |
| 82 ParamTraits<Type>::GetSize(sizer, static_cast<const Type&>(p)); | 89 ParamTraits<Type>::GetSize(sizer, static_cast<const Type&>(p)); |
| 83 } | 90 } |
| 84 | 91 |
| 92 // NOT checked by 'IPC checker' Clang plugin. |
| 93 template <class P> |
| 94 static inline void WriteParamUnchecked(base::Pickle* m, const P& p) { |
| 95 typedef typename SimilarTypeTraits<P>::Type Type; |
| 96 ParamTraits<Type>::Write(m, static_cast<const Type& >(p)); |
| 97 } |
| 98 |
| 99 // Checked by 'IPC checker' Clang plugin to enforce the following: |
| 100 // 1. int / unsigned int are allowed when used as is (not through typedef) |
| 101 // 2. long / unsigned long are banned |
| 102 // 3. Any typedefs to the types above are banned except for int32_t/uint32_t |
| 103 // and int64_t/uint64_t (typedefs to these are allowed) |
| 104 // 4. All other types are allowed |
| 85 template <class P> | 105 template <class P> |
| 86 static inline void WriteParam(base::Pickle* m, const P& p) { | 106 static inline void WriteParam(base::Pickle* m, const P& p) { |
| 87 typedef typename SimilarTypeTraits<P>::Type Type; | 107 WriteParamUnchecked(m, p); |
| 88 ParamTraits<Type>::Write(m, static_cast<const Type& >(p)); | |
| 89 } | 108 } |
| 90 | 109 |
| 91 template <class P> | 110 template <class P> |
| 92 static inline bool WARN_UNUSED_RESULT ReadParam(const base::Pickle* m, | 111 static inline bool WARN_UNUSED_RESULT ReadParam(const base::Pickle* m, |
| 93 base::PickleIterator* iter, | 112 base::PickleIterator* iter, |
| 94 P* p) { | 113 P* p) { |
| 95 typedef typename SimilarTypeTraits<P>::Type Type; | 114 typedef typename SimilarTypeTraits<P>::Type Type; |
| 96 return ParamTraits<Type>::Read(m, iter, reinterpret_cast<Type* >(p)); | 115 return ParamTraits<Type>::Read(m, iter, reinterpret_cast<Type* >(p)); |
| 97 } | 116 } |
| 98 | 117 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 struct ParamTraits<std::vector<P> > { | 381 struct ParamTraits<std::vector<P> > { |
| 363 typedef std::vector<P> param_type; | 382 typedef std::vector<P> param_type; |
| 364 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 383 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 365 GetParamSize(sizer, static_cast<int>(p.size())); | 384 GetParamSize(sizer, static_cast<int>(p.size())); |
| 366 for (size_t i = 0; i < p.size(); i++) | 385 for (size_t i = 0; i < p.size(); i++) |
| 367 GetParamSize(sizer, p[i]); | 386 GetParamSize(sizer, p[i]); |
| 368 } | 387 } |
| 369 static void Write(base::Pickle* m, const param_type& p) { | 388 static void Write(base::Pickle* m, const param_type& p) { |
| 370 WriteParam(m, static_cast<int>(p.size())); | 389 WriteParam(m, static_cast<int>(p.size())); |
| 371 for (size_t i = 0; i < p.size(); i++) | 390 for (size_t i = 0; i < p.size(); i++) |
| 372 WriteParam(m, p[i]); | 391 WriteParam<P>(m, p[i]); |
| 373 } | 392 } |
| 374 static bool Read(const base::Pickle* m, | 393 static bool Read(const base::Pickle* m, |
| 375 base::PickleIterator* iter, | 394 base::PickleIterator* iter, |
| 376 param_type* r) { | 395 param_type* r) { |
| 377 int size; | 396 int size; |
| 378 // ReadLength() checks for < 0 itself. | 397 // ReadLength() checks for < 0 itself. |
| 379 if (!iter->ReadLength(&size)) | 398 if (!iter->ReadLength(&size)) |
| 380 return false; | 399 return false; |
| 381 // Resizing beforehand is not safe, see BUG 1006367 for details. | 400 // Resizing beforehand is not safe, see BUG 1006367 for details. |
| 382 if (INT_MAX / sizeof(P) <= static_cast<size_t>(size)) | 401 if (INT_MAX / sizeof(P) <= static_cast<size_t>(size)) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 403 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 422 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 404 GetParamSize(sizer, static_cast<int>(p.size())); | 423 GetParamSize(sizer, static_cast<int>(p.size())); |
| 405 typename param_type::const_iterator iter; | 424 typename param_type::const_iterator iter; |
| 406 for (iter = p.begin(); iter != p.end(); ++iter) | 425 for (iter = p.begin(); iter != p.end(); ++iter) |
| 407 GetParamSize(sizer, *iter); | 426 GetParamSize(sizer, *iter); |
| 408 } | 427 } |
| 409 static void Write(base::Pickle* m, const param_type& p) { | 428 static void Write(base::Pickle* m, const param_type& p) { |
| 410 WriteParam(m, static_cast<int>(p.size())); | 429 WriteParam(m, static_cast<int>(p.size())); |
| 411 typename param_type::const_iterator iter; | 430 typename param_type::const_iterator iter; |
| 412 for (iter = p.begin(); iter != p.end(); ++iter) | 431 for (iter = p.begin(); iter != p.end(); ++iter) |
| 413 WriteParam(m, *iter); | 432 WriteParam<P>(m, *iter); |
| 414 } | 433 } |
| 415 static bool Read(const base::Pickle* m, | 434 static bool Read(const base::Pickle* m, |
| 416 base::PickleIterator* iter, | 435 base::PickleIterator* iter, |
| 417 param_type* r) { | 436 param_type* r) { |
| 418 int size; | 437 int size; |
| 419 if (!iter->ReadLength(&size)) | 438 if (!iter->ReadLength(&size)) |
| 420 return false; | 439 return false; |
| 421 for (int i = 0; i < size; ++i) { | 440 for (int i = 0; i < size; ++i) { |
| 422 P item; | 441 P item; |
| 423 if (!ReadParam(m, iter, &item)) | 442 if (!ReadParam(m, iter, &item)) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 439 typename param_type::const_iterator iter; | 458 typename param_type::const_iterator iter; |
| 440 for (iter = p.begin(); iter != p.end(); ++iter) { | 459 for (iter = p.begin(); iter != p.end(); ++iter) { |
| 441 GetParamSize(sizer, iter->first); | 460 GetParamSize(sizer, iter->first); |
| 442 GetParamSize(sizer, iter->second); | 461 GetParamSize(sizer, iter->second); |
| 443 } | 462 } |
| 444 } | 463 } |
| 445 static void Write(base::Pickle* m, const param_type& p) { | 464 static void Write(base::Pickle* m, const param_type& p) { |
| 446 WriteParam(m, static_cast<int>(p.size())); | 465 WriteParam(m, static_cast<int>(p.size())); |
| 447 typename param_type::const_iterator iter; | 466 typename param_type::const_iterator iter; |
| 448 for (iter = p.begin(); iter != p.end(); ++iter) { | 467 for (iter = p.begin(); iter != p.end(); ++iter) { |
| 449 WriteParam(m, iter->first); | 468 WriteParam<K>(m, iter->first); |
| 450 WriteParam(m, iter->second); | 469 WriteParam<V>(m, iter->second); |
| 451 } | 470 } |
| 452 } | 471 } |
| 453 static bool Read(const base::Pickle* m, | 472 static bool Read(const base::Pickle* m, |
| 454 base::PickleIterator* iter, | 473 base::PickleIterator* iter, |
| 455 param_type* r) { | 474 param_type* r) { |
| 456 int size; | 475 int size; |
| 457 if (!ReadParam(m, iter, &size) || size < 0) | 476 if (!ReadParam(m, iter, &size) || size < 0) |
| 458 return false; | 477 return false; |
| 459 for (int i = 0; i < size; ++i) { | 478 for (int i = 0; i < size; ++i) { |
| 460 K k; | 479 K k; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 472 }; | 491 }; |
| 473 | 492 |
| 474 template <class A, class B> | 493 template <class A, class B> |
| 475 struct ParamTraits<std::pair<A, B> > { | 494 struct ParamTraits<std::pair<A, B> > { |
| 476 typedef std::pair<A, B> param_type; | 495 typedef std::pair<A, B> param_type; |
| 477 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 496 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 478 GetParamSize(sizer, p.first); | 497 GetParamSize(sizer, p.first); |
| 479 GetParamSize(sizer, p.second); | 498 GetParamSize(sizer, p.second); |
| 480 } | 499 } |
| 481 static void Write(base::Pickle* m, const param_type& p) { | 500 static void Write(base::Pickle* m, const param_type& p) { |
| 482 WriteParam(m, p.first); | 501 WriteParam<A>(m, p.first); |
| 483 WriteParam(m, p.second); | 502 WriteParam<B>(m, p.second); |
| 484 } | 503 } |
| 485 static bool Read(const base::Pickle* m, | 504 static bool Read(const base::Pickle* m, |
| 486 base::PickleIterator* iter, | 505 base::PickleIterator* iter, |
| 487 param_type* r) { | 506 param_type* r) { |
| 488 return ReadParam(m, iter, &r->first) && ReadParam(m, iter, &r->second); | 507 return ReadParam(m, iter, &r->first) && ReadParam(m, iter, &r->second); |
| 489 } | 508 } |
| 490 static void Log(const param_type& p, std::string* l) { | 509 static void Log(const param_type& p, std::string* l) { |
| 491 l->append("("); | 510 l->append("("); |
| 492 LogParam(p.first, l); | 511 LogParam(p.first, l); |
| 493 l->append(", "); | 512 l->append(", "); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 } | 681 } |
| 663 }; | 682 }; |
| 664 | 683 |
| 665 template <class A> | 684 template <class A> |
| 666 struct ParamTraits<std::tuple<A>> { | 685 struct ParamTraits<std::tuple<A>> { |
| 667 typedef std::tuple<A> param_type; | 686 typedef std::tuple<A> param_type; |
| 668 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 687 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 669 GetParamSize(sizer, base::get<0>(p)); | 688 GetParamSize(sizer, base::get<0>(p)); |
| 670 } | 689 } |
| 671 static void Write(base::Pickle* m, const param_type& p) { | 690 static void Write(base::Pickle* m, const param_type& p) { |
| 672 WriteParam(m, base::get<0>(p)); | 691 WriteParam<A>(m, base::get<0>(p)); |
| 673 } | 692 } |
| 674 static bool Read(const base::Pickle* m, | 693 static bool Read(const base::Pickle* m, |
| 675 base::PickleIterator* iter, | 694 base::PickleIterator* iter, |
| 676 param_type* r) { | 695 param_type* r) { |
| 677 return ReadParam(m, iter, &base::get<0>(*r)); | 696 return ReadParam(m, iter, &base::get<0>(*r)); |
| 678 } | 697 } |
| 679 static void Log(const param_type& p, std::string* l) { | 698 static void Log(const param_type& p, std::string* l) { |
| 680 LogParam(base::get<0>(p), l); | 699 LogParam(base::get<0>(p), l); |
| 681 } | 700 } |
| 682 }; | 701 }; |
| 683 | 702 |
| 684 template <class A, class B> | 703 template <class A, class B> |
| 685 struct ParamTraits<std::tuple<A, B>> { | 704 struct ParamTraits<std::tuple<A, B>> { |
| 686 typedef std::tuple<A, B> param_type; | 705 typedef std::tuple<A, B> param_type; |
| 687 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 706 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 688 GetParamSize(sizer, base::get<0>(p)); | 707 GetParamSize(sizer, base::get<0>(p)); |
| 689 GetParamSize(sizer, base::get<1>(p)); | 708 GetParamSize(sizer, base::get<1>(p)); |
| 690 } | 709 } |
| 691 static void Write(base::Pickle* m, const param_type& p) { | 710 static void Write(base::Pickle* m, const param_type& p) { |
| 692 WriteParam(m, base::get<0>(p)); | 711 WriteParam<A>(m, base::get<0>(p)); |
| 693 WriteParam(m, base::get<1>(p)); | 712 WriteParam<B>(m, base::get<1>(p)); |
| 694 } | 713 } |
| 695 static bool Read(const base::Pickle* m, | 714 static bool Read(const base::Pickle* m, |
| 696 base::PickleIterator* iter, | 715 base::PickleIterator* iter, |
| 697 param_type* r) { | 716 param_type* r) { |
| 698 return (ReadParam(m, iter, &base::get<0>(*r)) && | 717 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 699 ReadParam(m, iter, &base::get<1>(*r))); | 718 ReadParam(m, iter, &base::get<1>(*r))); |
| 700 } | 719 } |
| 701 static void Log(const param_type& p, std::string* l) { | 720 static void Log(const param_type& p, std::string* l) { |
| 702 LogParam(base::get<0>(p), l); | 721 LogParam(base::get<0>(p), l); |
| 703 l->append(", "); | 722 l->append(", "); |
| 704 LogParam(base::get<1>(p), l); | 723 LogParam(base::get<1>(p), l); |
| 705 } | 724 } |
| 706 }; | 725 }; |
| 707 | 726 |
| 708 template <class A, class B, class C> | 727 template <class A, class B, class C> |
| 709 struct ParamTraits<std::tuple<A, B, C>> { | 728 struct ParamTraits<std::tuple<A, B, C>> { |
| 710 typedef std::tuple<A, B, C> param_type; | 729 typedef std::tuple<A, B, C> param_type; |
| 711 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 730 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 712 GetParamSize(sizer, base::get<0>(p)); | 731 GetParamSize(sizer, base::get<0>(p)); |
| 713 GetParamSize(sizer, base::get<1>(p)); | 732 GetParamSize(sizer, base::get<1>(p)); |
| 714 GetParamSize(sizer, base::get<2>(p)); | 733 GetParamSize(sizer, base::get<2>(p)); |
| 715 } | 734 } |
| 716 static void Write(base::Pickle* m, const param_type& p) { | 735 static void Write(base::Pickle* m, const param_type& p) { |
| 717 WriteParam(m, base::get<0>(p)); | 736 WriteParam<A>(m, base::get<0>(p)); |
| 718 WriteParam(m, base::get<1>(p)); | 737 WriteParam<B>(m, base::get<1>(p)); |
| 719 WriteParam(m, base::get<2>(p)); | 738 WriteParam<C>(m, base::get<2>(p)); |
| 720 } | 739 } |
| 721 static bool Read(const base::Pickle* m, | 740 static bool Read(const base::Pickle* m, |
| 722 base::PickleIterator* iter, | 741 base::PickleIterator* iter, |
| 723 param_type* r) { | 742 param_type* r) { |
| 724 return (ReadParam(m, iter, &base::get<0>(*r)) && | 743 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 725 ReadParam(m, iter, &base::get<1>(*r)) && | 744 ReadParam(m, iter, &base::get<1>(*r)) && |
| 726 ReadParam(m, iter, &base::get<2>(*r))); | 745 ReadParam(m, iter, &base::get<2>(*r))); |
| 727 } | 746 } |
| 728 static void Log(const param_type& p, std::string* l) { | 747 static void Log(const param_type& p, std::string* l) { |
| 729 LogParam(base::get<0>(p), l); | 748 LogParam(base::get<0>(p), l); |
| 730 l->append(", "); | 749 l->append(", "); |
| 731 LogParam(base::get<1>(p), l); | 750 LogParam(base::get<1>(p), l); |
| 732 l->append(", "); | 751 l->append(", "); |
| 733 LogParam(base::get<2>(p), l); | 752 LogParam(base::get<2>(p), l); |
| 734 } | 753 } |
| 735 }; | 754 }; |
| 736 | 755 |
| 737 template <class A, class B, class C, class D> | 756 template <class A, class B, class C, class D> |
| 738 struct ParamTraits<std::tuple<A, B, C, D>> { | 757 struct ParamTraits<std::tuple<A, B, C, D>> { |
| 739 typedef std::tuple<A, B, C, D> param_type; | 758 typedef std::tuple<A, B, C, D> param_type; |
| 740 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 759 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 741 GetParamSize(sizer, base::get<0>(p)); | 760 GetParamSize(sizer, base::get<0>(p)); |
| 742 GetParamSize(sizer, base::get<1>(p)); | 761 GetParamSize(sizer, base::get<1>(p)); |
| 743 GetParamSize(sizer, base::get<2>(p)); | 762 GetParamSize(sizer, base::get<2>(p)); |
| 744 GetParamSize(sizer, base::get<3>(p)); | 763 GetParamSize(sizer, base::get<3>(p)); |
| 745 } | 764 } |
| 746 static void Write(base::Pickle* m, const param_type& p) { | 765 static void Write(base::Pickle* m, const param_type& p) { |
| 747 WriteParam(m, base::get<0>(p)); | 766 WriteParam<A>(m, base::get<0>(p)); |
| 748 WriteParam(m, base::get<1>(p)); | 767 WriteParam<B>(m, base::get<1>(p)); |
| 749 WriteParam(m, base::get<2>(p)); | 768 WriteParam<C>(m, base::get<2>(p)); |
| 750 WriteParam(m, base::get<3>(p)); | 769 WriteParam<D>(m, base::get<3>(p)); |
| 751 } | 770 } |
| 752 static bool Read(const base::Pickle* m, | 771 static bool Read(const base::Pickle* m, |
| 753 base::PickleIterator* iter, | 772 base::PickleIterator* iter, |
| 754 param_type* r) { | 773 param_type* r) { |
| 755 return (ReadParam(m, iter, &base::get<0>(*r)) && | 774 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 756 ReadParam(m, iter, &base::get<1>(*r)) && | 775 ReadParam(m, iter, &base::get<1>(*r)) && |
| 757 ReadParam(m, iter, &base::get<2>(*r)) && | 776 ReadParam(m, iter, &base::get<2>(*r)) && |
| 758 ReadParam(m, iter, &base::get<3>(*r))); | 777 ReadParam(m, iter, &base::get<3>(*r))); |
| 759 } | 778 } |
| 760 static void Log(const param_type& p, std::string* l) { | 779 static void Log(const param_type& p, std::string* l) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 772 struct ParamTraits<std::tuple<A, B, C, D, E>> { | 791 struct ParamTraits<std::tuple<A, B, C, D, E>> { |
| 773 typedef std::tuple<A, B, C, D, E> param_type; | 792 typedef std::tuple<A, B, C, D, E> param_type; |
| 774 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 793 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 775 GetParamSize(sizer, base::get<0>(p)); | 794 GetParamSize(sizer, base::get<0>(p)); |
| 776 GetParamSize(sizer, base::get<1>(p)); | 795 GetParamSize(sizer, base::get<1>(p)); |
| 777 GetParamSize(sizer, base::get<2>(p)); | 796 GetParamSize(sizer, base::get<2>(p)); |
| 778 GetParamSize(sizer, base::get<3>(p)); | 797 GetParamSize(sizer, base::get<3>(p)); |
| 779 GetParamSize(sizer, base::get<4>(p)); | 798 GetParamSize(sizer, base::get<4>(p)); |
| 780 } | 799 } |
| 781 static void Write(base::Pickle* m, const param_type& p) { | 800 static void Write(base::Pickle* m, const param_type& p) { |
| 782 WriteParam(m, base::get<0>(p)); | 801 WriteParam<A>(m, base::get<0>(p)); |
| 783 WriteParam(m, base::get<1>(p)); | 802 WriteParam<B>(m, base::get<1>(p)); |
| 784 WriteParam(m, base::get<2>(p)); | 803 WriteParam<C>(m, base::get<2>(p)); |
| 785 WriteParam(m, base::get<3>(p)); | 804 WriteParam<D>(m, base::get<3>(p)); |
| 786 WriteParam(m, base::get<4>(p)); | 805 WriteParam<E>(m, base::get<4>(p)); |
| 787 } | 806 } |
| 788 static bool Read(const base::Pickle* m, | 807 static bool Read(const base::Pickle* m, |
| 789 base::PickleIterator* iter, | 808 base::PickleIterator* iter, |
| 790 param_type* r) { | 809 param_type* r) { |
| 791 return (ReadParam(m, iter, &base::get<0>(*r)) && | 810 return (ReadParam(m, iter, &base::get<0>(*r)) && |
| 792 ReadParam(m, iter, &base::get<1>(*r)) && | 811 ReadParam(m, iter, &base::get<1>(*r)) && |
| 793 ReadParam(m, iter, &base::get<2>(*r)) && | 812 ReadParam(m, iter, &base::get<2>(*r)) && |
| 794 ReadParam(m, iter, &base::get<3>(*r)) && | 813 ReadParam(m, iter, &base::get<3>(*r)) && |
| 795 ReadParam(m, iter, &base::get<4>(*r))); | 814 ReadParam(m, iter, &base::get<4>(*r))); |
| 796 } | 815 } |
| 797 static void Log(const param_type& p, std::string* l) { | 816 static void Log(const param_type& p, std::string* l) { |
| 798 LogParam(base::get<0>(p), l); | 817 LogParam(base::get<0>(p), l); |
| 799 l->append(", "); | 818 l->append(", "); |
| 800 LogParam(base::get<1>(p), l); | 819 LogParam(base::get<1>(p), l); |
| 801 l->append(", "); | 820 l->append(", "); |
| 802 LogParam(base::get<2>(p), l); | 821 LogParam(base::get<2>(p), l); |
| 803 l->append(", "); | 822 l->append(", "); |
| 804 LogParam(base::get<3>(p), l); | 823 LogParam(base::get<3>(p), l); |
| 805 l->append(", "); | 824 l->append(", "); |
| 806 LogParam(base::get<4>(p), l); | 825 LogParam(base::get<4>(p), l); |
| 807 } | 826 } |
| 808 }; | 827 }; |
| 809 | 828 |
| 810 template<class P> | 829 template<class P> |
| 811 struct ParamTraits<ScopedVector<P> > { | 830 struct ParamTraits<ScopedVector<P> > { |
| 812 typedef ScopedVector<P> param_type; | 831 typedef ScopedVector<P> param_type; |
| 813 static void Write(base::Pickle* m, const param_type& p) { | 832 static void Write(base::Pickle* m, const param_type& p) { |
| 814 WriteParam(m, static_cast<int>(p.size())); | 833 WriteParam(m, static_cast<int>(p.size())); |
| 815 for (size_t i = 0; i < p.size(); i++) | 834 for (size_t i = 0; i < p.size(); i++) |
| 816 WriteParam(m, *p[i]); | 835 WriteParam<P>(m, *p[i]); |
| 817 } | 836 } |
| 818 static bool Read(const base::Pickle* m, | 837 static bool Read(const base::Pickle* m, |
| 819 base::PickleIterator* iter, | 838 base::PickleIterator* iter, |
| 820 param_type* r) { | 839 param_type* r) { |
| 821 int size = 0; | 840 int size = 0; |
| 822 if (!iter->ReadLength(&size)) | 841 if (!iter->ReadLength(&size)) |
| 823 return false; | 842 return false; |
| 824 if (INT_MAX/sizeof(P) <= static_cast<size_t>(size)) | 843 if (INT_MAX/sizeof(P) <= static_cast<size_t>(size)) |
| 825 return false; | 844 return false; |
| 826 r->resize(size); | 845 r->resize(size); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 844 struct ParamTraits<base::StackVector<P, stack_capacity> > { | 863 struct ParamTraits<base::StackVector<P, stack_capacity> > { |
| 845 typedef base::StackVector<P, stack_capacity> param_type; | 864 typedef base::StackVector<P, stack_capacity> param_type; |
| 846 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 865 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 847 GetParamSize(sizer, static_cast<int>(p->size())); | 866 GetParamSize(sizer, static_cast<int>(p->size())); |
| 848 for (size_t i = 0; i < p->size(); i++) | 867 for (size_t i = 0; i < p->size(); i++) |
| 849 GetParamSize(sizer, p[i]); | 868 GetParamSize(sizer, p[i]); |
| 850 } | 869 } |
| 851 static void Write(base::Pickle* m, const param_type& p) { | 870 static void Write(base::Pickle* m, const param_type& p) { |
| 852 WriteParam(m, static_cast<int>(p->size())); | 871 WriteParam(m, static_cast<int>(p->size())); |
| 853 for (size_t i = 0; i < p->size(); i++) | 872 for (size_t i = 0; i < p->size(); i++) |
| 854 WriteParam(m, p[i]); | 873 WriteParam<P>(m, p[i]); |
| 855 } | 874 } |
| 856 static bool Read(const base::Pickle* m, | 875 static bool Read(const base::Pickle* m, |
| 857 base::PickleIterator* iter, | 876 base::PickleIterator* iter, |
| 858 param_type* r) { | 877 param_type* r) { |
| 859 int size; | 878 int size; |
| 860 // ReadLength() checks for < 0 itself. | 879 // ReadLength() checks for < 0 itself. |
| 861 if (!iter->ReadLength(&size)) | 880 if (!iter->ReadLength(&size)) |
| 862 return false; | 881 return false; |
| 863 // Sanity check for the vector size. | 882 // Sanity check for the vector size. |
| 864 if (INT_MAX / sizeof(P) <= static_cast<size_t>(size)) | 883 if (INT_MAX / sizeof(P) <= static_cast<size_t>(size)) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 893 typename param_type::const_iterator iter; | 912 typename param_type::const_iterator iter; |
| 894 for (iter = p.begin(); iter != p.end(); ++iter) { | 913 for (iter = p.begin(); iter != p.end(); ++iter) { |
| 895 GetParamSize(sizer, iter->first); | 914 GetParamSize(sizer, iter->first); |
| 896 GetParamSize(sizer, iter->second); | 915 GetParamSize(sizer, iter->second); |
| 897 } | 916 } |
| 898 } | 917 } |
| 899 static void Write(base::Pickle* m, const param_type& p) { | 918 static void Write(base::Pickle* m, const param_type& p) { |
| 900 WriteParam(m, static_cast<int>(p.size())); | 919 WriteParam(m, static_cast<int>(p.size())); |
| 901 typename param_type::const_iterator iter; | 920 typename param_type::const_iterator iter; |
| 902 for (iter = p.begin(); iter != p.end(); ++iter) { | 921 for (iter = p.begin(); iter != p.end(); ++iter) { |
| 903 WriteParam(m, iter->first); | 922 // We expect that types for 'first' and 'second' are specified in |
| 904 WriteParam(m, iter->second); | 923 // the NormalMap instantiation and hence are checked by CheckedTuple. |
| 924 // So it's safe to skip checks here. |
| 925 WriteParamUnchecked(m, iter->first); |
| 926 WriteParamUnchecked(m, iter->second); |
| 905 } | 927 } |
| 906 } | 928 } |
| 907 static bool Read(const base::Pickle* m, | 929 static bool Read(const base::Pickle* m, |
| 908 base::PickleIterator* iter, | 930 base::PickleIterator* iter, |
| 909 param_type* r) { | 931 param_type* r) { |
| 910 int size; | 932 int size; |
| 911 if (!iter->ReadLength(&size)) | 933 if (!iter->ReadLength(&size)) |
| 912 return false; | 934 return false; |
| 913 for (int i = 0; i < size; ++i) { | 935 for (int i = 0; i < size; ++i) { |
| 914 K key; | 936 K key; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 931 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 953 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 932 bool valid = !!p; | 954 bool valid = !!p; |
| 933 GetParamSize(sizer, valid); | 955 GetParamSize(sizer, valid); |
| 934 if (valid) | 956 if (valid) |
| 935 GetParamSize(sizer, *p); | 957 GetParamSize(sizer, *p); |
| 936 } | 958 } |
| 937 static void Write(base::Pickle* m, const param_type& p) { | 959 static void Write(base::Pickle* m, const param_type& p) { |
| 938 bool valid = !!p; | 960 bool valid = !!p; |
| 939 WriteParam(m, valid); | 961 WriteParam(m, valid); |
| 940 if (valid) | 962 if (valid) |
| 941 WriteParam(m, *p); | 963 WriteParam<P>(m, *p); |
| 942 } | 964 } |
| 943 static bool Read(const base::Pickle* m, | 965 static bool Read(const base::Pickle* m, |
| 944 base::PickleIterator* iter, | 966 base::PickleIterator* iter, |
| 945 param_type* r) { | 967 param_type* r) { |
| 946 bool valid = false; | 968 bool valid = false; |
| 947 if (!ReadParam(m, iter, &valid)) | 969 if (!ReadParam(m, iter, &valid)) |
| 948 return false; | 970 return false; |
| 949 | 971 |
| 950 if (!valid) { | 972 if (!valid) { |
| 951 r->reset(); | 973 r->reset(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 template <class ReplyParamType> | 1106 template <class ReplyParamType> |
| 1085 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, | 1107 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, |
| 1086 const Message* msg) {} | 1108 const Message* msg) {} |
| 1087 | 1109 |
| 1088 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} | 1110 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} |
| 1089 #endif | 1111 #endif |
| 1090 | 1112 |
| 1091 } // namespace IPC | 1113 } // namespace IPC |
| 1092 | 1114 |
| 1093 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1115 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
| OLD | NEW |