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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 *r = base::SharedMemoryHandle(handle, base::GetCurrentProcId()); | 771 *r = base::SharedMemoryHandle(handle, base::GetCurrentProcId()); |
775 return true; | 772 return true; |
776 } | 773 } |
777 | 774 |
778 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | 775 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
779 std::string* l) { | 776 std::string* l) { |
780 LogParam(p.GetHandle(), l); | 777 LogParam(p.GetHandle(), l); |
781 l->append(" needs brokering: "); | 778 l->append(" needs brokering: "); |
782 LogParam(p.NeedsBrokering(), l); | 779 LogParam(p.NeedsBrokering(), l); |
783 } | 780 } |
781 #elif defined(OS_POSIX) | |
782 void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, | |
783 const param_type& p) { | |
784 GetParamSize(sizer, p.IsValid()); | |
785 if (p.IsValid()) | |
786 sizer->AddAttachment(); | |
787 } | |
788 | |
789 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, | |
790 const param_type& p) { | |
791 const bool valid = p.IsValid(); | |
792 WriteParam(m, valid); | |
793 | |
794 if (!valid) | |
795 return; | |
796 | |
797 if (p.file_descriptor.auto_close) { | |
798 if (!m->WriteAttachment(new internal::PlatformFileAttachment( | |
799 base::ScopedFD(p.GetHandle())))) | |
800 NOTREACHED(); | |
801 } else { | |
802 if (!m->WriteAttachment( | |
803 new internal::PlatformFileAttachment(p.GetHandle()))) | |
804 NOTREACHED(); | |
805 } | |
806 } | |
807 | |
808 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, | |
809 base::PickleIterator* iter, | |
810 param_type* r) { | |
811 *r = base::SharedMemoryHandle(); | |
812 | |
813 bool valid; | |
814 if (!ReadParam(m, iter, &valid)) | |
815 return false; | |
816 | |
817 // TODO(morrita): Seems like this should return false. | |
Nico
2017/04/27 16:24:44
I take it you copied this block from somewhere; I
erikchen
2017/04/27 17:08:10
This file needs a separate IPC review anyways. I'l
| |
818 if (!valid) | |
819 return true; | |
820 | |
821 scoped_refptr<base::Pickle::Attachment> attachment; | |
822 if (!m->ReadAttachment(iter, &attachment)) | |
823 return false; | |
824 | |
825 if (static_cast<MessageAttachment*>(attachment.get())->GetType() != | |
826 MessageAttachment::Type::PLATFORM_FILE) { | |
827 return false; | |
828 } | |
829 | |
830 *r = base::SharedMemoryHandle(base::FileDescriptor( | |
831 static_cast<internal::PlatformFileAttachment*>(attachment.get()) | |
832 ->TakePlatformFile(), | |
833 true)); | |
834 return true; | |
835 } | |
836 | |
837 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | |
838 std::string* l) { | |
839 if (p.file_descriptor.auto_close) { | |
840 l->append(base::StringPrintf("FD(%d auto-close)", p.GetHandle())); | |
841 } else { | |
842 l->append(base::StringPrintf("FD(%d)", p.GetHandle())); | |
843 } | |
844 } | |
784 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 845 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
785 | 846 |
786 void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, | 847 void ParamTraits<base::FilePath>::GetSize(base::PickleSizer* sizer, |
787 const param_type& p) { | 848 const param_type& p) { |
788 p.GetSizeForPickle(sizer); | 849 p.GetSizeForPickle(sizer); |
789 } | 850 } |
790 | 851 |
791 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { | 852 void ParamTraits<base::FilePath>::Write(base::Pickle* m, const param_type& p) { |
792 p.WriteToPickle(m); | 853 p.WriteToPickle(m); |
793 } | 854 } |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 return result; | 1290 return result; |
1230 } | 1291 } |
1231 | 1292 |
1232 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1293 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1233 l->append("<MSG>"); | 1294 l->append("<MSG>"); |
1234 } | 1295 } |
1235 | 1296 |
1236 #endif // OS_WIN | 1297 #endif // OS_WIN |
1237 | 1298 |
1238 } // namespace IPC | 1299 } // namespace IPC |
OLD | NEW |