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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 1320783002: Make SharedMemoryHandle a class on windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_global
Patch Set: Fix DCHECK. Created 5 years, 2 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
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 "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) 23 #if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
24 #include "base/memory/shared_memory_handle.h" 24 #include "base/memory/shared_memory_handle.h"
25 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 25 #endif // (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
26 26
27 #if defined(OS_WIN) 27 #if defined(OS_WIN)
28 #include <tchar.h> 28 #include <tchar.h>
29 #include "ipc/handle_win.h"
29 #endif 30 #endif
30 31
31 namespace IPC { 32 namespace IPC {
32 33
33 namespace { 34 namespace {
34 35
35 const int kMaxRecursionDepth = 100; 36 const int kMaxRecursionDepth = 100;
36 37
37 template<typename CharType> 38 template<typename CharType>
38 void LogBytes(const std::vector<CharType>& data, std::string* out) { 39 void LogBytes(const std::vector<CharType>& data, std::string* out) {
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 return true; 586 return true;
586 } 587 }
587 588
588 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, 589 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
589 std::string* l) { 590 std::string* l) {
590 if (p.GetType() == base::SharedMemoryHandle::POSIX) { 591 if (p.GetType() == base::SharedMemoryHandle::POSIX) {
591 l->append(base::StringPrintf("Mechanism POSIX Fd")); 592 l->append(base::StringPrintf("Mechanism POSIX Fd"));
592 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l); 593 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l);
593 } 594 }
594 } 595 }
596 #elif defined(OS_WIN)
597 void ParamTraits<base::SharedMemoryHandle>::Write(Message* m,
598 const param_type& p) {
599 // Longs on windows are 32 bits.
600 uint32_t pid = p.GetPID();
601 m->WriteUInt32(pid);
602 m->WriteBool(p.NeedsBrokering());
603
604 if (p.NeedsBrokering()) {
605 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE);
606 ParamTraits<HandleWin>::Write(m, handle_win);
607 } else {
608 // Long on Windows is 32 bits.
Tom Sepez 2015/09/23 22:06:13 nit: comment doesn't add much value as you said th
erikchen 2015/09/24 00:44:18 I removed it.
609 m->WriteInt(HandleToLong(p.GetHandle()));
610 }
611 }
612
613 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m,
614 base::PickleIterator* iter,
615 param_type* r) {
616 uint32_t pid_int;
617 if (!iter->ReadUInt32(&pid_int))
618 return false;
619 base::ProcessId pid = pid_int;
620
621 bool needs_brokering;
622 if (!iter->ReadBool(&needs_brokering))
623 return false;
624
625 if (needs_brokering) {
626 HandleWin handle_win;
627 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win))
628 return false;
629 *r = base::SharedMemoryHandle(handle_win.get_handle(), pid);
630 return true;
631 }
632
633 int handle_int;
634 if (!iter->ReadInt(&handle_int))
635 return false;
636 HANDLE handle = LongToHandle(handle_int);
637 *r = base::SharedMemoryHandle(handle, pid);
638 return true;
639 }
640
641 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
642 std::string* l) {
643 LogParam(p.GetPID(), l);
644 l->append(" ");
645 LogParam(p.GetHandle(), l);
646 l->append(" needs brokering: ");
647 LogParam(p.NeedsBrokering(), l);
648 }
595 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 649 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
596 650
597 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { 651 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) {
598 p.WriteToPickle(m); 652 p.WriteToPickle(m);
599 } 653 }
600 654
601 bool ParamTraits<base::FilePath>::Read(const Message* m, 655 bool ParamTraits<base::FilePath>::Read(const Message* m,
602 base::PickleIterator* iter, 656 base::PickleIterator* iter,
603 param_type* r) { 657 param_type* r) {
604 return r->ReadFromPickle(iter); 658 return r->ReadFromPickle(iter);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 return result; 998 return result;
945 } 999 }
946 1000
947 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1001 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
948 l->append("<MSG>"); 1002 l->append("<MSG>");
949 } 1003 }
950 1004
951 #endif // OS_WIN 1005 #endif // OS_WIN
952 1006
953 } // namespace IPC 1007 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698