| 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_set.h" | 17 #include "ipc/ipc_message_attachment_set.h" |
| 17 | 18 |
| 19 #if defined(OS_POSIX) |
| 20 #include "ipc/ipc_platform_file_attachment.h" |
| 21 #endif |
| 22 |
| 18 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 19 #include <tchar.h> | 24 #include <tchar.h> |
| 20 #endif | 25 #endif |
| 21 | 26 |
| 22 namespace IPC { | 27 namespace IPC { |
| 23 | 28 |
| 24 namespace { | 29 namespace { |
| 25 | 30 |
| 26 const int kMaxRecursionDepth = 100; | 31 const int kMaxRecursionDepth = 100; |
| 27 | 32 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 463 |
| 459 #if defined(OS_POSIX) | 464 #if defined(OS_POSIX) |
| 460 void ParamTraits<base::FileDescriptor>::Write(Message* m, const param_type& p) { | 465 void ParamTraits<base::FileDescriptor>::Write(Message* m, const param_type& p) { |
| 461 const bool valid = p.fd >= 0; | 466 const bool valid = p.fd >= 0; |
| 462 WriteParam(m, valid); | 467 WriteParam(m, valid); |
| 463 | 468 |
| 464 if (!valid) | 469 if (!valid) |
| 465 return; | 470 return; |
| 466 | 471 |
| 467 if (p.auto_close) { | 472 if (p.auto_close) { |
| 468 if (!m->WriteFile(base::ScopedFD(p.fd))) | 473 if (!m->WriteAttachment( |
| 474 new internal::PlatformFileAttachment(base::ScopedFD(p.fd)))) |
| 469 NOTREACHED(); | 475 NOTREACHED(); |
| 470 } else { | 476 } else { |
| 471 if (!m->WriteBorrowingFile(p.fd)) | 477 if (!m->WriteAttachment(new internal::PlatformFileAttachment(p.fd))) |
| 472 NOTREACHED(); | 478 NOTREACHED(); |
| 473 } | 479 } |
| 474 } | 480 } |
| 475 | 481 |
| 476 bool ParamTraits<base::FileDescriptor>::Read(const Message* m, | 482 bool ParamTraits<base::FileDescriptor>::Read(const Message* m, |
| 477 PickleIterator* iter, | 483 PickleIterator* iter, |
| 478 param_type* r) { | 484 param_type* r) { |
| 479 *r = base::FileDescriptor(); | 485 *r = base::FileDescriptor(); |
| 480 | 486 |
| 481 bool valid; | 487 bool valid; |
| 482 if (!ReadParam(m, iter, &valid)) | 488 if (!ReadParam(m, iter, &valid)) |
| 483 return false; | 489 return false; |
| 484 | 490 |
| 485 // TODO(morrita): Seems like this should return false. | 491 // TODO(morrita): Seems like this should return false. |
| 486 if (!valid) | 492 if (!valid) |
| 487 return true; | 493 return true; |
| 488 | 494 |
| 489 base::ScopedFD fd; | 495 scoped_refptr<MessageAttachment> attachment; |
| 490 if (!m->ReadFile(iter, &fd)) | 496 if (!m->ReadAttachment(iter, &attachment)) |
| 491 return false; | 497 return false; |
| 492 | 498 |
| 493 *r = base::FileDescriptor(fd.release(), true); | 499 *r = base::FileDescriptor(attachment->TakePlatformFile(), true); |
| 494 return true; | 500 return true; |
| 495 } | 501 } |
| 496 | 502 |
| 497 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, | 503 void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
| 498 std::string* l) { | 504 std::string* l) { |
| 499 if (p.auto_close) { | 505 if (p.auto_close) { |
| 500 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); | 506 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
| 501 } else { | 507 } else { |
| 502 l->append(base::StringPrintf("FD(%d)", p.fd)); | 508 l->append(base::StringPrintf("FD(%d)", p.fd)); |
| 503 } | 509 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 } | 725 } |
| 720 | 726 |
| 721 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { | 727 void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { |
| 722 // Doesn't make sense to implement this! | 728 // Doesn't make sense to implement this! |
| 723 } | 729 } |
| 724 | 730 |
| 725 void ParamTraits<Message>::Write(Message* m, const Message& p) { | 731 void ParamTraits<Message>::Write(Message* m, const Message& p) { |
| 726 #if defined(OS_POSIX) | 732 #if defined(OS_POSIX) |
| 727 // We don't serialize the file descriptors in the nested message, so there | 733 // We don't serialize the file descriptors in the nested message, so there |
| 728 // better not be any. | 734 // better not be any. |
| 729 DCHECK(!p.HasFileDescriptors()); | 735 DCHECK(!p.HasAttachments()); |
| 730 #endif | 736 #endif |
| 731 | 737 |
| 732 // Don't just write out the message. This is used to send messages between | 738 // Don't just write out the message. This is used to send messages between |
| 733 // NaCl (Posix environment) and the browser (could be on Windows). The message | 739 // NaCl (Posix environment) and the browser (could be on Windows). The message |
| 734 // header formats differ between these systems (so does handle sharing, but | 740 // header formats differ between these systems (so does handle sharing, but |
| 735 // we already asserted we don't have any handles). So just write out the | 741 // we already asserted we don't have any handles). So just write out the |
| 736 // parts of the header we use. | 742 // parts of the header we use. |
| 737 // | 743 // |
| 738 // Be careful also to use only explicitly-sized types. The NaCl environment | 744 // Be careful also to use only explicitly-sized types. The NaCl environment |
| 739 // could be 64-bit and the host browser could be 32-bits. The nested message | 745 // could be 64-bit and the host browser could be 32-bits. The nested message |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 return result; | 835 return result; |
| 830 } | 836 } |
| 831 | 837 |
| 832 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 838 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
| 833 l->append("<MSG>"); | 839 l->append("<MSG>"); |
| 834 } | 840 } |
| 835 | 841 |
| 836 #endif // OS_WIN | 842 #endif // OS_WIN |
| 837 | 843 |
| 838 } // namespace IPC | 844 } // namespace IPC |
| OLD | NEW |