| 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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/shared_memory_handle.h" |
| 13 #include "base/strings/nullable_string16.h" | 14 #include "base/strings/nullable_string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "base/unguessable_token.h" | 18 #include "base/unguessable_token.h" |
| 18 #include "base/values.h" | 19 #include "base/values.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "ipc/ipc_channel_handle.h" | 21 #include "ipc/ipc_channel_handle.h" |
| 21 #include "ipc/ipc_message_attachment.h" | 22 #include "ipc/ipc_message_attachment.h" |
| 22 #include "ipc/ipc_message_attachment_set.h" | 23 #include "ipc/ipc_message_attachment_set.h" |
| 23 #include "ipc/ipc_mojo_param_traits.h" | 24 #include "ipc/ipc_mojo_param_traits.h" |
| 24 | 25 |
| 25 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
| 26 #include "base/file_descriptor_posix.h" | 27 #include "base/file_descriptor_posix.h" |
| 27 #include "ipc/ipc_platform_file_attachment_posix.h" | 28 #include "ipc/ipc_platform_file_attachment_posix.h" |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) | |
| 31 #include "base/memory/shared_memory_handle.h" | |
| 32 #endif // (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) | |
| 33 | |
| 34 #if defined(OS_MACOSX) && !defined(OS_IOS) | 31 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 35 #include "ipc/mach_port_mac.h" | 32 #include "ipc/mach_port_mac.h" |
| 36 #endif | 33 #endif |
| 37 | 34 |
| 38 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 39 #include <tchar.h> | 36 #include <tchar.h> |
| 40 #include "ipc/handle_win.h" | 37 #include "ipc/handle_win.h" |
| 41 #endif | 38 #endif |
| 42 | 39 |
| 43 namespace IPC { | 40 namespace IPC { |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 637 |
| 641 bool ParamTraits<base::FileDescriptor>::Read(const base::Pickle* m, | 638 bool ParamTraits<base::FileDescriptor>::Read(const base::Pickle* m, |
| 642 base::PickleIterator* iter, | 639 base::PickleIterator* iter, |
| 643 param_type* r) { | 640 param_type* r) { |
| 644 *r = base::FileDescriptor(); | 641 *r = base::FileDescriptor(); |
| 645 | 642 |
| 646 bool valid; | 643 bool valid; |
| 647 if (!ReadParam(m, iter, &valid)) | 644 if (!ReadParam(m, iter, &valid)) |
| 648 return false; | 645 return false; |
| 649 | 646 |
| 650 // TODO(morrita): Seems like this should return false. | |
| 651 if (!valid) | 647 if (!valid) |
| 652 return true; | 648 return true; |
| 653 | 649 |
| 654 scoped_refptr<base::Pickle::Attachment> attachment; | 650 scoped_refptr<base::Pickle::Attachment> attachment; |
| 655 if (!m->ReadAttachment(iter, &attachment)) | 651 if (!m->ReadAttachment(iter, &attachment)) |
| 656 return false; | 652 return false; |
| 657 | 653 |
| 658 if (static_cast<MessageAttachment*>(attachment.get())->GetType() != | 654 if (static_cast<MessageAttachment*>(attachment.get())->GetType() != |
| 659 MessageAttachment::Type::PLATFORM_FILE) { | 655 MessageAttachment::Type::PLATFORM_FILE) { |
| 660 return false; | 656 return false; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 *r = base::SharedMemoryHandle(handle, base::GetCurrentProcId()); | 770 *r = base::SharedMemoryHandle(handle, base::GetCurrentProcId()); |
| 775 return true; | 771 return true; |
| 776 } | 772 } |
| 777 | 773 |
| 778 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | 774 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
| 779 std::string* l) { | 775 std::string* l) { |
| 780 LogParam(p.GetHandle(), l); | 776 LogParam(p.GetHandle(), l); |
| 781 l->append(" needs brokering: "); | 777 l->append(" needs brokering: "); |
| 782 LogParam(p.NeedsBrokering(), l); | 778 LogParam(p.NeedsBrokering(), l); |
| 783 } | 779 } |
| 780 #elif defined(OS_POSIX) |
| 781 void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, |
| 782 const param_type& p) { |
| 783 GetParamSize(sizer, p.IsValid()); |
| 784 if (p.IsValid()) |
| 785 sizer->AddAttachment(); |
| 786 } |
| 787 |
| 788 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
| 789 const param_type& p) { |
| 790 const bool valid = p.IsValid(); |
| 791 WriteParam(m, valid); |
| 792 |
| 793 if (!valid) |
| 794 return; |
| 795 |
| 796 if (p.OwnershipPassesToIPC()) { |
| 797 if (!m->WriteAttachment(new internal::PlatformFileAttachment( |
| 798 base::ScopedFD(p.GetHandle())))) |
| 799 NOTREACHED(); |
| 800 } else { |
| 801 if (!m->WriteAttachment( |
| 802 new internal::PlatformFileAttachment(p.GetHandle()))) |
| 803 NOTREACHED(); |
| 804 } |
| 805 } |
| 806 |
| 807 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
| 808 base::PickleIterator* iter, |
| 809 param_type* r) { |
| 810 *r = base::SharedMemoryHandle(); |
| 811 |
| 812 bool valid; |
| 813 if (!ReadParam(m, iter, &valid)) |
| 814 return false; |
| 815 |
| 816 if (!valid) |
| 817 return true; |
| 818 |
| 819 scoped_refptr<base::Pickle::Attachment> attachment; |
| 820 if (!m->ReadAttachment(iter, &attachment)) |
| 821 return false; |
| 822 |
| 823 if (static_cast<MessageAttachment*>(attachment.get())->GetType() != |
| 824 MessageAttachment::Type::PLATFORM_FILE) { |
| 825 return false; |
| 826 } |
| 827 |
| 828 *r = base::SharedMemoryHandle(base::FileDescriptor( |
| 829 static_cast<internal::PlatformFileAttachment*>(attachment.get()) |
| 830 ->TakePlatformFile(), |
| 831 true)); |
| 832 return true; |
| 833 } |
| 834 |
| 835 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
| 836 std::string* l) { |
| 837 if (p.OwnershipPassesToIPC()) { |
| 838 l->append(base::StringPrintf("FD(%d auto-close)", p.GetHandle())); |
| 839 } else { |
| 840 l->append(base::StringPrintf("FD(%d)", p.GetHandle())); |
| 841 } |
| 842 } |
| 784 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 843 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 785 | 844 |
| 786 void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, | 845 void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, |
| 787 const param_type& p) { | 846 const param_type& p) { |
| 788 p.GetSizeForPickle(sizer); | 847 p.GetSizeForPickle(sizer); |
| 789 } | 848 } |
| 790 | 849 |
| 791 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { | 850 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { |
| 792 p.WriteToPickle(m); | 851 p.WriteToPickle(m); |
| 793 } | 852 } |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1229 return result; | 1288 return result; |
| 1230 } | 1289 } |
| 1231 | 1290 |
| 1232 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1291 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
| 1233 l->append("<MSG>"); | 1292 l->append("<MSG>"); |
| 1234 } | 1293 } |
| 1235 | 1294 |
| 1236 #endif // OS_WIN | 1295 #endif // OS_WIN |
| 1237 | 1296 |
| 1238 } // namespace IPC | 1297 } // namespace IPC |
| OLD | NEW |