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 static_assert(sizeof(base::SharedMemoryHandle::Type) <= sizeof(int), | |
Tom Sepez
2015/06/17 18:51:55
nit: this assert can go into the class body itself
erikchen
2015/06/18 17:58:33
Sure, done. I made a new type base::SharedMemoryHa
| |
527 "Size of enum SharedMemoryHandle::Type exceeds size of type " | |
528 "transmitted over wire."); | |
529 m->WriteInt(p.GetType()); | |
530 | |
531 if (p.GetType() == base::SharedMemoryHandle::POSIX) | |
532 ParamTraits<base::FileDescriptor>::Write(m, *p.GetFileDescriptor()); | |
533 } | |
534 | |
535 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, | |
536 base::PickleIterator* iter, | |
537 param_type* r) { | |
538 static_assert(sizeof(base::SharedMemoryHandle::Type) <= sizeof(int), | |
Tom Sepez
2015/06/17 18:51:55
same here.
erikchen
2015/06/18 17:58:33
Done.
| |
539 "Size of enum SharedMemoryHandle::Type exceeds size of type " | |
540 "transmitted over wire."); | |
541 int type; | |
542 if (!iter->ReadInt(&type)) | |
543 return false; | |
544 | |
545 switch (type) { | |
546 case base::SharedMemoryHandle::POSIX: | |
547 case base::SharedMemoryHandle::MACH: { | |
548 base::SharedMemoryHandle::Type shm_type = | |
549 static_cast<base::SharedMemoryHandle::Type>(type); | |
550 r->SetType(shm_type); | |
551 break; | |
552 } | |
553 default: | |
554 return false; | |
555 } | |
556 | |
557 if (r->GetType() == base::SharedMemoryHandle::POSIX) { | |
558 return ParamTraits<base::FileDescriptor>::Read(m, iter, | |
559 r->GetFileDescriptor()); | |
560 } | |
561 | |
Tom Sepez
2015/06/17 18:51:55
The pattern for these kinds of classes is to not a
erikchen
2015/06/18 17:58:33
Ah, good suggestion. Done.
| |
562 return true; | |
563 } | |
564 | |
565 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | |
566 std::string* l) { | |
567 if (p.GetType() == base::SharedMemoryHandle::POSIX) { | |
568 l->append(base::StringPrintf("Mechanism POSIX Fd")); | |
569 ParamTraits<base::FileDescriptor>::Log(*p.GetFileDescriptor(), l); | |
570 } | |
571 } | |
572 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
573 | |
519 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { | 574 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { |
520 p.WriteToPickle(m); | 575 p.WriteToPickle(m); |
521 } | 576 } |
522 | 577 |
523 bool ParamTraits<base::FilePath>::Read(const Message* m, | 578 bool ParamTraits<base::FilePath>::Read(const Message* m, |
524 base::PickleIterator* iter, | 579 base::PickleIterator* iter, |
525 param_type* r) { | 580 param_type* r) { |
526 return r->ReadFromPickle(iter); | 581 return r->ReadFromPickle(iter); |
527 } | 582 } |
528 | 583 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
866 return result; | 921 return result; |
867 } | 922 } |
868 | 923 |
869 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 924 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
870 l->append("<MSG>"); | 925 l->append("<MSG>"); |
871 } | 926 } |
872 | 927 |
873 #endif // OS_WIN | 928 #endif // OS_WIN |
874 | 929 |
875 } // namespace IPC | 930 } // namespace IPC |
OLD | NEW |