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 #include "content/public/common/common_param_traits.h" | 5 #include "content/public/common/common_param_traits.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "content/public/common/content_constants.h" | 9 #include "content/public/common/content_constants.h" |
10 #include "content/public/common/page_state.h" | 10 #include "content/public/common/page_state.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 *p = net::IPEndPoint(address, port); | 117 *p = net::IPEndPoint(address, port); |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { | 121 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { |
122 LogParam("IPEndPoint:" + p.ToString(), l); | 122 LogParam("IPEndPoint:" + p.ToString(), l); |
123 } | 123 } |
124 | 124 |
125 void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s, | 125 void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s, |
126 const param_type& p) { | 126 const param_type& p) { |
127 GetParamSize(s, p.bytes()); | 127 // TODO(rch): avoid creating a vector here. |
| 128 base::StackVector<uint8_t, 16> bytes; |
| 129 for (uint8_t byte : p.bytes()) |
| 130 bytes->push_back(byte); |
| 131 GetParamSize(s, bytes); |
128 } | 132 } |
129 | 133 |
130 void ParamTraits<net::IPAddress>::Write(base::Pickle* m, const param_type& p) { | 134 void ParamTraits<net::IPAddress>::Write(base::Pickle* m, const param_type& p) { |
131 WriteParam(m, p.bytes()); | 135 // TODO(rch): avoid creating a vector here. |
| 136 base::StackVector<uint8_t, 16> bytes; |
| 137 for (uint8_t byte : p.bytes()) |
| 138 bytes->push_back(byte); |
| 139 WriteParam(m, bytes); |
132 } | 140 } |
133 | 141 |
134 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m, | 142 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m, |
135 base::PickleIterator* iter, | 143 base::PickleIterator* iter, |
136 param_type* p) { | 144 param_type* p) { |
137 std::vector<uint8_t> bytes; | 145 base::StackVector<uint8_t, 16> bytes; |
138 if (!ReadParam(m, iter, &bytes)) | 146 if (!ReadParam(m, iter, &bytes)) |
139 return false; | 147 return false; |
140 if (bytes.size() && | 148 if (bytes->size() && bytes->size() != net::IPAddress::kIPv4AddressSize && |
141 bytes.size() != net::IPAddress::kIPv4AddressSize && | 149 bytes->size() != net::IPAddress::kIPv6AddressSize) { |
142 bytes.size() != net::IPAddress::kIPv6AddressSize) { | |
143 return false; | 150 return false; |
144 } | 151 } |
145 *p = net::IPAddress(bytes); | 152 *p = net::IPAddress(bytes); |
146 return true; | 153 return true; |
147 } | 154 } |
148 | 155 |
149 void ParamTraits<net::IPAddress>::Log(const param_type& p, std::string* l) { | 156 void ParamTraits<net::IPAddress>::Log(const param_type& p, std::string* l) { |
150 LogParam("IPAddress:" + (p.empty() ? "(empty)" : p.ToString()), l); | 157 LogParam("IPAddress:" + (p.empty() ? "(empty)" : p.ToString()), l); |
151 } | 158 } |
152 | 159 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 206 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
200 #include "content/public/common/common_param_traits_macros.h" | 207 #include "content/public/common/common_param_traits_macros.h" |
201 } // namespace IPC | 208 } // namespace IPC |
202 | 209 |
203 // Generate param traits log methods. | 210 // Generate param traits log methods. |
204 #include "ipc/param_traits_log_macros.h" | 211 #include "ipc/param_traits_log_macros.h" |
205 namespace IPC { | 212 namespace IPC { |
206 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 213 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
207 #include "content/public/common/common_param_traits_macros.h" | 214 #include "content/public/common/common_param_traits_macros.h" |
208 } // namespace IPC | 215 } // namespace IPC |
OLD | NEW |