OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ | 5 #ifndef CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ |
6 #define CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ | 6 #define CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "ipc/ipc_message.h" | 13 #include "ipc/ipc_message.h" |
14 #include "ipc/ipc_param_traits.h" | 14 #include "ipc/ipc_param_traits.h" |
15 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | 15 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" |
16 | 16 |
17 namespace IPC { | 17 namespace IPC { |
18 | 18 |
19 template <class Element> | 19 template <class Element> |
20 struct ParamTraits<google::protobuf::RepeatedPtrField<Element>> { | 20 struct ParamTraits<google::protobuf::RepeatedPtrField<Element>> { |
21 typedef google::protobuf::RepeatedPtrField<Element> param_type; | 21 typedef google::protobuf::RepeatedPtrField<Element> param_type; |
22 | 22 |
23 static void Write(Message* m, const param_type& p) { | 23 static void Write(base::Pickle* m, const param_type& p) { |
24 WriteParam(m, p.size()); | 24 WriteParam(m, p.size()); |
25 for (const auto& element : p) | 25 for (const auto& element : p) |
26 WriteParam(m, element); | 26 WriteParam(m, element); |
27 } | 27 } |
28 | 28 |
29 static bool Read(const Message* m, | 29 static bool Read(const base::Pickle* m, |
30 base::PickleIterator* iter, | 30 base::PickleIterator* iter, |
31 param_type* p) { | 31 param_type* p) { |
32 int size; | 32 int size; |
33 if (!iter->ReadLength(&size) || size < 0) | 33 if (!iter->ReadLength(&size) || size < 0) |
34 return false; | 34 return false; |
35 if (INT_MAX / static_cast<int>(sizeof(void*)) <= size) | 35 if (INT_MAX / static_cast<int>(sizeof(void*)) <= size) |
36 return false; | 36 return false; |
37 p->Clear(); | 37 p->Clear(); |
38 p->Reserve(size); | 38 p->Reserve(size); |
39 while (size--) { | 39 while (size--) { |
(...skipping 11 matching lines...) Expand all Loading... |
51 else | 51 else |
52 logged_first = true; | 52 logged_first = true; |
53 LogParam(element, l); | 53 LogParam(element, l); |
54 } | 54 } |
55 } | 55 } |
56 }; | 56 }; |
57 | 57 |
58 } // namespace IPC | 58 } // namespace IPC |
59 | 59 |
60 #endif // CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ | 60 #endif // CHROME_COMMON_SAFE_BROWSING_PROTOBUF_MESSAGE_PARAM_TRAITS_H_ |
OLD | NEW |