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 uint32_t mechanism = p.GetMechanismForWire(); |
| 527 WriteParam(m, mechanism); |
| 528 |
| 529 if (p.IsBackedByPOSIXFd()) |
| 530 ParamTraits<base::FileDescriptor>::Write(m, *p.GetFileDescriptor()); |
| 531 } |
| 532 |
| 533 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, |
| 534 base::PickleIterator* iter, |
| 535 param_type* r) { |
| 536 uint32_t mechanism; |
| 537 if (!ReadParam(m, iter, &mechanism)) |
| 538 return false; |
| 539 |
| 540 bool success = r->SetMechanismFromWire(mechanism); |
| 541 if (!success) |
| 542 return false; |
| 543 |
| 544 if (r->IsBackedByPOSIXFd()) { |
| 545 return ParamTraits<base::FileDescriptor>::Read(m, iter, |
| 546 r->GetFileDescriptor()); |
| 547 } |
| 548 |
| 549 return true; |
| 550 } |
| 551 |
| 552 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
| 553 std::string* l) { |
| 554 if (p.IsBackedByPOSIXFd()) { |
| 555 l->append(base::StringPrintf("Mechanism POSIX Fd")); |
| 556 ParamTraits<base::FileDescriptor>::Log(*p.GetFileDescriptor(), l); |
| 557 } |
| 558 } |
| 559 #endif |
| 560 |
519 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { | 561 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { |
520 p.WriteToPickle(m); | 562 p.WriteToPickle(m); |
521 } | 563 } |
522 | 564 |
523 bool ParamTraits<base::FilePath>::Read(const Message* m, | 565 bool ParamTraits<base::FilePath>::Read(const Message* m, |
524 base::PickleIterator* iter, | 566 base::PickleIterator* iter, |
525 param_type* r) { | 567 param_type* r) { |
526 return r->ReadFromPickle(iter); | 568 return r->ReadFromPickle(iter); |
527 } | 569 } |
528 | 570 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 return result; | 908 return result; |
867 } | 909 } |
868 | 910 |
869 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 911 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
870 l->append("<MSG>"); | 912 l->append("<MSG>"); |
871 } | 913 } |
872 | 914 |
873 #endif // OS_WIN | 915 #endif // OS_WIN |
874 | 916 |
875 } // namespace IPC | 917 } // namespace IPC |
OLD | NEW |