Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <map> | 13 #include <map> |
| 14 #include <set> | 14 #include <set> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/containers/small_map.h" | 18 #include "base/containers/small_map.h" |
| 19 #include "base/containers/stack_container.h" | 19 #include "base/containers/stack_container.h" |
| 20 #include "base/files/file.h" | 20 #include "base/files/file.h" |
| 21 #include "base/format_macros.h" | 21 #include "base/format_macros.h" |
| 22 #include "base/id_type.h" | |
| 22 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
| 23 #include "base/memory/scoped_vector.h" | 24 #include "base/memory/scoped_vector.h" |
| 24 #include "base/strings/string16.h" | 25 #include "base/strings/string16.h" |
| 25 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 26 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 27 #include "base/tuple.h" | 28 #include "base/tuple.h" |
| 28 #include "build/build_config.h" | 29 #include "build/build_config.h" |
| 29 #include "ipc/brokerable_attachment.h" | 30 #include "ipc/brokerable_attachment.h" |
| 30 #include "ipc/ipc_message_start.h" | 31 #include "ipc/ipc_message_start.h" |
| 31 #include "ipc/ipc_param_traits.h" | 32 #include "ipc/ipc_param_traits.h" |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 return true; | 970 return true; |
| 970 } | 971 } |
| 971 static void Log(const param_type& p, std::string* l) { | 972 static void Log(const param_type& p, std::string* l) { |
| 972 if (p) | 973 if (p) |
| 973 LogParam(*p, l); | 974 LogParam(*p, l); |
| 974 else | 975 else |
| 975 l->append("NULL"); | 976 l->append("NULL"); |
| 976 } | 977 } |
| 977 }; | 978 }; |
| 978 | 979 |
| 980 template <typename TypeMarker, typename WrappedType, WrappedType kInvalidValue> | |
| 981 struct ParamTraits<base::IdType<TypeMarker, WrappedType, kInvalidValue>> { | |
| 982 typedef base::IdType<TypeMarker, WrappedType, kInvalidValue> param_type; | |
| 983 typedef ParamTraits<WrappedType> base_param_traits; | |
| 984 static void Write(base::Pickle* m, const param_type& p) { | |
| 985 base_param_traits::Write(m, p.GetUnsafeValue()); | |
| 986 } | |
| 987 static bool Read(const base::Pickle* m, | |
| 988 base::PickleIterator* iter, | |
| 989 param_type* r) { | |
| 990 WrappedType value; | |
| 991 if (!base_param_traits::Read(m, iter, &value)) | |
| 992 return false; | |
| 993 *r = param_type::FromUnsafeValue(value); | |
| 994 return true; | |
| 995 } | |
| 996 static void Log(const param_type& p, std::string* l) { | |
| 997 base_param_traits::Log(p.GetUnsafeValue(), l); | |
| 998 } | |
| 999 }; | |
|
Nico
2016/02/09 20:04:29
This isn't more type-safe than just sending the in
Łukasz Anforowicz
2016/02/09 23:06:32
It *is* more type-safe to use gpu::CommandBufferId
| |
| 1000 | |
| 979 // IPC types ParamTraits ------------------------------------------------------- | 1001 // IPC types ParamTraits ------------------------------------------------------- |
| 980 | 1002 |
| 981 // A ChannelHandle is basically a platform-inspecific wrapper around the | 1003 // A ChannelHandle is basically a platform-inspecific wrapper around the |
| 982 // fact that IPC endpoints are handled specially on POSIX. See above comments | 1004 // fact that IPC endpoints are handled specially on POSIX. See above comments |
| 983 // on FileDescriptor for more background. | 1005 // on FileDescriptor for more background. |
| 984 template<> | 1006 template<> |
| 985 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { | 1007 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { |
| 986 typedef ChannelHandle param_type; | 1008 typedef ChannelHandle param_type; |
| 987 static void Write(base::Pickle* m, const param_type& p); | 1009 static void Write(base::Pickle* m, const param_type& p); |
| 988 static bool Read(const base::Pickle* m, | 1010 static bool Read(const base::Pickle* m, |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 template <typename... Ts> | 1199 template <typename... Ts> |
| 1178 static void WriteReplyParams(Message* reply, Ts... args) { | 1200 static void WriteReplyParams(Message* reply, Ts... args) { |
| 1179 ReplyParam p(args...); | 1201 ReplyParam p(args...); |
| 1180 WriteParam(reply, p); | 1202 WriteParam(reply, p); |
| 1181 } | 1203 } |
| 1182 }; | 1204 }; |
| 1183 | 1205 |
| 1184 } // namespace IPC | 1206 } // namespace IPC |
| 1185 | 1207 |
| 1186 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1208 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
| OLD | NEW |