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/files/file.h" | 15 #include "base/files/file.h" |
15 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
16 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/tuple.h" | 21 #include "base/tuple.h" |
21 #include "ipc/ipc_message_start.h" | 22 #include "ipc/ipc_message_start.h" |
22 #include "ipc/ipc_param_traits.h" | 23 #include "ipc/ipc_param_traits.h" |
23 #include "ipc/ipc_sync_message.h" | 24 #include "ipc/ipc_sync_message.h" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 } | 664 } |
664 static void Log(const param_type& p, std::string* l) { | 665 static void Log(const param_type& p, std::string* l) { |
665 for (size_t i = 0; i < p.size(); ++i) { | 666 for (size_t i = 0; i < p.size(); ++i) { |
666 if (i != 0) | 667 if (i != 0) |
667 l->append(" "); | 668 l->append(" "); |
668 LogParam(*p[i], l); | 669 LogParam(*p[i], l); |
669 } | 670 } |
670 } | 671 } |
671 }; | 672 }; |
672 | 673 |
674 template <typename NormalMap, | |
675 int kArraySize, | |
676 typename EqualKey, | |
677 typename MapInit> | |
678 struct ParamTraits<base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> > { | |
679 typedef base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> param_type; | |
680 typedef typename param_type::key_type K; | |
681 typedef typename param_type::data_type V; | |
682 static void Write(Message* m, const param_type& p) { | |
683 WriteParam(m, static_cast<int>(p.size())); | |
Tom Sepez
2014/02/14 19:05:37
we ought to be careful here if p.size() > INT_MAX,
Tom Sepez
2014/02/14 19:14:42
Though std::map has this same issue, so this is pr
jdduke (slow)
2014/02/18 01:42:21
Good point. I think some other container types ma
| |
684 typename param_type::const_iterator iter; | |
685 for (iter = p.begin(); iter != p.end(); ++iter) { | |
686 WriteParam(m, iter->first); | |
687 WriteParam(m, iter->second); | |
688 } | |
689 } | |
690 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | |
691 int size; | |
692 if (!m->ReadLength(iter, &size)) | |
693 return false; | |
694 for (int i = 0; i < size; ++i) { | |
Tom Sepez
2014/02/14 19:05:37
This one is more important: You'll want to return
jdduke (slow)
2014/02/18 01:42:21
Hmm, I was under the impression that |ReadLength()
| |
695 K key; | |
696 if (!ReadParam(m, iter, &key)) | |
697 return false; | |
698 V& value = (*r)[k]; | |
699 if (!ReadParam(m, iter, &value)) | |
700 return false; | |
701 } | |
702 return true; | |
703 } | |
704 static void Log(const param_type& p, std::string* l) { | |
705 l->append("<base::SmallMap>"); | |
706 } | |
707 }; | |
708 | |
673 // IPC types ParamTraits ------------------------------------------------------- | 709 // IPC types ParamTraits ------------------------------------------------------- |
674 | 710 |
675 // A ChannelHandle is basically a platform-inspecific wrapper around the | 711 // A ChannelHandle is basically a platform-inspecific wrapper around the |
676 // fact that IPC endpoints are handled specially on POSIX. See above comments | 712 // fact that IPC endpoints are handled specially on POSIX. See above comments |
677 // on FileDescriptor for more background. | 713 // on FileDescriptor for more background. |
678 template<> | 714 template<> |
679 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { | 715 struct IPC_EXPORT ParamTraits<IPC::ChannelHandle> { |
680 typedef ChannelHandle param_type; | 716 typedef ChannelHandle param_type; |
681 static void Write(Message* m, const param_type& p); | 717 static void Write(Message* m, const param_type& p); |
682 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | 718 static bool Read(const Message* m, PickleIterator* iter, param_type* r); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
878 template<typename TA, typename TB, typename TC, typename TD, typename TE> | 914 template<typename TA, typename TB, typename TC, typename TD, typename TE> |
879 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { | 915 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) { |
880 ReplyParam p(a, b, c, d, e); | 916 ReplyParam p(a, b, c, d, e); |
881 WriteParam(reply, p); | 917 WriteParam(reply, p); |
882 } | 918 } |
883 }; | 919 }; |
884 | 920 |
885 } // namespace IPC | 921 } // namespace IPC |
886 | 922 |
887 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 923 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
OLD | NEW |