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 "base/containers/stack_container.h" |
9 #include "content/public/common/content_constants.h" | 10 #include "content/public/common/content_constants.h" |
10 #include "content/public/common/page_state.h" | 11 #include "content/public/common/page_state.h" |
11 #include "content/public/common/referrer.h" | 12 #include "content/public/common/referrer.h" |
12 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
13 #include "net/base/ip_address.h" | 14 #include "net/base/ip_address.h" |
14 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
15 | 16 |
16 namespace IPC { | 17 namespace IPC { |
17 | 18 |
18 void ParamTraits<url::Origin>::GetSize(base::PickleSizer* s, | 19 void ParamTraits<url::Origin>::GetSize(base::PickleSizer* s, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 *p = net::IPEndPoint(address, port); | 118 *p = net::IPEndPoint(address, port); |
118 return true; | 119 return true; |
119 } | 120 } |
120 | 121 |
121 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { | 122 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { |
122 LogParam("IPEndPoint:" + p.ToString(), l); | 123 LogParam("IPEndPoint:" + p.ToString(), l); |
123 } | 124 } |
124 | 125 |
125 void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s, | 126 void ParamTraits<net::IPAddress>::GetSize(base::PickleSizer* s, |
126 const param_type& p) { | 127 const param_type& p) { |
127 GetParamSize(s, p.bytes()); | 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 base::StackVector<uint8_t, 16> bytes; |
| 136 for (uint8_t byte : p.bytes()) |
| 137 bytes->push_back(byte); |
| 138 WriteParam(m, bytes); |
132 } | 139 } |
133 | 140 |
134 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m, | 141 bool ParamTraits<net::IPAddress>::Read(const base::Pickle* m, |
135 base::PickleIterator* iter, | 142 base::PickleIterator* iter, |
136 param_type* p) { | 143 param_type* p) { |
137 std::vector<uint8_t> bytes; | 144 base::StackVector<uint8_t, 16> bytes; |
138 if (!ReadParam(m, iter, &bytes)) | 145 if (!ReadParam(m, iter, &bytes)) |
139 return false; | 146 return false; |
140 if (bytes.size() && | 147 if (bytes->size() && bytes->size() != net::IPAddress::kIPv4AddressSize && |
141 bytes.size() != net::IPAddress::kIPv4AddressSize && | 148 bytes->size() != net::IPAddress::kIPv6AddressSize) { |
142 bytes.size() != net::IPAddress::kIPv6AddressSize) { | |
143 return false; | 149 return false; |
144 } | 150 } |
145 *p = net::IPAddress(bytes); | 151 *p = net::IPAddress(bytes->data(), bytes->size()); |
146 return true; | 152 return true; |
147 } | 153 } |
148 | 154 |
149 void ParamTraits<net::IPAddress>::Log(const param_type& p, std::string* l) { | 155 void ParamTraits<net::IPAddress>::Log(const param_type& p, std::string* l) { |
150 LogParam("IPAddress:" + (p.empty() ? "(empty)" : p.ToString()), l); | 156 LogParam("IPAddress:" + (p.empty() ? "(empty)" : p.ToString()), l); |
151 } | 157 } |
152 | 158 |
153 void ParamTraits<content::PageState>::GetSize(base::PickleSizer* s, | 159 void ParamTraits<content::PageState>::GetSize(base::PickleSizer* s, |
154 const param_type& p) { | 160 const param_type& p) { |
155 GetParamSize(s, p.ToEncodedData()); | 161 GetParamSize(s, p.ToEncodedData()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 205 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
200 #include "content/public/common/common_param_traits_macros.h" | 206 #include "content/public/common/common_param_traits_macros.h" |
201 } // namespace IPC | 207 } // namespace IPC |
202 | 208 |
203 // Generate param traits log methods. | 209 // Generate param traits log methods. |
204 #include "ipc/param_traits_log_macros.h" | 210 #include "ipc/param_traits_log_macros.h" |
205 namespace IPC { | 211 namespace IPC { |
206 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 212 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
207 #include "content/public/common/common_param_traits_macros.h" | 213 #include "content/public/common/common_param_traits_macros.h" |
208 } // namespace IPC | 214 } // namespace IPC |
OLD | NEW |