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 "ipc/ipc_message_utils.h" | 5 #include "ipc/ipc_message_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 base::StringPrintf("[%02X]", static_cast<unsigned char>(data[i]))); | 60 base::StringPrintf("[%02X]", static_cast<unsigned char>(data[i]))); |
61 } | 61 } |
62 if (data.size() > kMaxBytesToLog) { | 62 if (data.size() > kMaxBytesToLog) { |
63 out->append(base::StringPrintf( | 63 out->append(base::StringPrintf( |
64 " and %u more bytes", | 64 " and %u more bytes", |
65 static_cast<unsigned>(data.size() - kMaxBytesToLog))); | 65 static_cast<unsigned>(data.size() - kMaxBytesToLog))); |
66 } | 66 } |
67 #endif | 67 #endif |
68 } | 68 } |
69 | 69 |
70 bool ReadValue(const Message* m, | 70 bool ReadValue(const base::Pickle* m, |
71 base::PickleIterator* iter, | 71 base::PickleIterator* iter, |
72 base::Value** value, | 72 base::Value** value, |
73 int recursion); | 73 int recursion); |
74 | 74 |
75 void WriteValue(Message* m, const base::Value* value, int recursion) { | 75 void WriteValue(base::Pickle* m, const base::Value* value, int recursion) { |
76 bool result; | 76 bool result; |
77 if (recursion > kMaxRecursionDepth) { | 77 if (recursion > kMaxRecursionDepth) { |
78 LOG(WARNING) << "Max recursion depth hit in WriteValue."; | 78 LOG(WARNING) << "Max recursion depth hit in WriteValue."; |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 m->WriteInt(value->GetType()); | 82 m->WriteInt(value->GetType()); |
83 | 83 |
84 switch (value->GetType()) { | 84 switch (value->GetType()) { |
85 case base::Value::TYPE_NULL: | 85 case base::Value::TYPE_NULL: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 it != list->end(); ++it) { | 138 it != list->end(); ++it) { |
139 WriteValue(m, *it, recursion + 1); | 139 WriteValue(m, *it, recursion + 1); |
140 } | 140 } |
141 break; | 141 break; |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 // Helper for ReadValue that reads a DictionaryValue into a pre-allocated | 146 // Helper for ReadValue that reads a DictionaryValue into a pre-allocated |
147 // object. | 147 // object. |
148 bool ReadDictionaryValue(const Message* m, | 148 bool ReadDictionaryValue(const base::Pickle* m, |
149 base::PickleIterator* iter, | 149 base::PickleIterator* iter, |
150 base::DictionaryValue* value, | 150 base::DictionaryValue* value, |
151 int recursion) { | 151 int recursion) { |
152 int size; | 152 int size; |
153 if (!ReadParam(m, iter, &size)) | 153 if (!ReadParam(m, iter, &size)) |
154 return false; | 154 return false; |
155 | 155 |
156 for (int i = 0; i < size; ++i) { | 156 for (int i = 0; i < size; ++i) { |
157 std::string key; | 157 std::string key; |
158 base::Value* subval; | 158 base::Value* subval; |
159 if (!ReadParam(m, iter, &key) || | 159 if (!ReadParam(m, iter, &key) || |
160 !ReadValue(m, iter, &subval, recursion + 1)) | 160 !ReadValue(m, iter, &subval, recursion + 1)) |
161 return false; | 161 return false; |
162 value->SetWithoutPathExpansion(key, subval); | 162 value->SetWithoutPathExpansion(key, subval); |
163 } | 163 } |
164 | 164 |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 // Helper for ReadValue that reads a ReadListValue into a pre-allocated | 168 // Helper for ReadValue that reads a ReadListValue into a pre-allocated |
169 // object. | 169 // object. |
170 bool ReadListValue(const Message* m, | 170 bool ReadListValue(const base::Pickle* m, |
171 base::PickleIterator* iter, | 171 base::PickleIterator* iter, |
172 base::ListValue* value, | 172 base::ListValue* value, |
173 int recursion) { | 173 int recursion) { |
174 int size; | 174 int size; |
175 if (!ReadParam(m, iter, &size)) | 175 if (!ReadParam(m, iter, &size)) |
176 return false; | 176 return false; |
177 | 177 |
178 for (int i = 0; i < size; ++i) { | 178 for (int i = 0; i < size; ++i) { |
179 base::Value* subval; | 179 base::Value* subval; |
180 if (!ReadValue(m, iter, &subval, recursion + 1)) | 180 if (!ReadValue(m, iter, &subval, recursion + 1)) |
181 return false; | 181 return false; |
182 value->Set(i, subval); | 182 value->Set(i, subval); |
183 } | 183 } |
184 | 184 |
185 return true; | 185 return true; |
186 } | 186 } |
187 | 187 |
188 bool ReadValue(const Message* m, | 188 bool ReadValue(const base::Pickle* m, |
189 base::PickleIterator* iter, | 189 base::PickleIterator* iter, |
190 base::Value** value, | 190 base::Value** value, |
191 int recursion) { | 191 int recursion) { |
192 if (recursion > kMaxRecursionDepth) { | 192 if (recursion > kMaxRecursionDepth) { |
193 LOG(WARNING) << "Max recursion depth hit in ReadValue."; | 193 LOG(WARNING) << "Max recursion depth hit in ReadValue."; |
194 return false; | 194 return false; |
195 } | 195 } |
196 | 196 |
197 int type; | 197 int type; |
198 if (!ReadParam(m, iter, &type)) | 198 if (!ReadParam(m, iter, &type)) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 dispatch(0) { | 271 dispatch(0) { |
272 } | 272 } |
273 | 273 |
274 LogData::~LogData() { | 274 LogData::~LogData() { |
275 } | 275 } |
276 | 276 |
277 void ParamTraits<bool>::Log(const param_type& p, std::string* l) { | 277 void ParamTraits<bool>::Log(const param_type& p, std::string* l) { |
278 l->append(p ? "true" : "false"); | 278 l->append(p ? "true" : "false"); |
279 } | 279 } |
280 | 280 |
281 void ParamTraits<signed char>::Write(Message* m, const param_type& p) { | 281 void ParamTraits<signed char>::Write(base::Pickle* m, const param_type& p) { |
282 m->WriteBytes(&p, sizeof(param_type)); | 282 m->WriteBytes(&p, sizeof(param_type)); |
283 } | 283 } |
284 | 284 |
285 bool ParamTraits<signed char>::Read(const Message* m, | 285 bool ParamTraits<signed char>::Read(const base::Pickle* m, |
286 base::PickleIterator* iter, | 286 base::PickleIterator* iter, |
287 param_type* r) { | 287 param_type* r) { |
288 const char* data; | 288 const char* data; |
289 if (!iter->ReadBytes(&data, sizeof(param_type))) | 289 if (!iter->ReadBytes(&data, sizeof(param_type))) |
290 return false; | 290 return false; |
291 memcpy(r, data, sizeof(param_type)); | 291 memcpy(r, data, sizeof(param_type)); |
292 return true; | 292 return true; |
293 } | 293 } |
294 | 294 |
295 void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { | 295 void ParamTraits<signed char>::Log(const param_type& p, std::string* l) { |
296 l->append(base::IntToString(p)); | 296 l->append(base::IntToString(p)); |
297 } | 297 } |
298 | 298 |
299 void ParamTraits<unsigned char>::Write(Message* m, const param_type& p) { | 299 void ParamTraits<unsigned char>::Write(base::Pickle* m, const param_type& p) { |
300 m->WriteBytes(&p, sizeof(param_type)); | 300 m->WriteBytes(&p, sizeof(param_type)); |
301 } | 301 } |
302 | 302 |
303 bool ParamTraits<unsigned char>::Read(const Message* m, | 303 bool ParamTraits<unsigned char>::Read(const base::Pickle* m, |
304 base::PickleIterator* iter, | 304 base::PickleIterator* iter, |
305 param_type* r) { | 305 param_type* r) { |
306 const char* data; | 306 const char* data; |
307 if (!iter->ReadBytes(&data, sizeof(param_type))) | 307 if (!iter->ReadBytes(&data, sizeof(param_type))) |
308 return false; | 308 return false; |
309 memcpy(r, data, sizeof(param_type)); | 309 memcpy(r, data, sizeof(param_type)); |
310 return true; | 310 return true; |
311 } | 311 } |
312 | 312 |
313 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { | 313 void ParamTraits<unsigned char>::Log(const param_type& p, std::string* l) { |
314 l->append(base::UintToString(p)); | 314 l->append(base::UintToString(p)); |
315 } | 315 } |
316 | 316 |
317 void ParamTraits<unsigned short>::Write(Message* m, const param_type& p) { | 317 void ParamTraits<unsigned short>::Write(base::Pickle* m, const param_type& p) { |
318 m->WriteBytes(&p, sizeof(param_type)); | 318 m->WriteBytes(&p, sizeof(param_type)); |
319 } | 319 } |
320 | 320 |
321 bool ParamTraits<unsigned short>::Read(const Message* m, | 321 bool ParamTraits<unsigned short>::Read(const base::Pickle* m, |
322 base::PickleIterator* iter, | 322 base::PickleIterator* iter, |
323 param_type* r) { | 323 param_type* r) { |
324 const char* data; | 324 const char* data; |
325 if (!iter->ReadBytes(&data, sizeof(param_type))) | 325 if (!iter->ReadBytes(&data, sizeof(param_type))) |
326 return false; | 326 return false; |
327 memcpy(r, data, sizeof(param_type)); | 327 memcpy(r, data, sizeof(param_type)); |
328 return true; | 328 return true; |
329 } | 329 } |
330 | 330 |
331 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { | 331 void ParamTraits<unsigned short>::Log(const param_type& p, std::string* l) { |
(...skipping 21 matching lines...) Expand all Loading... |
353 } | 353 } |
354 | 354 |
355 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { | 355 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { |
356 l->append(base::Uint64ToString(p)); | 356 l->append(base::Uint64ToString(p)); |
357 } | 357 } |
358 | 358 |
359 void ParamTraits<float>::Log(const param_type& p, std::string* l) { | 359 void ParamTraits<float>::Log(const param_type& p, std::string* l) { |
360 l->append(base::StringPrintf("%e", p)); | 360 l->append(base::StringPrintf("%e", p)); |
361 } | 361 } |
362 | 362 |
363 void ParamTraits<double>::Write(Message* m, const param_type& p) { | 363 void ParamTraits<double>::Write(base::Pickle* m, const param_type& p) { |
364 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); | 364 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type)); |
365 } | 365 } |
366 | 366 |
367 bool ParamTraits<double>::Read(const Message* m, | 367 bool ParamTraits<double>::Read(const base::Pickle* m, |
368 base::PickleIterator* iter, | 368 base::PickleIterator* iter, |
369 param_type* r) { | 369 param_type* r) { |
370 const char *data; | 370 const char *data; |
371 if (!iter->ReadBytes(&data, sizeof(*r))) { | 371 if (!iter->ReadBytes(&data, sizeof(*r))) { |
372 NOTREACHED(); | 372 NOTREACHED(); |
373 return false; | 373 return false; |
374 } | 374 } |
375 memcpy(r, data, sizeof(param_type)); | 375 memcpy(r, data, sizeof(param_type)); |
376 return true; | 376 return true; |
377 } | 377 } |
378 | 378 |
379 void ParamTraits<double>::Log(const param_type& p, std::string* l) { | 379 void ParamTraits<double>::Log(const param_type& p, std::string* l) { |
380 l->append(base::StringPrintf("%e", p)); | 380 l->append(base::StringPrintf("%e", p)); |
381 } | 381 } |
382 | 382 |
383 | 383 |
384 void ParamTraits<std::string>::Log(const param_type& p, std::string* l) { | 384 void ParamTraits<std::string>::Log(const param_type& p, std::string* l) { |
385 l->append(p); | 385 l->append(p); |
386 } | 386 } |
387 | 387 |
388 void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { | 388 void ParamTraits<base::string16>::Log(const param_type& p, std::string* l) { |
389 l->append(base::UTF16ToUTF8(p)); | 389 l->append(base::UTF16ToUTF8(p)); |
390 } | 390 } |
391 | 391 |
392 void ParamTraits<std::vector<char> >::Write(Message* m, const param_type& p) { | 392 void ParamTraits<std::vector<char>>::Write(base::Pickle* m, |
| 393 const param_type& p) { |
393 if (p.empty()) { | 394 if (p.empty()) { |
394 m->WriteData(NULL, 0); | 395 m->WriteData(NULL, 0); |
395 } else { | 396 } else { |
396 m->WriteData(&p.front(), static_cast<int>(p.size())); | 397 m->WriteData(&p.front(), static_cast<int>(p.size())); |
397 } | 398 } |
398 } | 399 } |
399 | 400 |
400 bool ParamTraits<std::vector<char>>::Read(const Message* m, | 401 bool ParamTraits<std::vector<char>>::Read(const base::Pickle* m, |
401 base::PickleIterator* iter, | 402 base::PickleIterator* iter, |
402 param_type* r) { | 403 param_type* r) { |
403 const char *data; | 404 const char *data; |
404 int data_size = 0; | 405 int data_size = 0; |
405 if (!iter->ReadData(&data, &data_size) || data_size < 0) | 406 if (!iter->ReadData(&data, &data_size) || data_size < 0) |
406 return false; | 407 return false; |
407 r->resize(data_size); | 408 r->resize(data_size); |
408 if (data_size) | 409 if (data_size) |
409 memcpy(&r->front(), data, data_size); | 410 memcpy(&r->front(), data, data_size); |
410 return true; | 411 return true; |
411 } | 412 } |
412 | 413 |
413 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { | 414 void ParamTraits<std::vector<char> >::Log(const param_type& p, std::string* l) { |
414 LogBytes(p, l); | 415 LogBytes(p, l); |
415 } | 416 } |
416 | 417 |
417 void ParamTraits<std::vector<unsigned char> >::Write(Message* m, | 418 void ParamTraits<std::vector<unsigned char>>::Write(base::Pickle* m, |
418 const param_type& p) { | 419 const param_type& p) { |
419 if (p.empty()) { | 420 if (p.empty()) { |
420 m->WriteData(NULL, 0); | 421 m->WriteData(NULL, 0); |
421 } else { | 422 } else { |
422 m->WriteData(reinterpret_cast<const char*>(&p.front()), | 423 m->WriteData(reinterpret_cast<const char*>(&p.front()), |
423 static_cast<int>(p.size())); | 424 static_cast<int>(p.size())); |
424 } | 425 } |
425 } | 426 } |
426 | 427 |
427 bool ParamTraits<std::vector<unsigned char>>::Read(const Message* m, | 428 bool ParamTraits<std::vector<unsigned char>>::Read(const base::Pickle* m, |
428 base::PickleIterator* iter, | 429 base::PickleIterator* iter, |
429 param_type* r) { | 430 param_type* r) { |
430 const char *data; | 431 const char *data; |
431 int data_size = 0; | 432 int data_size = 0; |
432 if (!iter->ReadData(&data, &data_size) || data_size < 0) | 433 if (!iter->ReadData(&data, &data_size) || data_size < 0) |
433 return false; | 434 return false; |
434 r->resize(data_size); | 435 r->resize(data_size); |
435 if (data_size) | 436 if (data_size) |
436 memcpy(&r->front(), data, data_size); | 437 memcpy(&r->front(), data, data_size); |
437 return true; | 438 return true; |
438 } | 439 } |
439 | 440 |
440 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, | 441 void ParamTraits<std::vector<unsigned char> >::Log(const param_type& p, |
441 std::string* l) { | 442 std::string* l) { |
442 LogBytes(p, l); | 443 LogBytes(p, l); |
443 } | 444 } |
444 | 445 |
445 void ParamTraits<std::vector<bool> >::Write(Message* m, const param_type& p) { | 446 void ParamTraits<std::vector<bool>>::Write(base::Pickle* m, |
| 447 const param_type& p) { |
446 WriteParam(m, static_cast<int>(p.size())); | 448 WriteParam(m, static_cast<int>(p.size())); |
447 // Cast to bool below is required because libc++'s | 449 // Cast to bool below is required because libc++'s |
448 // vector<bool>::const_reference is different from bool, and we want to avoid | 450 // vector<bool>::const_reference is different from bool, and we want to avoid |
449 // writing an extra specialization of ParamTraits for it. | 451 // writing an extra specialization of ParamTraits for it. |
450 for (size_t i = 0; i < p.size(); i++) | 452 for (size_t i = 0; i < p.size(); i++) |
451 WriteParam(m, static_cast<bool>(p[i])); | 453 WriteParam(m, static_cast<bool>(p[i])); |
452 } | 454 } |
453 | 455 |
454 bool ParamTraits<std::vector<bool>>::Read(const Message* m, | 456 bool ParamTraits<std::vector<bool>>::Read(const base::Pickle* m, |
455 base::PickleIterator* iter, | 457 base::PickleIterator* iter, |
456 param_type* r) { | 458 param_type* r) { |
457 int size; | 459 int size; |
458 // ReadLength() checks for < 0 itself. | 460 // ReadLength() checks for < 0 itself. |
459 if (!iter->ReadLength(&size)) | 461 if (!iter->ReadLength(&size)) |
460 return false; | 462 return false; |
461 r->resize(size); | 463 r->resize(size); |
462 for (int i = 0; i < size; i++) { | 464 for (int i = 0; i < size; i++) { |
463 bool value; | 465 bool value; |
464 if (!ReadParam(m, iter, &value)) | 466 if (!ReadParam(m, iter, &value)) |
465 return false; | 467 return false; |
466 (*r)[i] = value; | 468 (*r)[i] = value; |
467 } | 469 } |
468 return true; | 470 return true; |
469 } | 471 } |
470 | 472 |
471 void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) { | 473 void ParamTraits<std::vector<bool> >::Log(const param_type& p, std::string* l) { |
472 for (size_t i = 0; i < p.size(); ++i) { | 474 for (size_t i = 0; i < p.size(); ++i) { |
473 if (i != 0) | 475 if (i != 0) |
474 l->push_back(' '); | 476 l->push_back(' '); |
475 LogParam(static_cast<bool>(p[i]), l); | 477 LogParam(static_cast<bool>(p[i]), l); |
476 } | 478 } |
477 } | 479 } |
478 | 480 |
479 void ParamTraits<BrokerableAttachment::AttachmentId>::Write( | 481 void ParamTraits<BrokerableAttachment::AttachmentId>::Write( |
480 Message* m, | 482 base::Pickle* m, |
481 const param_type& p) { | 483 const param_type& p) { |
482 m->WriteBytes(p.nonce, BrokerableAttachment::kNonceSize); | 484 m->WriteBytes(p.nonce, BrokerableAttachment::kNonceSize); |
483 } | 485 } |
484 | 486 |
485 bool ParamTraits<BrokerableAttachment::AttachmentId>::Read( | 487 bool ParamTraits<BrokerableAttachment::AttachmentId>::Read( |
486 const Message* m, | 488 const base::Pickle* m, |
487 base::PickleIterator* iter, | 489 base::PickleIterator* iter, |
488 param_type* r) { | 490 param_type* r) { |
489 const char* data; | 491 const char* data; |
490 if (!iter->ReadBytes(&data, BrokerableAttachment::kNonceSize)) | 492 if (!iter->ReadBytes(&data, BrokerableAttachment::kNonceSize)) |
491 return false; | 493 return false; |
492 memcpy(r->nonce, data, BrokerableAttachment::kNonceSize); | 494 memcpy(r->nonce, data, BrokerableAttachment::kNonceSize); |
493 return true; | 495 return true; |
494 } | 496 } |
495 | 497 |
496 void ParamTraits<BrokerableAttachment::AttachmentId>::Log(const param_type& p, | 498 void ParamTraits<BrokerableAttachment::AttachmentId>::Log(const param_type& p, |
497 std::string* l) { | 499 std::string* l) { |
498 l->append(base::HexEncode(p.nonce, BrokerableAttachment::kNonceSize)); | 500 l->append(base::HexEncode(p.nonce, BrokerableAttachment::kNonceSize)); |
499 } | 501 } |
500 | 502 |
501 void ParamTraits<base::DictionaryValue>::Write(Message* m, | 503 void ParamTraits<base::DictionaryValue>::Write(base::Pickle* m, |
502 const param_type& p) { | 504 const param_type& p) { |
503 WriteValue(m, &p, 0); | 505 WriteValue(m, &p, 0); |
504 } | 506 } |
505 | 507 |
506 bool ParamTraits<base::DictionaryValue>::Read(const Message* m, | 508 bool ParamTraits<base::DictionaryValue>::Read(const base::Pickle* m, |
507 base::PickleIterator* iter, | 509 base::PickleIterator* iter, |
508 param_type* r) { | 510 param_type* r) { |
509 int type; | 511 int type; |
510 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) | 512 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_DICTIONARY) |
511 return false; | 513 return false; |
512 | 514 |
513 return ReadDictionaryValue(m, iter, r, 0); | 515 return ReadDictionaryValue(m, iter, r, 0); |
514 } | 516 } |
515 | 517 |
516 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, | 518 void ParamTraits<base::DictionaryValue>::Log(const param_type& p, |
517 std::string* l) { | 519 std::string* l) { |
518 std::string json; | 520 std::string json; |
519 base::JSONWriter::Write(p, &json); | 521 base::JSONWriter::Write(p, &json); |
520 l->append(json); | 522 l->append(json); |
521 } | 523 } |
522 | 524 |
523 #if defined(OS_POSIX) | 525 #if defined(OS_POSIX) |
524 void ParamTraits<base::FileDescriptor>::Write(Message* m, const param_type& p) { | 526 void ParamTraits<base::FileDescriptor>::Write(base::Pickle* m, |
| 527 const param_type& p) { |
525 const bool valid = p.fd >= 0; | 528 const bool valid = p.fd >= 0; |
526 WriteParam(m, valid); | 529 WriteParam(m, valid); |
527 | 530 |
528 if (!valid) | 531 if (!valid) |
529 return; | 532 return; |
530 | 533 |
531 if (p.auto_close) { | 534 if (p.auto_close) { |
532 if (!m->WriteAttachment( | 535 if (!m->WriteAttachment( |
533 new internal::PlatformFileAttachment(base::ScopedFD(p.fd)))) | 536 new internal::PlatformFileAttachment(base::ScopedFD(p.fd)))) |
534 NOTREACHED(); | 537 NOTREACHED(); |
535 } else { | 538 } else { |
536 if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd))) | 539 if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd))) |
537 NOTREACHED(); | 540 NOTREACHED(); |
538 } | 541 } |
539 } | 542 } |
540 | 543 |
541 bool ParamTraits<base::FileDescriptor>::Read(const Message* m, | 544 bool ParamTraits<base::FileDescriptor>::Read(const base::Pickle* m, |
542 base::PickleIterator* iter, | 545 base::PickleIterator* iter, |
543 param_type* r) { | 546 param_type* r) { |
544 *r = base::FileDescriptor(); | 547 *r = base::FileDescriptor(); |
545 | 548 |
546 bool valid; | 549 bool valid; |
547 if (!ReadParam(m, iter, &valid)) | 550 if (!ReadParam(m, iter, &valid)) |
548 return false; | 551 return false; |
549 | 552 |
550 // TODO(morrita): Seems like this should return false. | 553 // TODO(morrita): Seems like this should return false. |
551 if (!valid) | 554 if (!valid) |
552 return true; | 555 return true; |
553 | 556 |
554 scoped_refptr<MessageAttachment> attachment; | 557 scoped_refptr<base::Pickle::Attachment> attachment; |
555 if (!m->ReadAttachment(iter, &attachment)) | 558 if (!m->ReadAttachment(iter, &attachment)) |
556 return false; | 559 return false; |
557 | 560 |
558 *r = base::FileDescriptor(attachment->TakePlatformFile(), true); | 561 *r = base::FileDescriptor( |
| 562 static_cast<MessageAttachment*>(attachment.get())->TakePlatformFile(), |
| 563 true); |
559 return true; | 564 return true; |
560 } | 565 } |
561 | 566 |
562 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, | 567 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
563 std::string* l) { | 568 std::string* l) { |
564 if (p.auto_close) { | 569 if (p.auto_close) { |
565 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); | 570 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
566 } else { | 571 } else { |
567 l->append(base::StringPrintf("FD(%d)", p.fd)); | 572 l->append(base::StringPrintf("FD(%d)", p.fd)); |
568 } | 573 } |
569 } | 574 } |
570 #endif // defined(OS_POSIX) | 575 #endif // defined(OS_POSIX) |
571 | 576 |
572 #if defined(OS_MACOSX) && !defined(OS_IOS) | 577 #if defined(OS_MACOSX) && !defined(OS_IOS) |
573 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m, | 578 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
574 const param_type& p) { | 579 const param_type& p) { |
575 m->WriteInt(p.GetType()); | 580 m->WriteInt(p.GetType()); |
576 | 581 |
577 switch (p.GetType()) { | 582 switch (p.GetType()) { |
578 case base::SharedMemoryHandle::POSIX: | 583 case base::SharedMemoryHandle::POSIX: |
579 ParamTraits<base::FileDescriptor>::Write(m, p.GetFileDescriptor()); | 584 ParamTraits<base::FileDescriptor>::Write(m, p.GetFileDescriptor()); |
580 break; | 585 break; |
581 case base::SharedMemoryHandle::MACH: | 586 case base::SharedMemoryHandle::MACH: |
582 MachPortMac mach_port_mac(p.GetMemoryObject()); | 587 MachPortMac mach_port_mac(p.GetMemoryObject()); |
583 ParamTraits<MachPortMac>::Write(m, mach_port_mac); | 588 ParamTraits<MachPortMac>::Write(m, mach_port_mac); |
584 size_t size = 0; | 589 size_t size = 0; |
585 bool result = p.GetSize(&size); | 590 bool result = p.GetSize(&size); |
586 DCHECK(result); | 591 DCHECK(result); |
587 ParamTraits<size_t>::Write(m, size); | 592 ParamTraits<size_t>::Write(m, size); |
588 | 593 |
589 // If the caller intended to pass ownership to the IPC stack, release a | 594 // If the caller intended to pass ownership to the IPC stack, release a |
590 // reference. | 595 // reference. |
591 if (p.OwnershipPassesToIPC()) | 596 if (p.OwnershipPassesToIPC()) |
592 p.Close(); | 597 p.Close(); |
593 | 598 |
594 break; | 599 break; |
595 } | 600 } |
596 } | 601 } |
597 | 602 |
598 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, | 603 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
599 base::PickleIterator* iter, | 604 base::PickleIterator* iter, |
600 param_type* r) { | 605 param_type* r) { |
601 base::SharedMemoryHandle::TypeWireFormat type; | 606 base::SharedMemoryHandle::TypeWireFormat type; |
602 if (!iter->ReadInt(&type)) | 607 if (!iter->ReadInt(&type)) |
603 return false; | 608 return false; |
604 | 609 |
605 base::SharedMemoryHandle::Type shm_type = base::SharedMemoryHandle::POSIX; | 610 base::SharedMemoryHandle::Type shm_type = base::SharedMemoryHandle::POSIX; |
606 switch (type) { | 611 switch (type) { |
607 case base::SharedMemoryHandle::POSIX: | 612 case base::SharedMemoryHandle::POSIX: |
608 case base::SharedMemoryHandle::MACH: { | 613 case base::SharedMemoryHandle::MACH: { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l); | 656 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l); |
652 break; | 657 break; |
653 case base::SharedMemoryHandle::MACH: | 658 case base::SharedMemoryHandle::MACH: |
654 l->append("Mach port: "); | 659 l->append("Mach port: "); |
655 LogParam(p.GetMemoryObject(), l); | 660 LogParam(p.GetMemoryObject(), l); |
656 break; | 661 break; |
657 } | 662 } |
658 } | 663 } |
659 | 664 |
660 #elif defined(OS_WIN) | 665 #elif defined(OS_WIN) |
661 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m, | 666 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
662 const param_type& p) { | 667 const param_type& p) { |
663 m->WriteBool(p.NeedsBrokering()); | 668 m->WriteBool(p.NeedsBrokering()); |
664 | 669 |
665 if (p.NeedsBrokering()) { | 670 if (p.NeedsBrokering()) { |
666 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); | 671 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); |
667 ParamTraits<HandleWin>::Write(m, handle_win); | 672 ParamTraits<HandleWin>::Write(m, handle_win); |
668 } else { | 673 } else { |
669 m->WriteInt(HandleToLong(p.GetHandle())); | 674 m->WriteInt(HandleToLong(p.GetHandle())); |
670 } | 675 } |
671 } | 676 } |
672 | 677 |
673 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, | 678 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
674 base::PickleIterator* iter, | 679 base::PickleIterator* iter, |
675 param_type* r) { | 680 param_type* r) { |
676 bool needs_brokering; | 681 bool needs_brokering; |
677 if (!iter->ReadBool(&needs_brokering)) | 682 if (!iter->ReadBool(&needs_brokering)) |
678 return false; | 683 return false; |
679 | 684 |
680 if (needs_brokering) { | 685 if (needs_brokering) { |
681 HandleWin handle_win; | 686 HandleWin handle_win; |
682 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win)) | 687 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win)) |
683 return false; | 688 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
695 } | 700 } |
696 | 701 |
697 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | 702 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
698 std::string* l) { | 703 std::string* l) { |
699 LogParam(p.GetHandle(), l); | 704 LogParam(p.GetHandle(), l); |
700 l->append(" needs brokering: "); | 705 l->append(" needs brokering: "); |
701 LogParam(p.NeedsBrokering(), l); | 706 LogParam(p.NeedsBrokering(), l); |
702 } | 707 } |
703 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 708 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
704 | 709 |
705 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { | 710 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { |
706 p.WriteToPickle(m); | 711 p.WriteToPickle(m); |
707 } | 712 } |
708 | 713 |
709 bool ParamTraits<base::FilePath>::Read(const Message* m, | 714 bool ParamTraits<base::FilePath>::Read(const base::Pickle* m, |
710 base::PickleIterator* iter, | 715 base::PickleIterator* iter, |
711 param_type* r) { | 716 param_type* r) { |
712 return r->ReadFromPickle(iter); | 717 return r->ReadFromPickle(iter); |
713 } | 718 } |
714 | 719 |
715 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { | 720 void ParamTraits<base::FilePath>::Log(const param_type& p, std::string* l) { |
716 ParamTraits<base::FilePath::StringType>::Log(p.value(), l); | 721 ParamTraits<base::FilePath::StringType>::Log(p.value(), l); |
717 } | 722 } |
718 | 723 |
719 void ParamTraits<base::ListValue>::Write(Message* m, const param_type& p) { | 724 void ParamTraits<base::ListValue>::Write(base::Pickle* m, const param_type& p) { |
720 WriteValue(m, &p, 0); | 725 WriteValue(m, &p, 0); |
721 } | 726 } |
722 | 727 |
723 bool ParamTraits<base::ListValue>::Read(const Message* m, | 728 bool ParamTraits<base::ListValue>::Read(const base::Pickle* m, |
724 base::PickleIterator* iter, | 729 base::PickleIterator* iter, |
725 param_type* r) { | 730 param_type* r) { |
726 int type; | 731 int type; |
727 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) | 732 if (!ReadParam(m, iter, &type) || type != base::Value::TYPE_LIST) |
728 return false; | 733 return false; |
729 | 734 |
730 return ReadListValue(m, iter, r, 0); | 735 return ReadListValue(m, iter, r, 0); |
731 } | 736 } |
732 | 737 |
733 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { | 738 void ParamTraits<base::ListValue>::Log(const param_type& p, std::string* l) { |
734 std::string json; | 739 std::string json; |
735 base::JSONWriter::Write(p, &json); | 740 base::JSONWriter::Write(p, &json); |
736 l->append(json); | 741 l->append(json); |
737 } | 742 } |
738 | 743 |
739 void ParamTraits<base::NullableString16>::Write(Message* m, | 744 void ParamTraits<base::NullableString16>::Write(base::Pickle* m, |
740 const param_type& p) { | 745 const param_type& p) { |
741 WriteParam(m, p.string()); | 746 WriteParam(m, p.string()); |
742 WriteParam(m, p.is_null()); | 747 WriteParam(m, p.is_null()); |
743 } | 748 } |
744 | 749 |
745 bool ParamTraits<base::NullableString16>::Read(const Message* m, | 750 bool ParamTraits<base::NullableString16>::Read(const base::Pickle* m, |
746 base::PickleIterator* iter, | 751 base::PickleIterator* iter, |
747 param_type* r) { | 752 param_type* r) { |
748 base::string16 string; | 753 base::string16 string; |
749 if (!ReadParam(m, iter, &string)) | 754 if (!ReadParam(m, iter, &string)) |
750 return false; | 755 return false; |
751 bool is_null; | 756 bool is_null; |
752 if (!ReadParam(m, iter, &is_null)) | 757 if (!ReadParam(m, iter, &is_null)) |
753 return false; | 758 return false; |
754 *r = base::NullableString16(string, is_null); | 759 *r = base::NullableString16(string, is_null); |
755 return true; | 760 return true; |
756 } | 761 } |
757 | 762 |
758 void ParamTraits<base::NullableString16>::Log(const param_type& p, | 763 void ParamTraits<base::NullableString16>::Log(const param_type& p, |
759 std::string* l) { | 764 std::string* l) { |
760 l->append("("); | 765 l->append("("); |
761 LogParam(p.string(), l); | 766 LogParam(p.string(), l); |
762 l->append(", "); | 767 l->append(", "); |
763 LogParam(p.is_null(), l); | 768 LogParam(p.is_null(), l); |
764 l->append(")"); | 769 l->append(")"); |
765 } | 770 } |
766 | 771 |
767 void ParamTraits<base::File::Info>::Write(Message* m, | 772 void ParamTraits<base::File::Info>::Write(base::Pickle* m, |
768 const param_type& p) { | 773 const param_type& p) { |
769 WriteParam(m, p.size); | 774 WriteParam(m, p.size); |
770 WriteParam(m, p.is_directory); | 775 WriteParam(m, p.is_directory); |
771 WriteParam(m, p.last_modified.ToDoubleT()); | 776 WriteParam(m, p.last_modified.ToDoubleT()); |
772 WriteParam(m, p.last_accessed.ToDoubleT()); | 777 WriteParam(m, p.last_accessed.ToDoubleT()); |
773 WriteParam(m, p.creation_time.ToDoubleT()); | 778 WriteParam(m, p.creation_time.ToDoubleT()); |
774 } | 779 } |
775 | 780 |
776 bool ParamTraits<base::File::Info>::Read(const Message* m, | 781 bool ParamTraits<base::File::Info>::Read(const base::Pickle* m, |
777 base::PickleIterator* iter, | 782 base::PickleIterator* iter, |
778 param_type* p) { | 783 param_type* p) { |
779 double last_modified, last_accessed, creation_time; | 784 double last_modified, last_accessed, creation_time; |
780 if (!ReadParam(m, iter, &p->size) || | 785 if (!ReadParam(m, iter, &p->size) || |
781 !ReadParam(m, iter, &p->is_directory) || | 786 !ReadParam(m, iter, &p->is_directory) || |
782 !ReadParam(m, iter, &last_modified) || | 787 !ReadParam(m, iter, &last_modified) || |
783 !ReadParam(m, iter, &last_accessed) || | 788 !ReadParam(m, iter, &last_accessed) || |
784 !ReadParam(m, iter, &creation_time)) | 789 !ReadParam(m, iter, &creation_time)) |
785 return false; | 790 return false; |
786 p->last_modified = base::Time::FromDoubleT(last_modified); | 791 p->last_modified = base::Time::FromDoubleT(last_modified); |
(...skipping 10 matching lines...) Expand all Loading... |
797 LogParam(p.is_directory, l); | 802 LogParam(p.is_directory, l); |
798 l->append(","); | 803 l->append(","); |
799 LogParam(p.last_modified.ToDoubleT(), l); | 804 LogParam(p.last_modified.ToDoubleT(), l); |
800 l->append(","); | 805 l->append(","); |
801 LogParam(p.last_accessed.ToDoubleT(), l); | 806 LogParam(p.last_accessed.ToDoubleT(), l); |
802 l->append(","); | 807 l->append(","); |
803 LogParam(p.creation_time.ToDoubleT(), l); | 808 LogParam(p.creation_time.ToDoubleT(), l); |
804 l->append(")"); | 809 l->append(")"); |
805 } | 810 } |
806 | 811 |
807 void ParamTraits<base::Time>::Write(Message* m, const param_type& p) { | 812 void ParamTraits<base::Time>::Write(base::Pickle* m, const param_type& p) { |
808 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 813 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
809 } | 814 } |
810 | 815 |
811 bool ParamTraits<base::Time>::Read(const Message* m, | 816 bool ParamTraits<base::Time>::Read(const base::Pickle* m, |
812 base::PickleIterator* iter, | 817 base::PickleIterator* iter, |
813 param_type* r) { | 818 param_type* r) { |
814 int64_t value; | 819 int64_t value; |
815 if (!ParamTraits<int64_t>::Read(m, iter, &value)) | 820 if (!ParamTraits<int64_t>::Read(m, iter, &value)) |
816 return false; | 821 return false; |
817 *r = base::Time::FromInternalValue(value); | 822 *r = base::Time::FromInternalValue(value); |
818 return true; | 823 return true; |
819 } | 824 } |
820 | 825 |
821 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { | 826 void ParamTraits<base::Time>::Log(const param_type& p, std::string* l) { |
822 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 827 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
823 } | 828 } |
824 | 829 |
825 void ParamTraits<base::TimeDelta>::Write(Message* m, const param_type& p) { | 830 void ParamTraits<base::TimeDelta>::Write(base::Pickle* m, const param_type& p) { |
826 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 831 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
827 } | 832 } |
828 | 833 |
829 bool ParamTraits<base::TimeDelta>::Read(const Message* m, | 834 bool ParamTraits<base::TimeDelta>::Read(const base::Pickle* m, |
830 base::PickleIterator* iter, | 835 base::PickleIterator* iter, |
831 param_type* r) { | 836 param_type* r) { |
832 int64_t value; | 837 int64_t value; |
833 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); | 838 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
834 if (ret) | 839 if (ret) |
835 *r = base::TimeDelta::FromInternalValue(value); | 840 *r = base::TimeDelta::FromInternalValue(value); |
836 | 841 |
837 return ret; | 842 return ret; |
838 } | 843 } |
839 | 844 |
840 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { | 845 void ParamTraits<base::TimeDelta>::Log(const param_type& p, std::string* l) { |
841 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 846 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
842 } | 847 } |
843 | 848 |
844 void ParamTraits<base::TimeTicks>::Write(Message* m, const param_type& p) { | 849 void ParamTraits<base::TimeTicks>::Write(base::Pickle* m, const param_type& p) { |
845 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); | 850 ParamTraits<int64_t>::Write(m, p.ToInternalValue()); |
846 } | 851 } |
847 | 852 |
848 bool ParamTraits<base::TimeTicks>::Read(const Message* m, | 853 bool ParamTraits<base::TimeTicks>::Read(const base::Pickle* m, |
849 base::PickleIterator* iter, | 854 base::PickleIterator* iter, |
850 param_type* r) { | 855 param_type* r) { |
851 int64_t value; | 856 int64_t value; |
852 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); | 857 bool ret = ParamTraits<int64_t>::Read(m, iter, &value); |
853 if (ret) | 858 if (ret) |
854 *r = base::TimeTicks::FromInternalValue(value); | 859 *r = base::TimeTicks::FromInternalValue(value); |
855 | 860 |
856 return ret; | 861 return ret; |
857 } | 862 } |
858 | 863 |
859 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { | 864 void ParamTraits<base::TimeTicks>::Log(const param_type& p, std::string* l) { |
860 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); | 865 ParamTraits<int64_t>::Log(p.ToInternalValue(), l); |
861 } | 866 } |
862 | 867 |
863 void ParamTraits<IPC::ChannelHandle>::Write(Message* m, const param_type& p) { | 868 void ParamTraits<IPC::ChannelHandle>::Write(base::Pickle* m, |
| 869 const param_type& p) { |
864 #if defined(OS_WIN) | 870 #if defined(OS_WIN) |
865 // On Windows marshalling pipe handle is not supported. | 871 // On Windows marshalling pipe handle is not supported. |
866 DCHECK(p.pipe.handle == NULL); | 872 DCHECK(p.pipe.handle == NULL); |
867 #endif // defined (OS_WIN) | 873 #endif // defined (OS_WIN) |
868 WriteParam(m, p.name); | 874 WriteParam(m, p.name); |
869 #if defined(OS_POSIX) | 875 #if defined(OS_POSIX) |
870 WriteParam(m, p.socket); | 876 WriteParam(m, p.socket); |
871 #endif | 877 #endif |
872 } | 878 } |
873 | 879 |
874 bool ParamTraits<IPC::ChannelHandle>::Read(const Message* m, | 880 bool ParamTraits<IPC::ChannelHandle>::Read(const base::Pickle* m, |
875 base::PickleIterator* iter, | 881 base::PickleIterator* iter, |
876 param_type* r) { | 882 param_type* r) { |
877 return ReadParam(m, iter, &r->name) | 883 return ReadParam(m, iter, &r->name) |
878 #if defined(OS_POSIX) | 884 #if defined(OS_POSIX) |
879 && ReadParam(m, iter, &r->socket) | 885 && ReadParam(m, iter, &r->socket) |
880 #endif | 886 #endif |
881 ; | 887 ; |
882 } | 888 } |
883 | 889 |
884 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, | 890 void ParamTraits<IPC::ChannelHandle>::Log(const param_type& p, |
885 std::string* l) { | 891 std::string* l) { |
886 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); | 892 l->append(base::StringPrintf("ChannelHandle(%s", p.name.c_str())); |
887 #if defined(OS_POSIX) | 893 #if defined(OS_POSIX) |
888 l->append(", "); | 894 l->append(", "); |
889 ParamTraits<base::FileDescriptor>::Log(p.socket, l); | 895 ParamTraits<base::FileDescriptor>::Log(p.socket, l); |
890 #endif | 896 #endif |
891 l->append(")"); | 897 l->append(")"); |
892 } | 898 } |
893 | 899 |
894 void ParamTraits<LogData>::Write(Message* m, const param_type& p) { | 900 void ParamTraits<LogData>::Write(base::Pickle* m, const param_type& p) { |
895 WriteParam(m, p.channel); | 901 WriteParam(m, p.channel); |
896 WriteParam(m, p.routing_id); | 902 WriteParam(m, p.routing_id); |
897 WriteParam(m, p.type); | 903 WriteParam(m, p.type); |
898 WriteParam(m, p.flags); | 904 WriteParam(m, p.flags); |
899 WriteParam(m, p.sent); | 905 WriteParam(m, p.sent); |
900 WriteParam(m, p.receive); | 906 WriteParam(m, p.receive); |
901 WriteParam(m, p.dispatch); | 907 WriteParam(m, p.dispatch); |
902 WriteParam(m, p.message_name); | 908 WriteParam(m, p.message_name); |
903 WriteParam(m, p.params); | 909 WriteParam(m, p.params); |
904 } | 910 } |
905 | 911 |
906 bool ParamTraits<LogData>::Read(const Message* m, | 912 bool ParamTraits<LogData>::Read(const base::Pickle* m, |
907 base::PickleIterator* iter, | 913 base::PickleIterator* iter, |
908 param_type* r) { | 914 param_type* r) { |
909 return | 915 return |
910 ReadParam(m, iter, &r->channel) && | 916 ReadParam(m, iter, &r->channel) && |
911 ReadParam(m, iter, &r->routing_id) && | 917 ReadParam(m, iter, &r->routing_id) && |
912 ReadParam(m, iter, &r->type) && | 918 ReadParam(m, iter, &r->type) && |
913 ReadParam(m, iter, &r->flags) && | 919 ReadParam(m, iter, &r->flags) && |
914 ReadParam(m, iter, &r->sent) && | 920 ReadParam(m, iter, &r->sent) && |
915 ReadParam(m, iter, &r->receive) && | 921 ReadParam(m, iter, &r->receive) && |
916 ReadParam(m, iter, &r->dispatch) && | 922 ReadParam(m, iter, &r->dispatch) && |
917 ReadParam(m, iter, &r->message_name) && | 923 ReadParam(m, iter, &r->message_name) && |
918 ReadParam(m, iter, &r->params); | 924 ReadParam(m, iter, &r->params); |
919 } | 925 } |
920 | 926 |
921 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { | 927 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { |
922 // Doesn't make sense to implement this! | 928 // Doesn't make sense to implement this! |
923 } | 929 } |
924 | 930 |
925 void ParamTraits<Message>::Write(Message* m, const Message& p) { | 931 void ParamTraits<Message>::Write(base::Pickle* m, const Message& p) { |
926 #if defined(OS_POSIX) | 932 #if defined(OS_POSIX) |
927 // We don't serialize the file descriptors in the nested message, so there | 933 // We don't serialize the file descriptors in the nested message, so there |
928 // better not be any. | 934 // better not be any. |
929 DCHECK(!p.HasAttachments()); | 935 DCHECK(!p.HasAttachments()); |
930 #endif | 936 #endif |
931 | 937 |
932 // Don't just write out the message. This is used to send messages between | 938 // Don't just write out the message. This is used to send messages between |
933 // NaCl (Posix environment) and the browser (could be on Windows). The message | 939 // NaCl (Posix environment) and the browser (could be on Windows). The message |
934 // header formats differ between these systems (so does handle sharing, but | 940 // header formats differ between these systems (so does handle sharing, but |
935 // we already asserted we don't have any handles). So just write out the | 941 // we already asserted we don't have any handles). So just write out the |
936 // parts of the header we use. | 942 // parts of the header we use. |
937 // | 943 // |
938 // Be careful also to use only explicitly-sized types. The NaCl environment | 944 // Be careful also to use only explicitly-sized types. The NaCl environment |
939 // could be 64-bit and the host browser could be 32-bits. The nested message | 945 // could be 64-bit and the host browser could be 32-bits. The nested message |
940 // may or may not be safe to send between 32-bit and 64-bit systems, but we | 946 // may or may not be safe to send between 32-bit and 64-bit systems, but we |
941 // leave that up to the code sending the message to ensure. | 947 // leave that up to the code sending the message to ensure. |
942 m->WriteUInt32(static_cast<uint32_t>(p.routing_id())); | 948 m->WriteUInt32(static_cast<uint32_t>(p.routing_id())); |
943 m->WriteUInt32(p.type()); | 949 m->WriteUInt32(p.type()); |
944 m->WriteUInt32(p.flags()); | 950 m->WriteUInt32(p.flags()); |
945 m->WriteData(p.payload(), static_cast<uint32_t>(p.payload_size())); | 951 m->WriteData(p.payload(), static_cast<uint32_t>(p.payload_size())); |
946 } | 952 } |
947 | 953 |
948 bool ParamTraits<Message>::Read(const Message* m, | 954 bool ParamTraits<Message>::Read(const base::Pickle* m, |
949 base::PickleIterator* iter, | 955 base::PickleIterator* iter, |
950 Message* r) { | 956 Message* r) { |
951 uint32_t routing_id, type, flags; | 957 uint32_t routing_id, type, flags; |
952 if (!iter->ReadUInt32(&routing_id) || | 958 if (!iter->ReadUInt32(&routing_id) || |
953 !iter->ReadUInt32(&type) || | 959 !iter->ReadUInt32(&type) || |
954 !iter->ReadUInt32(&flags)) | 960 !iter->ReadUInt32(&flags)) |
955 return false; | 961 return false; |
956 | 962 |
957 int payload_size; | 963 int payload_size; |
958 const char* payload; | 964 const char* payload; |
959 if (!iter->ReadData(&payload, &payload_size)) | 965 if (!iter->ReadData(&payload, &payload_size)) |
960 return false; | 966 return false; |
961 | 967 |
962 r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); | 968 r->SetHeaderValues(static_cast<int32_t>(routing_id), type, flags); |
963 return r->WriteBytes(payload, payload_size); | 969 return r->WriteBytes(payload, payload_size); |
964 } | 970 } |
965 | 971 |
966 void ParamTraits<Message>::Log(const Message& p, std::string* l) { | 972 void ParamTraits<Message>::Log(const Message& p, std::string* l) { |
967 l->append("<IPC::Message>"); | 973 l->append("<IPC::Message>"); |
968 } | 974 } |
969 | 975 |
970 #if defined(OS_WIN) | 976 #if defined(OS_WIN) |
971 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 | 977 // Note that HWNDs/HANDLE/HCURSOR/HACCEL etc are always 32 bits, even on 64 |
972 // bit systems. That's why we use the Windows macros to convert to 32 bits. | 978 // bit systems. That's why we use the Windows macros to convert to 32 bits. |
973 void ParamTraits<HANDLE>::Write(Message* m, const param_type& p) { | 979 void ParamTraits<HANDLE>::Write(base::Pickle* m, const param_type& p) { |
974 m->WriteInt(HandleToLong(p)); | 980 m->WriteInt(HandleToLong(p)); |
975 } | 981 } |
976 | 982 |
977 bool ParamTraits<HANDLE>::Read(const Message* m, | 983 bool ParamTraits<HANDLE>::Read(const base::Pickle* m, |
978 base::PickleIterator* iter, | 984 base::PickleIterator* iter, |
979 param_type* r) { | 985 param_type* r) { |
980 int32_t temp; | 986 int32_t temp; |
981 if (!iter->ReadInt(&temp)) | 987 if (!iter->ReadInt(&temp)) |
982 return false; | 988 return false; |
983 *r = LongToHandle(temp); | 989 *r = LongToHandle(temp); |
984 return true; | 990 return true; |
985 } | 991 } |
986 | 992 |
987 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { | 993 void ParamTraits<HANDLE>::Log(const param_type& p, std::string* l) { |
988 l->append(base::StringPrintf("0x%p", p)); | 994 l->append(base::StringPrintf("0x%p", p)); |
989 } | 995 } |
990 | 996 |
991 void ParamTraits<LOGFONT>::Write(Message* m, const param_type& p) { | 997 void ParamTraits<LOGFONT>::Write(base::Pickle* m, const param_type& p) { |
992 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); | 998 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT)); |
993 } | 999 } |
994 | 1000 |
995 bool ParamTraits<LOGFONT>::Read(const Message* m, | 1001 bool ParamTraits<LOGFONT>::Read(const base::Pickle* m, |
996 base::PickleIterator* iter, | 1002 base::PickleIterator* iter, |
997 param_type* r) { | 1003 param_type* r) { |
998 const char *data; | 1004 const char *data; |
999 int data_size = 0; | 1005 int data_size = 0; |
1000 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { | 1006 if (iter->ReadData(&data, &data_size) && data_size == sizeof(LOGFONT)) { |
1001 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); | 1007 const LOGFONT *font = reinterpret_cast<LOGFONT*>(const_cast<char*>(data)); |
1002 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { | 1008 if (_tcsnlen(font->lfFaceName, LF_FACESIZE) < LF_FACESIZE) { |
1003 memcpy(r, data, sizeof(LOGFONT)); | 1009 memcpy(r, data, sizeof(LOGFONT)); |
1004 return true; | 1010 return true; |
1005 } | 1011 } |
1006 } | 1012 } |
1007 | 1013 |
1008 NOTREACHED(); | 1014 NOTREACHED(); |
1009 return false; | 1015 return false; |
1010 } | 1016 } |
1011 | 1017 |
1012 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { | 1018 void ParamTraits<LOGFONT>::Log(const param_type& p, std::string* l) { |
1013 l->append(base::StringPrintf("<LOGFONT>")); | 1019 l->append(base::StringPrintf("<LOGFONT>")); |
1014 } | 1020 } |
1015 | 1021 |
1016 void ParamTraits<MSG>::Write(Message* m, const param_type& p) { | 1022 void ParamTraits<MSG>::Write(base::Pickle* m, const param_type& p) { |
1017 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); | 1023 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG)); |
1018 } | 1024 } |
1019 | 1025 |
1020 bool ParamTraits<MSG>::Read(const Message* m, | 1026 bool ParamTraits<MSG>::Read(const base::Pickle* m, |
1021 base::PickleIterator* iter, | 1027 base::PickleIterator* iter, |
1022 param_type* r) { | 1028 param_type* r) { |
1023 const char *data; | 1029 const char *data; |
1024 int data_size = 0; | 1030 int data_size = 0; |
1025 bool result = iter->ReadData(&data, &data_size); | 1031 bool result = iter->ReadData(&data, &data_size); |
1026 if (result && data_size == sizeof(MSG)) { | 1032 if (result && data_size == sizeof(MSG)) { |
1027 memcpy(r, data, sizeof(MSG)); | 1033 memcpy(r, data, sizeof(MSG)); |
1028 } else { | 1034 } else { |
1029 result = false; | 1035 result = false; |
1030 NOTREACHED(); | 1036 NOTREACHED(); |
1031 } | 1037 } |
1032 | 1038 |
1033 return result; | 1039 return result; |
1034 } | 1040 } |
1035 | 1041 |
1036 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1042 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1037 l->append("<MSG>"); | 1043 l->append("<MSG>"); |
1038 } | 1044 } |
1039 | 1045 |
1040 #endif // OS_WIN | 1046 #endif // OS_WIN |
1041 | 1047 |
1042 } // namespace IPC | 1048 } // namespace IPC |
OLD | NEW |