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; | |
eroman
2017/05/18 18:43:17
Better thanks!
| |
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 std::vector<uint8_t> bytes; |
eroman
2017/05/18 18:43:17
For symmetry with GetSize() and Write(), can you c
Ryan Hamilton
2017/05/19 03:38:50
Done. Though in order to do this, I needed to add
eroman
2017/05/19 17:37:54
I am fine with adding a StackVector ctor if it is
Ryan Hamilton
2017/05/19 21:30:46
Oh, I see. Duh! Ok, I've removed the new StackVect
| |
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() && |
141 bytes.size() != net::IPAddress::kIPv4AddressSize && | 149 bytes.size() != net::IPAddress::kIPv4AddressSize && |
142 bytes.size() != net::IPAddress::kIPv6AddressSize) { | 150 bytes.size() != net::IPAddress::kIPv6AddressSize) { |
143 return false; | 151 return false; |
144 } | 152 } |
145 *p = net::IPAddress(bytes); | 153 *p = net::IPAddress(bytes); |
146 return true; | 154 return true; |
147 } | 155 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 207 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
200 #include "content/public/common/common_param_traits_macros.h" | 208 #include "content/public/common/common_param_traits_macros.h" |
201 } // namespace IPC | 209 } // namespace IPC |
202 | 210 |
203 // Generate param traits log methods. | 211 // Generate param traits log methods. |
204 #include "ipc/param_traits_log_macros.h" | 212 #include "ipc/param_traits_log_macros.h" |
205 namespace IPC { | 213 namespace IPC { |
206 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 214 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
207 #include "content/public/common/common_param_traits_macros.h" | 215 #include "content/public/common/common_param_traits_macros.h" |
208 } // namespace IPC | 216 } // namespace IPC |
OLD | NEW |