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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <map> | 11 #include <map> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/containers/small_map.h" | 16 #include "base/containers/small_map.h" |
17 #include "base/containers/stack_container.h" | 17 #include "base/containers/stack_container.h" |
18 #include "base/files/file.h" | 18 #include "base/files/file.h" |
19 #include "base/format_macros.h" | 19 #include "base/format_macros.h" |
| 20 #include "base/id_type.h" |
20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
21 #include "base/memory/scoped_vector.h" | 22 #include "base/memory/scoped_vector.h" |
22 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
24 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
25 #include "base/tuple.h" | 26 #include "base/tuple.h" |
26 #include "ipc/brokerable_attachment.h" | 27 #include "ipc/brokerable_attachment.h" |
27 #include "ipc/ipc_message_start.h" | 28 #include "ipc/ipc_message_start.h" |
28 #include "ipc/ipc_param_traits.h" | 29 #include "ipc/ipc_param_traits.h" |
29 #include "ipc/ipc_sync_message.h" | 30 #include "ipc/ipc_sync_message.h" |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 return true; | 852 return true; |
852 } | 853 } |
853 static void Log(const param_type& p, std::string* l) { | 854 static void Log(const param_type& p, std::string* l) { |
854 if (p) | 855 if (p) |
855 LogParam(*p, l); | 856 LogParam(*p, l); |
856 else | 857 else |
857 l->append("NULL"); | 858 l->append("NULL"); |
858 } | 859 } |
859 }; | 860 }; |
860 | 861 |
| 862 template <typename TypeBeingIdentified, |
| 863 typename WrappedType, |
| 864 WrappedType kInvalidValue> |
| 865 struct ParamTraits< |
| 866 base::IdType<TypeBeingIdentified, WrappedType, kInvalidValue>> { |
| 867 typedef base::IdType<TypeBeingIdentified, WrappedType, kInvalidValue> |
| 868 param_type; |
| 869 typedef ParamTraits<WrappedType> base_param_traits; |
| 870 static void Write(Message* m, const param_type& p) { |
| 871 base_param_traits::Write(m, p.GetUnsafeValue()); |
| 872 } |
| 873 static bool Read(const Message* m, |
| 874 base::PickleIterator* iter, |
| 875 param_type* r) { |
| 876 WrappedType value; |
| 877 if (!base_param_traits::Read(m, iter, &value)) |
| 878 return false; |
| 879 *r = param_type::FromUnsafeValue(value); |
| 880 return true; |
| 881 } |
| 882 static void Log(const param_type& p, std::string* l) { |
| 883 base_param_traits::Log(p.GetUnsafeValue(), l); |
| 884 } |
| 885 }; |
| 886 |
861 // IPC types ParamTraits ------------------------------------------------------- | 887 // IPC types ParamTraits ------------------------------------------------------- |
862 | 888 |
863 // A ChannelHandle is basically a platform-inspecific wrapper around the | 889 // A ChannelHandle is basically a platform-inspecific wrapper around the |
864 // fact that IPC endpoints are handled specially on POSIX. See above comments | 890 // fact that IPC endpoints are handled specially on POSIX. See above comments |
865 // on FileDescriptor for more background. | 891 // on FileDescriptor for more background. |
866 template<> | 892 template<> |
867 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { | 893 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { |
868 typedef ChannelHandle param_type; | 894 typedef ChannelHandle param_type; |
869 static void Write(Message* m, const param_type& p); | 895 static void Write(Message* m, const param_type& p); |
870 static bool Read(const Message* m, | 896 static bool Read(const Message* m, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 template <typename... Ts> | 1081 template <typename... Ts> |
1056 static void WriteReplyParams(Message* reply, Ts... args) { | 1082 static void WriteReplyParams(Message* reply, Ts... args) { |
1057 ReplyParam p(args...); | 1083 ReplyParam p(args...); |
1058 WriteParam(reply, p); | 1084 WriteParam(reply, p); |
1059 } | 1085 } |
1060 }; | 1086 }; |
1061 | 1087 |
1062 } // namespace IPC | 1088 } // namespace IPC |
1063 | 1089 |
1064 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1090 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
OLD | NEW |