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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/nullable_string16.h" | 10 #include "base/strings/nullable_string16.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "ipc/ipc_channel_handle.h" | 15 #include "ipc/ipc_channel_handle.h" |
16 #include "ipc/ipc_message_attachment.h" | 16 #include "ipc/ipc_message_attachment.h" |
17 #include "ipc/ipc_message_attachment_set.h" | 17 #include "ipc/ipc_message_attachment_set.h" |
18 | 18 |
19 #if defined(OS_POSIX) | 19 #if defined(OS_POSIX) |
20 #include "ipc/ipc_platform_file_attachment_posix.h" | 20 #include "ipc/ipc_platform_file_attachment_posix.h" |
21 #endif | 21 #endif |
22 | 22 |
| 23 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 24 #include "base/memory/shared_memory_handle.h" |
| 25 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 26 |
23 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
24 #include <tchar.h> | 28 #include <tchar.h> |
25 #endif | 29 #endif |
26 | 30 |
27 namespace IPC { | 31 namespace IPC { |
28 | 32 |
29 namespace { | 33 namespace { |
30 | 34 |
31 const int kMaxRecursionDepth = 100; | 35 const int kMaxRecursionDepth = 100; |
32 | 36 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, | 513 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
510 std::string* l) { | 514 std::string* l) { |
511 if (p.auto_close) { | 515 if (p.auto_close) { |
512 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); | 516 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
513 } else { | 517 } else { |
514 l->append(base::StringPrintf("FD(%d)", p.fd)); | 518 l->append(base::StringPrintf("FD(%d)", p.fd)); |
515 } | 519 } |
516 } | 520 } |
517 #endif // defined(OS_POSIX) | 521 #endif // defined(OS_POSIX) |
518 | 522 |
| 523 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 524 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m, |
| 525 const param_type& p) { |
| 526 m->WriteInt(p.GetType()); |
| 527 |
| 528 if (p.GetType() == base::SharedMemoryHandle::POSIX) |
| 529 ParamTraits<base::FileDescriptor>::Write(m, p.GetFileDescriptor()); |
| 530 } |
| 531 |
| 532 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, |
| 533 base::PickleIterator* iter, |
| 534 param_type* r) { |
| 535 base::SharedMemoryHandle::TypeWireFormat type; |
| 536 if (!iter->ReadInt(&type)) |
| 537 return false; |
| 538 |
| 539 base::SharedMemoryHandle::Type shm_type = base::SharedMemoryHandle::POSIX; |
| 540 switch (type) { |
| 541 case base::SharedMemoryHandle::POSIX: |
| 542 case base::SharedMemoryHandle::MACH: { |
| 543 shm_type = static_cast<base::SharedMemoryHandle::Type>(type); |
| 544 break; |
| 545 } |
| 546 default: |
| 547 return false; |
| 548 } |
| 549 |
| 550 if (shm_type == base::SharedMemoryHandle::POSIX) { |
| 551 base::FileDescriptor file_descriptor; |
| 552 |
| 553 bool success = |
| 554 ParamTraits<base::FileDescriptor>::Read(m, iter, &file_descriptor); |
| 555 if (!success) |
| 556 return false; |
| 557 |
| 558 *r = base::SharedMemoryHandle(file_descriptor.fd, |
| 559 file_descriptor.auto_close); |
| 560 return true; |
| 561 } |
| 562 |
| 563 return true; |
| 564 } |
| 565 |
| 566 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
| 567 std::string* l) { |
| 568 if (p.GetType() == base::SharedMemoryHandle::POSIX) { |
| 569 l->append(base::StringPrintf("Mechanism POSIX Fd")); |
| 570 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l); |
| 571 } |
| 572 } |
| 573 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 574 |
519 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { | 575 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { |
520 p.WriteToPickle(m); | 576 p.WriteToPickle(m); |
521 } | 577 } |
522 | 578 |
523 bool ParamTraits<base::FilePath>::Read(const Message* m, | 579 bool ParamTraits<base::FilePath>::Read(const Message* m, |
524 base::PickleIterator* iter, | 580 base::PickleIterator* iter, |
525 param_type* r) { | 581 param_type* r) { |
526 return r->ReadFromPickle(iter); | 582 return r->ReadFromPickle(iter); |
527 } | 583 } |
528 | 584 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 return result; | 922 return result; |
867 } | 923 } |
868 | 924 |
869 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 925 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
870 l->append("<MSG>"); | 926 l->append("<MSG>"); |
871 } | 927 } |
872 | 928 |
873 #endif // OS_WIN | 929 #endif // OS_WIN |
874 | 930 |
875 } // namespace IPC | 931 } // namespace IPC |
OLD | NEW |