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

Side by Side Diff: ipc/ipc_message_utils.h

Issue 1655333002: Add message sizing to basic IPC traits and struct macros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@with-pickles
Patch Set: include ArrayHeader in size (oops!) and ensure the buffer doesn't relocate Created 4 years, 10 months 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
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef IPC_IPC_MESSAGE_UTILS_H_ 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_
6 #define IPC_IPC_MESSAGE_UTILS_H_ 6 #define IPC_IPC_MESSAGE_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 }; 93 };
94 94
95 //----------------------------------------------------------------------------- 95 //-----------------------------------------------------------------------------
96 96
97 // A dummy struct to place first just to allow leading commas for all 97 // A dummy struct to place first just to allow leading commas for all
98 // members in the macro-generated constructor initializer lists. 98 // members in the macro-generated constructor initializer lists.
99 struct NoParams { 99 struct NoParams {
100 }; 100 };
101 101
102 template <class P> 102 template <class P>
103 static inline void GetParamSize(base::PickleSizer* sizer, const P& p) {
104 typedef typename SimilarTypeTraits<P>::Type Type;
105 ParamTraits<Type>::GetSize(sizer, static_cast<const Type&>(p));
106 }
107
108 template <class P>
103 static inline void WriteParam(base::Pickle* m, const P& p) { 109 static inline void WriteParam(base::Pickle* m, const P& p) {
104 typedef typename SimilarTypeTraits<P>::Type Type; 110 typedef typename SimilarTypeTraits<P>::Type Type;
105 ParamTraits<Type>::Write(m, static_cast<const Type& >(p)); 111 ParamTraits<Type>::Write(m, static_cast<const Type& >(p));
106 } 112 }
107 113
108 template <class P> 114 template <class P>
109 static inline bool WARN_UNUSED_RESULT ReadParam(const base::Pickle* m, 115 static inline bool WARN_UNUSED_RESULT ReadParam(const base::Pickle* m,
110 base::PickleIterator* iter, 116 base::PickleIterator* iter,
111 P* p) { 117 P* p) {
112 typedef typename SimilarTypeTraits<P>::Type Type; 118 typedef typename SimilarTypeTraits<P>::Type Type;
113 return ParamTraits<Type>::Read(m, iter, reinterpret_cast<Type* >(p)); 119 return ParamTraits<Type>::Read(m, iter, reinterpret_cast<Type* >(p));
114 } 120 }
115 121
116 template <class P> 122 template <class P>
117 static inline void LogParam(const P& p, std::string* l) { 123 static inline void LogParam(const P& p, std::string* l) {
118 typedef typename SimilarTypeTraits<P>::Type Type; 124 typedef typename SimilarTypeTraits<P>::Type Type;
119 ParamTraits<Type>::Log(static_cast<const Type& >(p), l); 125 ParamTraits<Type>::Log(static_cast<const Type& >(p), l);
120 } 126 }
121 127
122 // Primitive ParamTraits ------------------------------------------------------- 128 // Primitive ParamTraits -------------------------------------------------------
123 129
124 template <> 130 template <>
125 struct ParamTraits<bool> { 131 struct ParamTraits<bool> {
126 typedef bool param_type; 132 typedef bool param_type;
133 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
134 sizer->AddBool();
135 }
127 static void Write(base::Pickle* m, const param_type& p) { m->WriteBool(p); } 136 static void Write(base::Pickle* m, const param_type& p) { m->WriteBool(p); }
128 static bool Read(const base::Pickle* m, 137 static bool Read(const base::Pickle* m,
129 base::PickleIterator* iter, 138 base::PickleIterator* iter,
130 param_type* r) { 139 param_type* r) {
131 return iter->ReadBool(r); 140 return iter->ReadBool(r);
132 } 141 }
133 IPC_EXPORT static void Log(const param_type& p, std::string* l); 142 IPC_EXPORT static void Log(const param_type& p, std::string* l);
134 }; 143 };
135 144
136 template <> 145 template <>
137 struct IPC_EXPORT ParamTraits<signed char> { 146 struct IPC_EXPORT ParamTraits<signed char> {
138 typedef signed char param_type; 147 typedef signed char param_type;
148 static void GetSize(base::PickleSizer* sizer, const param_type& p);
139 static void Write(base::Pickle* m, const param_type& p); 149 static void Write(base::Pickle* m, const param_type& p);
140 static bool Read(const base::Pickle* m, 150 static bool Read(const base::Pickle* m,
141 base::PickleIterator* iter, 151 base::PickleIterator* iter,
142 param_type* r); 152 param_type* r);
143 static void Log(const param_type& p, std::string* l); 153 static void Log(const param_type& p, std::string* l);
144 }; 154 };
145 155
146 template <> 156 template <>
147 struct IPC_EXPORT ParamTraits<unsigned char> { 157 struct IPC_EXPORT ParamTraits<unsigned char> {
148 typedef unsigned char param_type; 158 typedef unsigned char param_type;
159 static void GetSize(base::PickleSizer* sizer, const param_type& p);
149 static void Write(base::Pickle* m, const param_type& p); 160 static void Write(base::Pickle* m, const param_type& p);
150 static bool Read(const base::Pickle* m, 161 static bool Read(const base::Pickle* m,
151 base::PickleIterator* iter, 162 base::PickleIterator* iter,
152 param_type* r); 163 param_type* r);
153 static void Log(const param_type& p, std::string* l); 164 static void Log(const param_type& p, std::string* l);
154 }; 165 };
155 166
156 template <> 167 template <>
157 struct IPC_EXPORT ParamTraits<unsigned short> { 168 struct IPC_EXPORT ParamTraits<unsigned short> {
158 typedef unsigned short param_type; 169 typedef unsigned short param_type;
170 static void GetSize(base::PickleSizer* sizer, const param_type& p);
159 static void Write(base::Pickle* m, const param_type& p); 171 static void Write(base::Pickle* m, const param_type& p);
160 static bool Read(const base::Pickle* m, 172 static bool Read(const base::Pickle* m,
161 base::PickleIterator* iter, 173 base::PickleIterator* iter,
162 param_type* r); 174 param_type* r);
163 static void Log(const param_type& p, std::string* l); 175 static void Log(const param_type& p, std::string* l);
164 }; 176 };
165 177
166 template <> 178 template <>
167 struct ParamTraits<int> { 179 struct ParamTraits<int> {
168 typedef int param_type; 180 typedef int param_type;
181 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
182 sizer->AddInt();
183 }
169 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); } 184 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); }
170 static bool Read(const base::Pickle* m, 185 static bool Read(const base::Pickle* m,
171 base::PickleIterator* iter, 186 base::PickleIterator* iter,
172 param_type* r) { 187 param_type* r) {
173 return iter->ReadInt(r); 188 return iter->ReadInt(r);
174 } 189 }
175 IPC_EXPORT static void Log(const param_type& p, std::string* l); 190 IPC_EXPORT static void Log(const param_type& p, std::string* l);
176 }; 191 };
177 192
178 template <> 193 template <>
179 struct ParamTraits<unsigned int> { 194 struct ParamTraits<unsigned int> {
180 typedef unsigned int param_type; 195 typedef unsigned int param_type;
196 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
197 sizer->AddInt();
198 }
181 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); } 199 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); }
182 static bool Read(const base::Pickle* m, 200 static bool Read(const base::Pickle* m,
183 base::PickleIterator* iter, 201 base::PickleIterator* iter,
184 param_type* r) { 202 param_type* r) {
185 return iter->ReadInt(reinterpret_cast<int*>(r)); 203 return iter->ReadInt(reinterpret_cast<int*>(r));
186 } 204 }
187 IPC_EXPORT static void Log(const param_type& p, std::string* l); 205 IPC_EXPORT static void Log(const param_type& p, std::string* l);
188 }; 206 };
189 207
190 template <> 208 template <>
191 struct ParamTraits<long> { 209 struct ParamTraits<long> {
192 typedef long param_type; 210 typedef long param_type;
211 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
212 sizer->AddLongUsingDangerousNonPortableLessPersistableForm();
213 }
193 static void Write(base::Pickle* m, const param_type& p) { 214 static void Write(base::Pickle* m, const param_type& p) {
194 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); 215 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p);
195 } 216 }
196 static bool Read(const base::Pickle* m, 217 static bool Read(const base::Pickle* m,
197 base::PickleIterator* iter, 218 base::PickleIterator* iter,
198 param_type* r) { 219 param_type* r) {
199 return iter->ReadLong(r); 220 return iter->ReadLong(r);
200 } 221 }
201 IPC_EXPORT static void Log(const param_type& p, std::string* l); 222 IPC_EXPORT static void Log(const param_type& p, std::string* l);
202 }; 223 };
203 224
204 template <> 225 template <>
205 struct ParamTraits<unsigned long> { 226 struct ParamTraits<unsigned long> {
206 typedef unsigned long param_type; 227 typedef unsigned long param_type;
228 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
229 sizer->AddLongUsingDangerousNonPortableLessPersistableForm();
230 }
207 static void Write(base::Pickle* m, const param_type& p) { 231 static void Write(base::Pickle* m, const param_type& p) {
208 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); 232 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p);
209 } 233 }
210 static bool Read(const base::Pickle* m, 234 static bool Read(const base::Pickle* m,
211 base::PickleIterator* iter, 235 base::PickleIterator* iter,
212 param_type* r) { 236 param_type* r) {
213 return iter->ReadLong(reinterpret_cast<long*>(r)); 237 return iter->ReadLong(reinterpret_cast<long*>(r));
214 } 238 }
215 IPC_EXPORT static void Log(const param_type& p, std::string* l); 239 IPC_EXPORT static void Log(const param_type& p, std::string* l);
216 }; 240 };
217 241
218 template <> 242 template <>
219 struct ParamTraits<long long> { 243 struct ParamTraits<long long> {
220 typedef long long param_type; 244 typedef long long param_type;
245 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
246 sizer->AddInt64();
247 }
221 static void Write(base::Pickle* m, const param_type& p) { 248 static void Write(base::Pickle* m, const param_type& p) {
222 m->WriteInt64(static_cast<int64_t>(p)); 249 m->WriteInt64(static_cast<int64_t>(p));
223 } 250 }
224 static bool Read(const base::Pickle* m, 251 static bool Read(const base::Pickle* m,
225 base::PickleIterator* iter, 252 base::PickleIterator* iter,
226 param_type* r) { 253 param_type* r) {
227 return iter->ReadInt64(reinterpret_cast<int64_t*>(r)); 254 return iter->ReadInt64(reinterpret_cast<int64_t*>(r));
228 } 255 }
229 IPC_EXPORT static void Log(const param_type& p, std::string* l); 256 IPC_EXPORT static void Log(const param_type& p, std::string* l);
230 }; 257 };
231 258
232 template <> 259 template <>
233 struct ParamTraits<unsigned long long> { 260 struct ParamTraits<unsigned long long> {
234 typedef unsigned long long param_type; 261 typedef unsigned long long param_type;
262 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
263 sizer->AddInt64();
264 }
235 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt64(p); } 265 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt64(p); }
236 static bool Read(const base::Pickle* m, 266 static bool Read(const base::Pickle* m,
237 base::PickleIterator* iter, 267 base::PickleIterator* iter,
238 param_type* r) { 268 param_type* r) {
239 return iter->ReadInt64(reinterpret_cast<int64_t*>(r)); 269 return iter->ReadInt64(reinterpret_cast<int64_t*>(r));
240 } 270 }
241 IPC_EXPORT static void Log(const param_type& p, std::string* l); 271 IPC_EXPORT static void Log(const param_type& p, std::string* l);
242 }; 272 };
243 273
244 // Note that the IPC layer doesn't sanitize NaNs and +/- INF values. Clients 274 // Note that the IPC layer doesn't sanitize NaNs and +/- INF values. Clients
245 // should be sure to check the sanity of these values after receiving them over 275 // should be sure to check the sanity of these values after receiving them over
246 // IPC. 276 // IPC.
247 template <> 277 template <>
248 struct IPC_EXPORT ParamTraits<float> { 278 struct IPC_EXPORT ParamTraits<float> {
249 typedef float param_type; 279 typedef float param_type;
280 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
281 sizer->AddFloat();
282 }
250 static void Write(base::Pickle* m, const param_type& p) { m->WriteFloat(p); } 283 static void Write(base::Pickle* m, const param_type& p) { m->WriteFloat(p); }
251 static bool Read(const base::Pickle* m, 284 static bool Read(const base::Pickle* m,
252 base::PickleIterator* iter, 285 base::PickleIterator* iter,
253 param_type* r) { 286 param_type* r) {
254 return iter->ReadFloat(r); 287 return iter->ReadFloat(r);
255 } 288 }
256 static void Log(const param_type& p, std::string* l); 289 static void Log(const param_type& p, std::string* l);
257 }; 290 };
258 291
259 template <> 292 template <>
260 struct IPC_EXPORT ParamTraits<double> { 293 struct IPC_EXPORT ParamTraits<double> {
261 typedef double param_type; 294 typedef double param_type;
295 static void GetSize(base::PickleSizer* sizer, const param_type& p);
262 static void Write(base::Pickle* m, const param_type& p); 296 static void Write(base::Pickle* m, const param_type& p);
263 static bool Read(const base::Pickle* m, 297 static bool Read(const base::Pickle* m,
264 base::PickleIterator* iter, 298 base::PickleIterator* iter,
265 param_type* r); 299 param_type* r);
266 static void Log(const param_type& p, std::string* l); 300 static void Log(const param_type& p, std::string* l);
267 }; 301 };
268 302
269 // STL ParamTraits ------------------------------------------------------------- 303 // STL ParamTraits -------------------------------------------------------------
270 304
271 template <> 305 template <>
272 struct ParamTraits<std::string> { 306 struct ParamTraits<std::string> {
273 typedef std::string param_type; 307 typedef std::string param_type;
308 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
309 sizer->AddString(p);
310 }
274 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); } 311 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); }
275 static bool Read(const base::Pickle* m, 312 static bool Read(const base::Pickle* m,
276 base::PickleIterator* iter, 313 base::PickleIterator* iter,
277 param_type* r) { 314 param_type* r) {
278 return iter->ReadString(r); 315 return iter->ReadString(r);
279 } 316 }
280 IPC_EXPORT static void Log(const param_type& p, std::string* l); 317 IPC_EXPORT static void Log(const param_type& p, std::string* l);
281 }; 318 };
282 319
283 template <> 320 template <>
284 struct ParamTraits<base::string16> { 321 struct ParamTraits<base::string16> {
285 typedef base::string16 param_type; 322 typedef base::string16 param_type;
323 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
324 sizer->AddString16(p);
325 }
286 static void Write(base::Pickle* m, const param_type& p) { 326 static void Write(base::Pickle* m, const param_type& p) {
287 m->WriteString16(p); 327 m->WriteString16(p);
288 } 328 }
289 static bool Read(const base::Pickle* m, 329 static bool Read(const base::Pickle* m,
290 base::PickleIterator* iter, 330 base::PickleIterator* iter,
291 param_type* r) { 331 param_type* r) {
292 return iter->ReadString16(r); 332 return iter->ReadString16(r);
293 } 333 }
294 IPC_EXPORT static void Log(const param_type& p, std::string* l); 334 IPC_EXPORT static void Log(const param_type& p, std::string* l);
295 }; 335 };
296 336
297 template <> 337 template <>
298 struct IPC_EXPORT ParamTraits<std::vector<char> > { 338 struct IPC_EXPORT ParamTraits<std::vector<char> > {
299 typedef std::vector<char> param_type; 339 typedef std::vector<char> param_type;
340 static void GetSize(base::PickleSizer* sizer, const param_type& p);
300 static void Write(base::Pickle* m, const param_type& p); 341 static void Write(base::Pickle* m, const param_type& p);
301 static bool Read(const base::Pickle*, 342 static bool Read(const base::Pickle*,
302 base::PickleIterator* iter, 343 base::PickleIterator* iter,
303 param_type* r); 344 param_type* r);
304 static void Log(const param_type& p, std::string* l); 345 static void Log(const param_type& p, std::string* l);
305 }; 346 };
306 347
307 template <> 348 template <>
308 struct IPC_EXPORT ParamTraits<std::vector<unsigned char> > { 349 struct IPC_EXPORT ParamTraits<std::vector<unsigned char> > {
309 typedef std::vector<unsigned char> param_type; 350 typedef std::vector<unsigned char> param_type;
351 static void GetSize(base::PickleSizer* sizer, const param_type& p);
310 static void Write(base::Pickle* m, const param_type& p); 352 static void Write(base::Pickle* m, const param_type& p);
311 static bool Read(const base::Pickle* m, 353 static bool Read(const base::Pickle* m,
312 base::PickleIterator* iter, 354 base::PickleIterator* iter,
313 param_type* r); 355 param_type* r);
314 static void Log(const param_type& p, std::string* l); 356 static void Log(const param_type& p, std::string* l);
315 }; 357 };
316 358
317 template <> 359 template <>
318 struct IPC_EXPORT ParamTraits<std::vector<bool> > { 360 struct IPC_EXPORT ParamTraits<std::vector<bool> > {
319 typedef std::vector<bool> param_type; 361 typedef std::vector<bool> param_type;
362 static void GetSize(base::PickleSizer* sizer, const param_type& p);
320 static void Write(base::Pickle* m, const param_type& p); 363 static void Write(base::Pickle* m, const param_type& p);
321 static bool Read(const base::Pickle* m, 364 static bool Read(const base::Pickle* m,
322 base::PickleIterator* iter, 365 base::PickleIterator* iter,
323 param_type* r); 366 param_type* r);
324 static void Log(const param_type& p, std::string* l); 367 static void Log(const param_type& p, std::string* l);
325 }; 368 };
326 369
327 template <class P> 370 template <class P>
328 struct ParamTraits<std::vector<P> > { 371 struct ParamTraits<std::vector<P> > {
329 typedef std::vector<P> param_type; 372 typedef std::vector<P> param_type;
373 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
374 GetParamSize(sizer, static_cast<int>(p.size()));
375 for (size_t i = 0; i < p.size(); i++)
376 GetParamSize(sizer, p[i]);
377 }
330 static void Write(base::Pickle* m, const param_type& p) { 378 static void Write(base::Pickle* m, const param_type& p) {
331 WriteParam(m, static_cast<int>(p.size())); 379 WriteParam(m, static_cast<int>(p.size()));
332 for (size_t i = 0; i < p.size(); i++) 380 for (size_t i = 0; i < p.size(); i++)
333 WriteParam(m, p[i]); 381 WriteParam(m, p[i]);
334 } 382 }
335 static bool Read(const base::Pickle* m, 383 static bool Read(const base::Pickle* m,
336 base::PickleIterator* iter, 384 base::PickleIterator* iter,
337 param_type* r) { 385 param_type* r) {
338 int size; 386 int size;
339 // ReadLength() checks for < 0 itself. 387 // ReadLength() checks for < 0 itself.
(...skipping 14 matching lines...) Expand all
354 if (i != 0) 402 if (i != 0)
355 l->append(" "); 403 l->append(" ");
356 LogParam((p[i]), l); 404 LogParam((p[i]), l);
357 } 405 }
358 } 406 }
359 }; 407 };
360 408
361 template <class P> 409 template <class P>
362 struct ParamTraits<std::set<P> > { 410 struct ParamTraits<std::set<P> > {
363 typedef std::set<P> param_type; 411 typedef std::set<P> param_type;
412 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
413 GetParamSize(sizer, static_cast<int>(p.size()));
414 typename param_type::const_iterator iter;
415 for (iter = p.begin(); iter != p.end(); ++iter)
416 GetParamSize(sizer, *iter);
417 }
364 static void Write(base::Pickle* m, const param_type& p) { 418 static void Write(base::Pickle* m, const param_type& p) {
365 WriteParam(m, static_cast<int>(p.size())); 419 WriteParam(m, static_cast<int>(p.size()));
366 typename param_type::const_iterator iter; 420 typename param_type::const_iterator iter;
367 for (iter = p.begin(); iter != p.end(); ++iter) 421 for (iter = p.begin(); iter != p.end(); ++iter)
368 WriteParam(m, *iter); 422 WriteParam(m, *iter);
369 } 423 }
370 static bool Read(const base::Pickle* m, 424 static bool Read(const base::Pickle* m,
371 base::PickleIterator* iter, 425 base::PickleIterator* iter,
372 param_type* r) { 426 param_type* r) {
373 int size; 427 int size;
374 if (!iter->ReadLength(&size)) 428 if (!iter->ReadLength(&size))
375 return false; 429 return false;
376 for (int i = 0; i < size; ++i) { 430 for (int i = 0; i < size; ++i) {
377 P item; 431 P item;
378 if (!ReadParam(m, iter, &item)) 432 if (!ReadParam(m, iter, &item))
379 return false; 433 return false;
380 r->insert(item); 434 r->insert(item);
381 } 435 }
382 return true; 436 return true;
383 } 437 }
384 static void Log(const param_type& p, std::string* l) { 438 static void Log(const param_type& p, std::string* l) {
385 l->append("<std::set>"); 439 l->append("<std::set>");
386 } 440 }
387 }; 441 };
388 442
389 template <class K, class V, class C, class A> 443 template <class K, class V, class C, class A>
390 struct ParamTraits<std::map<K, V, C, A> > { 444 struct ParamTraits<std::map<K, V, C, A> > {
391 typedef std::map<K, V, C, A> param_type; 445 typedef std::map<K, V, C, A> param_type;
446 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
447 GetParamSize(sizer, static_cast<int>(p.size()));
448 typename param_type::const_iterator iter;
449 for (iter = p.begin(); iter != p.end(); ++iter) {
450 GetParamSize(sizer, iter->first);
451 GetParamSize(sizer, iter->second);
452 }
453 }
392 static void Write(base::Pickle* m, const param_type& p) { 454 static void Write(base::Pickle* m, const param_type& p) {
393 WriteParam(m, static_cast<int>(p.size())); 455 WriteParam(m, static_cast<int>(p.size()));
394 typename param_type::const_iterator iter; 456 typename param_type::const_iterator iter;
395 for (iter = p.begin(); iter != p.end(); ++iter) { 457 for (iter = p.begin(); iter != p.end(); ++iter) {
396 WriteParam(m, iter->first); 458 WriteParam(m, iter->first);
397 WriteParam(m, iter->second); 459 WriteParam(m, iter->second);
398 } 460 }
399 } 461 }
400 static bool Read(const base::Pickle* m, 462 static bool Read(const base::Pickle* m,
401 base::PickleIterator* iter, 463 base::PickleIterator* iter,
(...skipping 12 matching lines...) Expand all
414 return true; 476 return true;
415 } 477 }
416 static void Log(const param_type& p, std::string* l) { 478 static void Log(const param_type& p, std::string* l) {
417 l->append("<std::map>"); 479 l->append("<std::map>");
418 } 480 }
419 }; 481 };
420 482
421 template <class A, class B> 483 template <class A, class B>
422 struct ParamTraits<std::pair<A, B> > { 484 struct ParamTraits<std::pair<A, B> > {
423 typedef std::pair<A, B> param_type; 485 typedef std::pair<A, B> param_type;
486 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
487 GetParamSize(sizer, p.first);
488 GetParamSize(sizer, p.second);
489 }
424 static void Write(base::Pickle* m, const param_type& p) { 490 static void Write(base::Pickle* m, const param_type& p) {
425 WriteParam(m, p.first); 491 WriteParam(m, p.first);
426 WriteParam(m, p.second); 492 WriteParam(m, p.second);
427 } 493 }
428 static bool Read(const base::Pickle* m, 494 static bool Read(const base::Pickle* m,
429 base::PickleIterator* iter, 495 base::PickleIterator* iter,
430 param_type* r) { 496 param_type* r) {
431 return ReadParam(m, iter, &r->first) && ReadParam(m, iter, &r->second); 497 return ReadParam(m, iter, &r->first) && ReadParam(m, iter, &r->second);
432 } 498 }
433 static void Log(const param_type& p, std::string* l) { 499 static void Log(const param_type& p, std::string* l) {
(...skipping 14 matching lines...) Expand all
448 base::PickleIterator* iter, 514 base::PickleIterator* iter,
449 param_type* r); 515 param_type* r);
450 static void Log(const param_type& p, std::string* l); 516 static void Log(const param_type& p, std::string* l);
451 }; 517 };
452 518
453 // Base ParamTraits ------------------------------------------------------------ 519 // Base ParamTraits ------------------------------------------------------------
454 520
455 template <> 521 template <>
456 struct IPC_EXPORT ParamTraits<base::DictionaryValue> { 522 struct IPC_EXPORT ParamTraits<base::DictionaryValue> {
457 typedef base::DictionaryValue param_type; 523 typedef base::DictionaryValue param_type;
524 static void GetSize(base::PickleSizer* sizer, const param_type& p);
458 static void Write(base::Pickle* m, const param_type& p); 525 static void Write(base::Pickle* m, const param_type& p);
459 static bool Read(const base::Pickle* m, 526 static bool Read(const base::Pickle* m,
460 base::PickleIterator* iter, 527 base::PickleIterator* iter,
461 param_type* r); 528 param_type* r);
462 static void Log(const param_type& p, std::string* l); 529 static void Log(const param_type& p, std::string* l);
463 }; 530 };
464 531
465 #if defined(OS_POSIX) 532 #if defined(OS_POSIX)
466 // FileDescriptors may be serialised over IPC channels on POSIX. On the 533 // FileDescriptors may be serialised over IPC channels on POSIX. On the
467 // receiving side, the FileDescriptor is a valid duplicate of the file 534 // receiving side, the FileDescriptor is a valid duplicate of the file
(...skipping 29 matching lines...) Expand all
497 static bool Read(const base::Pickle* m, 564 static bool Read(const base::Pickle* m,
498 base::PickleIterator* iter, 565 base::PickleIterator* iter,
499 param_type* r); 566 param_type* r);
500 static void Log(const param_type& p, std::string* l); 567 static void Log(const param_type& p, std::string* l);
501 }; 568 };
502 #endif // (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) 569 #endif // (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
503 570
504 template <> 571 template <>
505 struct IPC_EXPORT ParamTraits<base::FilePath> { 572 struct IPC_EXPORT ParamTraits<base::FilePath> {
506 typedef base::FilePath param_type; 573 typedef base::FilePath param_type;
574 static void GetSize(base::PickleSizer* sizer, const param_type& p);
507 static void Write(base::Pickle* m, const param_type& p); 575 static void Write(base::Pickle* m, const param_type& p);
508 static bool Read(const base::Pickle* m, 576 static bool Read(const base::Pickle* m,
509 base::PickleIterator* iter, 577 base::PickleIterator* iter,
510 param_type* r); 578 param_type* r);
511 static void Log(const param_type& p, std::string* l); 579 static void Log(const param_type& p, std::string* l);
512 }; 580 };
513 581
514 template <> 582 template <>
515 struct IPC_EXPORT ParamTraits<base::ListValue> { 583 struct IPC_EXPORT ParamTraits<base::ListValue> {
516 typedef base::ListValue param_type; 584 typedef base::ListValue param_type;
585 static void GetSize(base::PickleSizer* sizer, const param_type& p);
517 static void Write(base::Pickle* m, const param_type& p); 586 static void Write(base::Pickle* m, const param_type& p);
518 static bool Read(const base::Pickle* m, 587 static bool Read(const base::Pickle* m,
519 base::PickleIterator* iter, 588 base::PickleIterator* iter,
520 param_type* r); 589 param_type* r);
521 static void Log(const param_type& p, std::string* l); 590 static void Log(const param_type& p, std::string* l);
522 }; 591 };
523 592
524 template <> 593 template <>
525 struct IPC_EXPORT ParamTraits<base::NullableString16> { 594 struct IPC_EXPORT ParamTraits<base::NullableString16> {
526 typedef base::NullableString16 param_type; 595 typedef base::NullableString16 param_type;
596 static void GetSize(base::PickleSizer* sizer, const param_type& p);
527 static void Write(base::Pickle* m, const param_type& p); 597 static void Write(base::Pickle* m, const param_type& p);
528 static bool Read(const base::Pickle* m, 598 static bool Read(const base::Pickle* m,
529 base::PickleIterator* iter, 599 base::PickleIterator* iter,
530 param_type* r); 600 param_type* r);
531 static void Log(const param_type& p, std::string* l); 601 static void Log(const param_type& p, std::string* l);
532 }; 602 };
533 603
534 template <> 604 template <>
535 struct IPC_EXPORT ParamTraits<base::File::Info> { 605 struct IPC_EXPORT ParamTraits<base::File::Info> {
536 typedef base::File::Info param_type; 606 typedef base::File::Info param_type;
607 static void GetSize(base::PickleSizer* sizer, const param_type& p);
537 static void Write(base::Pickle* m, const param_type& p); 608 static void Write(base::Pickle* m, const param_type& p);
538 static bool Read(const base::Pickle* m, 609 static bool Read(const base::Pickle* m,
539 base::PickleIterator* iter, 610 base::PickleIterator* iter,
540 param_type* r); 611 param_type* r);
541 static void Log(const param_type& p, std::string* l); 612 static void Log(const param_type& p, std::string* l);
542 }; 613 };
543 614
544 template <> 615 template <>
545 struct SimilarTypeTraits<base::File::Error> { 616 struct SimilarTypeTraits<base::File::Error> {
546 typedef int Type; 617 typedef int Type;
547 }; 618 };
548 619
549 #if defined(OS_WIN) 620 #if defined(OS_WIN)
550 template <> 621 template <>
551 struct SimilarTypeTraits<HWND> { 622 struct SimilarTypeTraits<HWND> {
552 typedef HANDLE Type; 623 typedef HANDLE Type;
553 }; 624 };
554 #endif // defined(OS_WIN) 625 #endif // defined(OS_WIN)
555 626
556 template <> 627 template <>
557 struct IPC_EXPORT ParamTraits<base::Time> { 628 struct IPC_EXPORT ParamTraits<base::Time> {
558 typedef base::Time param_type; 629 typedef base::Time param_type;
630 static void GetSize(base::PickleSizer* sizer, const param_type& p);
559 static void Write(base::Pickle* m, const param_type& p); 631 static void Write(base::Pickle* m, const param_type& p);
560 static bool Read(const base::Pickle* m, 632 static bool Read(const base::Pickle* m,
561 base::PickleIterator* iter, 633 base::PickleIterator* iter,
562 param_type* r); 634 param_type* r);
563 static void Log(const param_type& p, std::string* l); 635 static void Log(const param_type& p, std::string* l);
564 }; 636 };
565 637
566 template <> 638 template <>
567 struct IPC_EXPORT ParamTraits<base::TimeDelta> { 639 struct IPC_EXPORT ParamTraits<base::TimeDelta> {
568 typedef base::TimeDelta param_type; 640 typedef base::TimeDelta param_type;
641 static void GetSize(base::PickleSizer* sizer, const param_type& p);
569 static void Write(base::Pickle* m, const param_type& p); 642 static void Write(base::Pickle* m, const param_type& p);
570 static bool Read(const base::Pickle* m, 643 static bool Read(const base::Pickle* m,
571 base::PickleIterator* iter, 644 base::PickleIterator* iter,
572 param_type* r); 645 param_type* r);
573 static void Log(const param_type& p, std::string* l); 646 static void Log(const param_type& p, std::string* l);
574 }; 647 };
575 648
576 template <> 649 template <>
577 struct IPC_EXPORT ParamTraits<base::TimeTicks> { 650 struct IPC_EXPORT ParamTraits<base::TimeTicks> {
578 typedef base::TimeTicks param_type; 651 typedef base::TimeTicks param_type;
652 static void GetSize(base::PickleSizer* sizer, const param_type& p);
579 static void Write(base::Pickle* m, const param_type& p); 653 static void Write(base::Pickle* m, const param_type& p);
580 static bool Read(const base::Pickle* m, 654 static bool Read(const base::Pickle* m,
581 base::PickleIterator* iter, 655 base::PickleIterator* iter,
582 param_type* r); 656 param_type* r);
583 static void Log(const param_type& p, std::string* l); 657 static void Log(const param_type& p, std::string* l);
584 }; 658 };
585 659
586 template <> 660 template <>
587 struct ParamTraits<base::Tuple<>> { 661 struct ParamTraits<base::Tuple<>> {
588 typedef base::Tuple<> param_type; 662 typedef base::Tuple<> param_type;
663 static void GetSize(base::PickleSizer* sizer, const param_type& p) {}
589 static void Write(base::Pickle* m, const param_type& p) {} 664 static void Write(base::Pickle* m, const param_type& p) {}
590 static bool Read(const base::Pickle* m, 665 static bool Read(const base::Pickle* m,
591 base::PickleIterator* iter, 666 base::PickleIterator* iter,
592 param_type* r) { 667 param_type* r) {
593 return true; 668 return true;
594 } 669 }
595 static void Log(const param_type& p, std::string* l) { 670 static void Log(const param_type& p, std::string* l) {
596 } 671 }
597 }; 672 };
598 673
599 template <class A> 674 template <class A>
600 struct ParamTraits<base::Tuple<A>> { 675 struct ParamTraits<base::Tuple<A>> {
601 typedef base::Tuple<A> param_type; 676 typedef base::Tuple<A> param_type;
677 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
678 GetParamSize(sizer, base::get<0>(p));
679 }
602 static void Write(base::Pickle* m, const param_type& p) { 680 static void Write(base::Pickle* m, const param_type& p) {
603 WriteParam(m, base::get<0>(p)); 681 WriteParam(m, base::get<0>(p));
604 } 682 }
605 static bool Read(const base::Pickle* m, 683 static bool Read(const base::Pickle* m,
606 base::PickleIterator* iter, 684 base::PickleIterator* iter,
607 param_type* r) { 685 param_type* r) {
608 return ReadParam(m, iter, &base::get<0>(*r)); 686 return ReadParam(m, iter, &base::get<0>(*r));
609 } 687 }
610 static void Log(const param_type& p, std::string* l) { 688 static void Log(const param_type& p, std::string* l) {
611 LogParam(base::get<0>(p), l); 689 LogParam(base::get<0>(p), l);
612 } 690 }
613 }; 691 };
614 692
615 template <class A, class B> 693 template <class A, class B>
616 struct ParamTraits<base::Tuple<A, B>> { 694 struct ParamTraits<base::Tuple<A, B>> {
617 typedef base::Tuple<A, B> param_type; 695 typedef base::Tuple<A, B> param_type;
696 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
697 GetParamSize(sizer, base::get<0>(p));
698 GetParamSize(sizer, base::get<1>(p));
699 }
618 static void Write(base::Pickle* m, const param_type& p) { 700 static void Write(base::Pickle* m, const param_type& p) {
619 WriteParam(m, base::get<0>(p)); 701 WriteParam(m, base::get<0>(p));
620 WriteParam(m, base::get<1>(p)); 702 WriteParam(m, base::get<1>(p));
621 } 703 }
622 static bool Read(const base::Pickle* m, 704 static bool Read(const base::Pickle* m,
623 base::PickleIterator* iter, 705 base::PickleIterator* iter,
624 param_type* r) { 706 param_type* r) {
625 return (ReadParam(m, iter, &base::get<0>(*r)) && 707 return (ReadParam(m, iter, &base::get<0>(*r)) &&
626 ReadParam(m, iter, &base::get<1>(*r))); 708 ReadParam(m, iter, &base::get<1>(*r)));
627 } 709 }
628 static void Log(const param_type& p, std::string* l) { 710 static void Log(const param_type& p, std::string* l) {
629 LogParam(base::get<0>(p), l); 711 LogParam(base::get<0>(p), l);
630 l->append(", "); 712 l->append(", ");
631 LogParam(base::get<1>(p), l); 713 LogParam(base::get<1>(p), l);
632 } 714 }
633 }; 715 };
634 716
635 template <class A, class B, class C> 717 template <class A, class B, class C>
636 struct ParamTraits<base::Tuple<A, B, C>> { 718 struct ParamTraits<base::Tuple<A, B, C>> {
637 typedef base::Tuple<A, B, C> param_type; 719 typedef base::Tuple<A, B, C> param_type;
720 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
721 GetParamSize(sizer, base::get<0>(p));
722 GetParamSize(sizer, base::get<1>(p));
723 GetParamSize(sizer, base::get<2>(p));
724 }
638 static void Write(base::Pickle* m, const param_type& p) { 725 static void Write(base::Pickle* m, const param_type& p) {
639 WriteParam(m, base::get<0>(p)); 726 WriteParam(m, base::get<0>(p));
640 WriteParam(m, base::get<1>(p)); 727 WriteParam(m, base::get<1>(p));
641 WriteParam(m, base::get<2>(p)); 728 WriteParam(m, base::get<2>(p));
642 } 729 }
643 static bool Read(const base::Pickle* m, 730 static bool Read(const base::Pickle* m,
644 base::PickleIterator* iter, 731 base::PickleIterator* iter,
645 param_type* r) { 732 param_type* r) {
646 return (ReadParam(m, iter, &base::get<0>(*r)) && 733 return (ReadParam(m, iter, &base::get<0>(*r)) &&
647 ReadParam(m, iter, &base::get<1>(*r)) && 734 ReadParam(m, iter, &base::get<1>(*r)) &&
648 ReadParam(m, iter, &base::get<2>(*r))); 735 ReadParam(m, iter, &base::get<2>(*r)));
649 } 736 }
650 static void Log(const param_type& p, std::string* l) { 737 static void Log(const param_type& p, std::string* l) {
651 LogParam(base::get<0>(p), l); 738 LogParam(base::get<0>(p), l);
652 l->append(", "); 739 l->append(", ");
653 LogParam(base::get<1>(p), l); 740 LogParam(base::get<1>(p), l);
654 l->append(", "); 741 l->append(", ");
655 LogParam(base::get<2>(p), l); 742 LogParam(base::get<2>(p), l);
656 } 743 }
657 }; 744 };
658 745
659 template <class A, class B, class C, class D> 746 template <class A, class B, class C, class D>
660 struct ParamTraits<base::Tuple<A, B, C, D>> { 747 struct ParamTraits<base::Tuple<A, B, C, D>> {
661 typedef base::Tuple<A, B, C, D> param_type; 748 typedef base::Tuple<A, B, C, D> param_type;
749 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
750 GetParamSize(sizer, base::get<0>(p));
751 GetParamSize(sizer, base::get<1>(p));
752 GetParamSize(sizer, base::get<2>(p));
753 GetParamSize(sizer, base::get<3>(p));
754 }
662 static void Write(base::Pickle* m, const param_type& p) { 755 static void Write(base::Pickle* m, const param_type& p) {
663 WriteParam(m, base::get<0>(p)); 756 WriteParam(m, base::get<0>(p));
664 WriteParam(m, base::get<1>(p)); 757 WriteParam(m, base::get<1>(p));
665 WriteParam(m, base::get<2>(p)); 758 WriteParam(m, base::get<2>(p));
666 WriteParam(m, base::get<3>(p)); 759 WriteParam(m, base::get<3>(p));
667 } 760 }
668 static bool Read(const base::Pickle* m, 761 static bool Read(const base::Pickle* m,
669 base::PickleIterator* iter, 762 base::PickleIterator* iter,
670 param_type* r) { 763 param_type* r) {
671 return (ReadParam(m, iter, &base::get<0>(*r)) && 764 return (ReadParam(m, iter, &base::get<0>(*r)) &&
672 ReadParam(m, iter, &base::get<1>(*r)) && 765 ReadParam(m, iter, &base::get<1>(*r)) &&
673 ReadParam(m, iter, &base::get<2>(*r)) && 766 ReadParam(m, iter, &base::get<2>(*r)) &&
674 ReadParam(m, iter, &base::get<3>(*r))); 767 ReadParam(m, iter, &base::get<3>(*r)));
675 } 768 }
676 static void Log(const param_type& p, std::string* l) { 769 static void Log(const param_type& p, std::string* l) {
677 LogParam(base::get<0>(p), l); 770 LogParam(base::get<0>(p), l);
678 l->append(", "); 771 l->append(", ");
679 LogParam(base::get<1>(p), l); 772 LogParam(base::get<1>(p), l);
680 l->append(", "); 773 l->append(", ");
681 LogParam(base::get<2>(p), l); 774 LogParam(base::get<2>(p), l);
682 l->append(", "); 775 l->append(", ");
683 LogParam(base::get<3>(p), l); 776 LogParam(base::get<3>(p), l);
684 } 777 }
685 }; 778 };
686 779
687 template <class A, class B, class C, class D, class E> 780 template <class A, class B, class C, class D, class E>
688 struct ParamTraits<base::Tuple<A, B, C, D, E>> { 781 struct ParamTraits<base::Tuple<A, B, C, D, E>> {
689 typedef base::Tuple<A, B, C, D, E> param_type; 782 typedef base::Tuple<A, B, C, D, E> param_type;
783 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
784 GetParamSize(sizer, base::get<0>(p));
785 GetParamSize(sizer, base::get<1>(p));
786 GetParamSize(sizer, base::get<2>(p));
787 GetParamSize(sizer, base::get<3>(p));
788 GetParamSize(sizer, base::get<4>(p));
789 }
690 static void Write(base::Pickle* m, const param_type& p) { 790 static void Write(base::Pickle* m, const param_type& p) {
691 WriteParam(m, base::get<0>(p)); 791 WriteParam(m, base::get<0>(p));
692 WriteParam(m, base::get<1>(p)); 792 WriteParam(m, base::get<1>(p));
693 WriteParam(m, base::get<2>(p)); 793 WriteParam(m, base::get<2>(p));
694 WriteParam(m, base::get<3>(p)); 794 WriteParam(m, base::get<3>(p));
695 WriteParam(m, base::get<4>(p)); 795 WriteParam(m, base::get<4>(p));
696 } 796 }
697 static bool Read(const base::Pickle* m, 797 static bool Read(const base::Pickle* m,
698 base::PickleIterator* iter, 798 base::PickleIterator* iter,
699 param_type* r) { 799 param_type* r) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 if (i != 0) 845 if (i != 0)
746 l->append(" "); 846 l->append(" ");
747 LogParam(*p[i], l); 847 LogParam(*p[i], l);
748 } 848 }
749 } 849 }
750 }; 850 };
751 851
752 template <class P, size_t stack_capacity> 852 template <class P, size_t stack_capacity>
753 struct ParamTraits<base::StackVector<P, stack_capacity> > { 853 struct ParamTraits<base::StackVector<P, stack_capacity> > {
754 typedef base::StackVector<P, stack_capacity> param_type; 854 typedef base::StackVector<P, stack_capacity> param_type;
855 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
856 GetParamSize(sizer, static_cast<int>(p->size()));
857 for (size_t i = 0; i < p->size(); i++)
858 GetParamSize(sizer, p[i]);
859 }
755 static void Write(base::Pickle* m, const param_type& p) { 860 static void Write(base::Pickle* m, const param_type& p) {
756 WriteParam(m, static_cast<int>(p->size())); 861 WriteParam(m, static_cast<int>(p->size()));
757 for (size_t i = 0; i < p->size(); i++) 862 for (size_t i = 0; i < p->size(); i++)
758 WriteParam(m, p[i]); 863 WriteParam(m, p[i]);
759 } 864 }
760 static bool Read(const base::Pickle* m, 865 static bool Read(const base::Pickle* m,
761 base::PickleIterator* iter, 866 base::PickleIterator* iter,
762 param_type* r) { 867 param_type* r) {
763 int size; 868 int size;
764 // ReadLength() checks for < 0 itself. 869 // ReadLength() checks for < 0 itself.
(...skipping 20 matching lines...) Expand all
785 }; 890 };
786 891
787 template <typename NormalMap, 892 template <typename NormalMap,
788 int kArraySize, 893 int kArraySize,
789 typename EqualKey, 894 typename EqualKey,
790 typename MapInit> 895 typename MapInit>
791 struct ParamTraits<base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> > { 896 struct ParamTraits<base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> > {
792 typedef base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> param_type; 897 typedef base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> param_type;
793 typedef typename param_type::key_type K; 898 typedef typename param_type::key_type K;
794 typedef typename param_type::data_type V; 899 typedef typename param_type::data_type V;
900 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
901 GetParamSize(sizer, static_cast<int>(p.size()));
902 typename param_type::const_iterator iter;
903 for (iter = p.begin(); iter != p.end(); ++iter) {
904 GetParamSize(sizer, iter->first);
905 GetParamSize(sizer, iter->second);
906 }
907 }
795 static void Write(base::Pickle* m, const param_type& p) { 908 static void Write(base::Pickle* m, const param_type& p) {
796 WriteParam(m, static_cast<int>(p.size())); 909 WriteParam(m, static_cast<int>(p.size()));
797 typename param_type::const_iterator iter; 910 typename param_type::const_iterator iter;
798 for (iter = p.begin(); iter != p.end(); ++iter) { 911 for (iter = p.begin(); iter != p.end(); ++iter) {
799 WriteParam(m, iter->first); 912 WriteParam(m, iter->first);
800 WriteParam(m, iter->second); 913 WriteParam(m, iter->second);
801 } 914 }
802 } 915 }
803 static bool Read(const base::Pickle* m, 916 static bool Read(const base::Pickle* m,
804 base::PickleIterator* iter, 917 base::PickleIterator* iter,
(...skipping 12 matching lines...) Expand all
817 return true; 930 return true;
818 } 931 }
819 static void Log(const param_type& p, std::string* l) { 932 static void Log(const param_type& p, std::string* l) {
820 l->append("<base::SmallMap>"); 933 l->append("<base::SmallMap>");
821 } 934 }
822 }; 935 };
823 936
824 template <class P> 937 template <class P>
825 struct ParamTraits<scoped_ptr<P> > { 938 struct ParamTraits<scoped_ptr<P> > {
826 typedef scoped_ptr<P> param_type; 939 typedef scoped_ptr<P> param_type;
940 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
941 bool valid = !!p;
942 GetParamSize(sizer, valid);
943 if (valid)
944 GetParamSize(sizer, *p);
945 }
827 static void Write(base::Pickle* m, const param_type& p) { 946 static void Write(base::Pickle* m, const param_type& p) {
828 bool valid = !!p; 947 bool valid = !!p;
829 WriteParam(m, valid); 948 WriteParam(m, valid);
830 if (valid) 949 if (valid)
831 WriteParam(m, *p); 950 WriteParam(m, *p);
832 } 951 }
833 static bool Read(const base::Pickle* m, 952 static bool Read(const base::Pickle* m,
834 base::PickleIterator* iter, 953 base::PickleIterator* iter,
835 param_type* r) { 954 param_type* r) {
836 bool valid = false; 955 bool valid = false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 static void Write(base::Pickle* m, const param_type& p); 987 static void Write(base::Pickle* m, const param_type& p);
869 static bool Read(const base::Pickle* m, 988 static bool Read(const base::Pickle* m,
870 base::PickleIterator* iter, 989 base::PickleIterator* iter,
871 param_type* r); 990 param_type* r);
872 static void Log(const param_type& p, std::string* l); 991 static void Log(const param_type& p, std::string* l);
873 }; 992 };
874 993
875 template <> 994 template <>
876 struct IPC_EXPORT ParamTraits<LogData> { 995 struct IPC_EXPORT ParamTraits<LogData> {
877 typedef LogData param_type; 996 typedef LogData param_type;
997 static void GetSize(base::PickleSizer* sizer, const param_type& p);
878 static void Write(base::Pickle* m, const param_type& p); 998 static void Write(base::Pickle* m, const param_type& p);
879 static bool Read(const base::Pickle* m, 999 static bool Read(const base::Pickle* m,
880 base::PickleIterator* iter, 1000 base::PickleIterator* iter,
881 param_type* r); 1001 param_type* r);
882 static void Log(const param_type& p, std::string* l); 1002 static void Log(const param_type& p, std::string* l);
883 }; 1003 };
884 1004
885 template <> 1005 template <>
886 struct IPC_EXPORT ParamTraits<Message> { 1006 struct IPC_EXPORT ParamTraits<Message> {
887 static void Write(base::Pickle* m, const Message& p); 1007 static void Write(base::Pickle* m, const Message& p);
888 static bool Read(const base::Pickle* m, 1008 static bool Read(const base::Pickle* m,
889 base::PickleIterator* iter, 1009 base::PickleIterator* iter,
890 Message* r); 1010 Message* r);
891 static void Log(const Message& p, std::string* l); 1011 static void Log(const Message& p, std::string* l);
892 }; 1012 };
893 1013
894 // Windows ParamTraits --------------------------------------------------------- 1014 // Windows ParamTraits ---------------------------------------------------------
895 1015
896 #if defined(OS_WIN) 1016 #if defined(OS_WIN)
897 template <> 1017 template <>
898 struct IPC_EXPORT ParamTraits<HANDLE> { 1018 struct IPC_EXPORT ParamTraits<HANDLE> {
899 typedef HANDLE param_type; 1019 typedef HANDLE param_type;
1020 static void GetSize(base::PickleSizer* sizer, const param_type& p);
900 static void Write(base::Pickle* m, const param_type& p); 1021 static void Write(base::Pickle* m, const param_type& p);
901 static bool Read(const base::Pickle* m, 1022 static bool Read(const base::Pickle* m,
902 base::PickleIterator* iter, 1023 base::PickleIterator* iter,
903 param_type* r); 1024 param_type* r);
904 static void Log(const param_type& p, std::string* l); 1025 static void Log(const param_type& p, std::string* l);
905 }; 1026 };
906 1027
907 template <> 1028 template <>
908 struct IPC_EXPORT ParamTraits<LOGFONT> { 1029 struct IPC_EXPORT ParamTraits<LOGFONT> {
909 typedef LOGFONT param_type; 1030 typedef LOGFONT param_type;
1031 static void GetSize(base::PickleSizer* sizer, const param_type& p);
910 static void Write(base::Pickle* m, const param_type& p); 1032 static void Write(base::Pickle* m, const param_type& p);
911 static bool Read(const base::Pickle* m, 1033 static bool Read(const base::Pickle* m,
912 base::PickleIterator* iter, 1034 base::PickleIterator* iter,
913 param_type* r); 1035 param_type* r);
914 static void Log(const param_type& p, std::string* l); 1036 static void Log(const param_type& p, std::string* l);
915 }; 1037 };
916 1038
917 template <> 1039 template <>
918 struct IPC_EXPORT ParamTraits<MSG> { 1040 struct IPC_EXPORT ParamTraits<MSG> {
919 typedef MSG param_type; 1041 typedef MSG param_type;
1042 static void GetSize(base::PickleSizer* sizer, const param_type& p);
920 static void Write(base::Pickle* m, const param_type& p); 1043 static void Write(base::Pickle* m, const param_type& p);
921 static bool Read(const base::Pickle* m, 1044 static bool Read(const base::Pickle* m,
922 base::PickleIterator* iter, 1045 base::PickleIterator* iter,
923 param_type* r); 1046 param_type* r);
924 static void Log(const param_type& p, std::string* l); 1047 static void Log(const param_type& p, std::string* l);
925 }; 1048 };
926 #endif // defined(OS_WIN) 1049 #endif // defined(OS_WIN)
927 1050
928 //----------------------------------------------------------------------------- 1051 //-----------------------------------------------------------------------------
929 // Generic message subclasses 1052 // Generic message subclasses
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 template <typename... Ts> 1177 template <typename... Ts>
1055 static void WriteReplyParams(Message* reply, Ts... args) { 1178 static void WriteReplyParams(Message* reply, Ts... args) {
1056 ReplyParam p(args...); 1179 ReplyParam p(args...);
1057 WriteParam(reply, p); 1180 WriteParam(reply, p);
1058 } 1181 }
1059 }; 1182 };
1060 1183
1061 } // namespace IPC 1184 } // namespace IPC
1062 1185
1063 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1186 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW
« no previous file with comments | « ipc/ipc_message_macros.h ('k') | ipc/ipc_message_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698