Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: content/public/common/common_param_traits.cc

Issue 1534583002: Migrate Local Discovery from net::IPAddressNumber to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/public/common/referrer.h" 11 #include "content/public/common/referrer.h"
12 #include "net/base/host_port_pair.h" 12 #include "net/base/host_port_pair.h"
13 #include "net/base/ip_address.h"
13 #include "net/base/ip_endpoint.h" 14 #include "net/base/ip_endpoint.h"
14 15
15 namespace IPC { 16 namespace IPC {
16 17
17 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { 18 void ParamTraits<GURL>::Write(Message* m, const GURL& p) {
18 if (p.possibly_invalid_spec().length() > content::kMaxURLChars) { 19 if (p.possibly_invalid_spec().length() > content::kMaxURLChars) {
19 m->WriteString(std::string()); 20 m->WriteString(std::string());
20 return; 21 return;
21 } 22 }
22 23
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return false; 133 return false;
133 } 134 }
134 *p = net::IPEndPoint(address, port); 135 *p = net::IPEndPoint(address, port);
135 return true; 136 return true;
136 } 137 }
137 138
138 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { 139 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) {
139 LogParam("IPEndPoint:" + p.ToString(), l); 140 LogParam("IPEndPoint:" + p.ToString(), l);
140 } 141 }
141 142
143 void ParamTraits<net::IPAddress>::Write(Message* m, const param_type& p) {
144 WriteParam(m, p.bytes());
145 }
146
147 bool ParamTraits<net::IPAddress>::Read(const Message* m,
148 base::PickleIterator* iter,
149 param_type* p) {
150 std::vector<uint8_t> bytes;
151 if (!ReadParam(m, iter, &bytes))
152 return false;
153 net::IPAddress address(&bytes.front(), bytes.size());
eroman 2015/12/21 20:47:33 This is not correct. bytes might be empty, in whic
martijnc 2016/01/27 22:50:52 Handled in a separate CL.
154 if (address.size() && !address.IsIPv4() && !address.IsIPv6()) {
155 return false;
156 }
157 *p = address;
158 return true;
159 }
160
161 void ParamTraits<net::IPAddress>::Log(const param_type& p, std::string* l) {
162 LogParam("IPAddress:" + p.ToString(), l);
163 }
164
142 void ParamTraits<content::PageState>::Write( 165 void ParamTraits<content::PageState>::Write(
143 Message* m, const param_type& p) { 166 Message* m, const param_type& p) {
144 WriteParam(m, p.ToEncodedData()); 167 WriteParam(m, p.ToEncodedData());
145 } 168 }
146 169
147 bool ParamTraits<content::PageState>::Read(const Message* m, 170 bool ParamTraits<content::PageState>::Read(const Message* m,
148 base::PickleIterator* iter, 171 base::PickleIterator* iter,
149 param_type* r) { 172 param_type* r) {
150 std::string data; 173 std::string data;
151 if (!ReadParam(m, iter, &data)) 174 if (!ReadParam(m, iter, &data))
(...skipping 24 matching lines...) Expand all
176 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 199 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
177 #include "content/public/common/common_param_traits_macros.h" 200 #include "content/public/common/common_param_traits_macros.h"
178 } // namespace IPC 201 } // namespace IPC
179 202
180 // Generate param traits log methods. 203 // Generate param traits log methods.
181 #include "ipc/param_traits_log_macros.h" 204 #include "ipc/param_traits_log_macros.h"
182 namespace IPC { 205 namespace IPC {
183 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 206 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
184 #include "content/public/common/common_param_traits_macros.h" 207 #include "content/public/common/common_param_traits_macros.h"
185 } // namespace IPC 208 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698