Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: ipc/ipc_message_utils.h

Issue 2098823003: Add IPC serialization support for base::Optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comment Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 14 #include <memory>
15 #include <set> 15 #include <set>
16 #include <string> 16 #include <string>
17 #include <tuple> 17 #include <tuple>
18 #include <vector> 18 #include <vector>
19 19
20 #include "base/containers/small_map.h" 20 #include "base/containers/small_map.h"
21 #include "base/containers/stack_container.h" 21 #include "base/containers/stack_container.h"
22 #include "base/files/file.h" 22 #include "base/files/file.h"
23 #include "base/format_macros.h" 23 #include "base/format_macros.h"
24 #include "base/memory/scoped_vector.h" 24 #include "base/memory/scoped_vector.h"
25 #include "base/optional.h"
25 #include "base/strings/string16.h" 26 #include "base/strings/string16.h"
26 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
27 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.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"
32 #include "ipc/ipc_sync_message.h" 33 #include "ipc/ipc_sync_message.h"
33 34
34 namespace base { 35 namespace base {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 typedef std::vector<bool> param_type; 368 typedef std::vector<bool> param_type;
368 static void GetSize(base::PickleSizer* sizer, const param_type& p); 369 static void GetSize(base::PickleSizer* sizer, const param_type& p);
369 static void Write(base::Pickle* m, const param_type& p); 370 static void Write(base::Pickle* m, const param_type& p);
370 static bool Read(const base::Pickle* m, 371 static bool Read(const base::Pickle* m,
371 base::PickleIterator* iter, 372 base::PickleIterator* iter,
372 param_type* r); 373 param_type* r);
373 static void Log(const param_type& p, std::string* l); 374 static void Log(const param_type& p, std::string* l);
374 }; 375 };
375 376
376 template <class P> 377 template <class P>
377 struct ParamTraits<std::vector<P> > { 378 struct ParamTraits<std::vector<P>> {
378 typedef std::vector<P> param_type; 379 typedef std::vector<P> param_type;
379 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 380 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
380 GetParamSize(sizer, static_cast<int>(p.size())); 381 GetParamSize(sizer, static_cast<int>(p.size()));
381 for (size_t i = 0; i < p.size(); i++) 382 for (size_t i = 0; i < p.size(); i++)
382 GetParamSize(sizer, p[i]); 383 GetParamSize(sizer, p[i]);
383 } 384 }
384 static void Write(base::Pickle* m, const param_type& p) { 385 static void Write(base::Pickle* m, const param_type& p) {
385 WriteParam(m, static_cast<int>(p.size())); 386 WriteParam(m, static_cast<int>(p.size()));
386 for (size_t i = 0; i < p.size(); i++) 387 for (size_t i = 0; i < p.size(); i++)
387 WriteParam(m, p[i]); 388 WriteParam(m, p[i]);
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 return true; 978 return true;
978 } 979 }
979 static void Log(const param_type& p, std::string* l) { 980 static void Log(const param_type& p, std::string* l) {
980 if (p) 981 if (p)
981 LogParam(*p, l); 982 LogParam(*p, l);
982 else 983 else
983 l->append("NULL"); 984 l->append("NULL");
984 } 985 }
985 }; 986 };
986 987
988 template <class P>
989 struct ParamTraits<base::Optional<P>> {
990 typedef base::Optional<P> param_type;
991 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
992 const bool is_set = static_cast<bool>(p);
993 GetParamSize(sizer, is_set);
994 if (is_set)
995 GetParamSize(sizer, p.value());
996 }
997 static void Write(base::Pickle* m, const param_type& p) {
998 const bool is_set = static_cast<bool>(p);
999 WriteParam(m, is_set);
1000 if (is_set)
1001 WriteParam(m, p.value());
1002 }
1003 static bool Read(const base::Pickle* m,
1004 base::PickleIterator* iter,
1005 param_type* r) {
1006 bool is_set = false;
1007 if (!iter->ReadBool(&is_set))
1008 return false;
1009 if (is_set) {
1010 P value;
1011 if (!ReadParam(m, iter, &value))
1012 return false;
1013 *r = std::move(value);
1014 }
1015 return true;
1016 }
1017 static void Log(const param_type& p, std::string* l) {
1018 if (p)
1019 LogParam(p.value(), l);
1020 else
1021 l->append("(unset)");
1022 }
1023 };
1024
987 // IPC types ParamTraits ------------------------------------------------------- 1025 // IPC types ParamTraits -------------------------------------------------------
988 1026
989 // A ChannelHandle is basically a platform-inspecific wrapper around the 1027 // A ChannelHandle is basically a platform-inspecific wrapper around the
990 // fact that IPC endpoints are handled specially on POSIX. See above comments 1028 // fact that IPC endpoints are handled specially on POSIX. See above comments
991 // on FileDescriptor for more background. 1029 // on FileDescriptor for more background.
992 template<> 1030 template<>
993 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { 1031 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> {
994 typedef ChannelHandle param_type; 1032 typedef ChannelHandle param_type;
995 static void GetSize(base::PickleSizer* sizer, const param_type& p); 1033 static void GetSize(base::PickleSizer* sizer, const param_type& p);
996 static void Write(base::Pickle* m, const param_type& p); 1034 static void Write(base::Pickle* m, const param_type& p);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 template <class ReplyParamType> 1140 template <class ReplyParamType>
1103 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, 1141 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1104 const Message* msg) {} 1142 const Message* msg) {}
1105 1143
1106 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} 1144 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
1107 #endif 1145 #endif
1108 1146
1109 } // namespace IPC 1147 } // namespace IPC
1110 1148
1111 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1149 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_message_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698