Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 1493413004: ipc: Allow attachment brokering for shared memory handles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp1
Patch Set: Fix more tests. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc.gyp ('k') | ipc/ipc_test_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 case base::SharedMemoryHandle::MACH: 653 case base::SharedMemoryHandle::MACH:
654 l->append("Mach port: "); 654 l->append("Mach port: ");
655 LogParam(p.GetMemoryObject(), l); 655 LogParam(p.GetMemoryObject(), l);
656 break; 656 break;
657 } 657 }
658 } 658 }
659 659
660 #elif defined(OS_WIN) 660 #elif defined(OS_WIN)
661 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m, 661 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m,
662 const param_type& p) { 662 const param_type& p) {
663 // Longs on windows are 32 bits.
664 uint32_t pid = p.GetPID();
665 m->WriteUInt32(pid);
666 m->WriteBool(p.NeedsBrokering()); 663 m->WriteBool(p.NeedsBrokering());
667 664
668 if (p.NeedsBrokering()) { 665 if (p.NeedsBrokering()) {
669 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); 666 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE);
670 ParamTraits<HandleWin>::Write(m, handle_win); 667 ParamTraits<HandleWin>::Write(m, handle_win);
671 } else { 668 } else {
672 m->WriteInt(HandleToLong(p.GetHandle())); 669 m->WriteInt(HandleToLong(p.GetHandle()));
673 } 670 }
674 } 671 }
675 672
676 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m, 673 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m,
677 base::PickleIterator* iter, 674 base::PickleIterator* iter,
678 param_type* r) { 675 param_type* r) {
679 uint32_t pid_int;
680 if (!iter->ReadUInt32(&pid_int))
681 return false;
682 base::ProcessId pid = pid_int;
683
684 bool needs_brokering; 676 bool needs_brokering;
685 if (!iter->ReadBool(&needs_brokering)) 677 if (!iter->ReadBool(&needs_brokering))
686 return false; 678 return false;
687 679
688 if (needs_brokering) { 680 if (needs_brokering) {
689 HandleWin handle_win; 681 HandleWin handle_win;
690 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win)) 682 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win))
691 return false; 683 return false;
692 *r = base::SharedMemoryHandle(handle_win.get_handle(), pid); 684 *r = base::SharedMemoryHandle(handle_win.get_handle(),
685 base::GetCurrentProcId());
693 return true; 686 return true;
694 } 687 }
695 688
696 int handle_int; 689 int handle_int;
697 if (!iter->ReadInt(&handle_int)) 690 if (!iter->ReadInt(&handle_int))
698 return false; 691 return false;
699 HANDLE handle = LongToHandle(handle_int); 692 HANDLE handle = LongToHandle(handle_int);
700 *r = base::SharedMemoryHandle(handle, pid); 693 *r = base::SharedMemoryHandle(handle, base::GetCurrentProcId());
701 return true; 694 return true;
702 } 695 }
703 696
704 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, 697 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
705 std::string* l) { 698 std::string* l) {
706 LogParam(p.GetPID(), l);
707 l->append(" ");
708 LogParam(p.GetHandle(), l); 699 LogParam(p.GetHandle(), l);
709 l->append(" needs brokering: "); 700 l->append(" needs brokering: ");
710 LogParam(p.NeedsBrokering(), l); 701 LogParam(p.NeedsBrokering(), l);
711 } 702 }
712 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 703 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
713 704
714 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { 705 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) {
715 p.WriteToPickle(m); 706 p.WriteToPickle(m);
716 } 707 }
717 708
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 return result; 1033 return result;
1043 } 1034 }
1044 1035
1045 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1036 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
1046 l->append("<MSG>"); 1037 l->append("<MSG>");
1047 } 1038 }
1048 1039
1049 #endif // OS_WIN 1040 #endif // OS_WIN
1050 1041
1051 } // namespace IPC 1042 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc.gyp ('k') | ipc/ipc_test_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698