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 p.WriteMechanismToPickle(m); | |
527 | |
528 if (p.IsBackedByPOSIXFd()) | |
529 ParamTraits<base::FileDescriptor>::Write(m, *p.GetFileDescriptor()); | |
Robert Sesek
2015/06/15 21:34:33
Hm… looking at this again, it's a bit odd to have
erikchen
2015/06/16 00:59:27
Added static asserts. Moved logic out of SharedMem
| |
530 } | |
531 | |
532 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, | |
533 base::PickleIterator* iter, | |
534 param_type* r) { | |
535 if (!r->ReadMechanismFromPickle(iter)) | |
536 return false; | |
537 | |
538 if (r->IsBackedByPOSIXFd()) { | |
539 return ParamTraits<base::FileDescriptor>::Read(m, iter, | |
540 r->GetFileDescriptor()); | |
541 } | |
542 | |
543 return true; | |
544 } | |
545 | |
546 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | |
547 std::string* l) { | |
548 if (p.IsBackedByPOSIXFd()) { | |
549 l->append(base::StringPrintf("Mechanism POSIX Fd")); | |
550 ParamTraits<base::FileDescriptor>::Log(*p.GetFileDescriptor(), l); | |
551 } | |
552 } | |
553 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
554 | |
519 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { | 555 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { |
520 p.WriteToPickle(m); | 556 p.WriteToPickle(m); |
521 } | 557 } |
522 | 558 |
523 bool ParamTraits<base::FilePath>::Read(const Message* m, | 559 bool ParamTraits<base::FilePath>::Read(const Message* m, |
524 base::PickleIterator* iter, | 560 base::PickleIterator* iter, |
525 param_type* r) { | 561 param_type* r) { |
526 return r->ReadFromPickle(iter); | 562 return r->ReadFromPickle(iter); |
527 } | 563 } |
528 | 564 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 return result; | 902 return result; |
867 } | 903 } |
868 | 904 |
869 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 905 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
870 l->append("<MSG>"); | 906 l->append("<MSG>"); |
871 } | 907 } |
872 | 908 |
873 #endif // OS_WIN | 909 #endif // OS_WIN |
874 | 910 |
875 } // namespace IPC | 911 } // namespace IPC |
OLD | NEW |