| 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 <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/containers/small_map.h" | 14 #include "base/containers/small_map.h" |
| 15 #include "base/files/file.h" | 15 #include "base/files/file.h" |
| 16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
| 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/tuple.h" | 22 #include "base/tuple.h" |
| 22 #include "ipc/ipc_message_start.h" | 23 #include "ipc/ipc_message_start.h" |
| 23 #include "ipc/ipc_param_traits.h" | 24 #include "ipc/ipc_param_traits.h" |
| 24 #include "ipc/ipc_sync_message.h" | 25 #include "ipc/ipc_sync_message.h" |
| 25 | 26 |
| 26 #if defined(COMPILER_GCC) | 27 #if defined(COMPILER_GCC) |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 if (!ReadParam(m, iter, &value)) | 700 if (!ReadParam(m, iter, &value)) |
| 700 return false; | 701 return false; |
| 701 } | 702 } |
| 702 return true; | 703 return true; |
| 703 } | 704 } |
| 704 static void Log(const param_type& p, std::string* l) { | 705 static void Log(const param_type& p, std::string* l) { |
| 705 l->append("<base::SmallMap>"); | 706 l->append("<base::SmallMap>"); |
| 706 } | 707 } |
| 707 }; | 708 }; |
| 708 | 709 |
| 710 template <class P> |
| 711 struct ParamTraits<scoped_ptr<P> > { |
| 712 typedef scoped_ptr<P> param_type; |
| 713 static void Write(Message* m, const param_type& p) { |
| 714 bool valid = !!p; |
| 715 WriteParam(m, valid); |
| 716 if (valid) |
| 717 WriteParam(m, *p); |
| 718 } |
| 719 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 720 bool valid = false; |
| 721 if (!ReadParam(m, iter, &valid)) |
| 722 return false; |
| 723 |
| 724 if (!valid) { |
| 725 r->reset(); |
| 726 return true; |
| 727 } |
| 728 |
| 729 param_type temp(new P()); |
| 730 if (!ReadParam(m, iter, temp.get())) |
| 731 return false; |
| 732 |
| 733 r->swap(temp); |
| 734 return true; |
| 735 } |
| 736 static void Log(const param_type& p, std::string* l) { |
| 737 if (p) |
| 738 LogParam(*p, l); |
| 739 else |
| 740 l->append("NULL"); |
| 741 } |
| 742 }; |
| 743 |
| 709 // IPC types ParamTraits ------------------------------------------------------- | 744 // IPC types ParamTraits ------------------------------------------------------- |
| 710 | 745 |
| 711 // A ChannelHandle is basically a platform-inspecific wrapper around the | 746 // A ChannelHandle is basically a platform-inspecific wrapper around the |
| 712 // fact that IPC endpoints are handled specially on POSIX. See above comments | 747 // fact that IPC endpoints are handled specially on POSIX. See above comments |
| 713 // on FileDescriptor for more background. | 748 // on FileDescriptor for more background. |
| 714 template<> | 749 template<> |
| 715 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { | 750 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { |
| 716 typedef ChannelHandle param_type; | 751 typedef ChannelHandle param_type; |
| 717 static void Write(Message* m, const param_type& p); | 752 static void Write(Message* m, const param_type& p); |
| 718 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 753 static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 template<typename TA, typename TB, typename TC, typename TD, typename TE> | 949 template<typename TA, typename TB, typename TC, typename TD, typename TE> |
| 915 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { | 950 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { |
| 916 ReplyParam p(a, b, c, d, e); | 951 ReplyParam p(a, b, c, d, e); |
| 917 WriteParam(reply, p); | 952 WriteParam(reply, p); |
| 918 } | 953 } |
| 919 }; | 954 }; |
| 920 | 955 |
| 921 } // namespace IPC | 956 } // namespace IPC |
| 922 | 957 |
| 923 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 958 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
| OLD | NEW |