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

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: Rebase. 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
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | mojo/gles2/command_buffer_client_impl.cc » ('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 "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 m->WriteInt(HandleToLong(p.GetHandle()));
609 }
610 }
611
612 bool ParamTraits<base::SharedMemoryHandle>::Read(const Message* m,
613 base::PickleIterator* iter,
614 param_type* r) {
615 uint32_t pid_int;
616 if (!iter->ReadUInt32(&pid_int))
617 return false;
618 base::ProcessId pid = pid_int;
619
620 bool needs_brokering;
621 if (!iter->ReadBool(&needs_brokering))
622 return false;
623
624 if (needs_brokering) {
625 HandleWin handle_win;
626 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win))
627 return false;
628 *r = base::SharedMemoryHandle(handle_win.get_handle(), pid);
629 return true;
630 }
631
632 int handle_int;
633 if (!iter->ReadInt(&handle_int))
634 return false;
635 HANDLE handle = LongToHandle(handle_int);
636 *r = base::SharedMemoryHandle(handle, pid);
637 return true;
638 }
639
640 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
641 std::string* l) {
642 LogParam(p.GetPID(), l);
643 l->append(" ");
644 LogParam(p.GetHandle(), l);
645 l->append(" needs brokering: ");
646 LogParam(p.NeedsBrokering(), l);
647 }
595 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 648 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
596 649
597 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) { 650 void ParamTraits<base::FilePath>::Write(Message* m, const param_type& p) {
598 p.WriteToPickle(m); 651 p.WriteToPickle(m);
599 } 652 }
600 653
601 bool ParamTraits<base::FilePath>::Read(const Message* m, 654 bool ParamTraits<base::FilePath>::Read(const Message* m,
602 base::PickleIterator* iter, 655 base::PickleIterator* iter,
603 param_type* r) { 656 param_type* r) {
604 return r->ReadFromPickle(iter); 657 return r->ReadFromPickle(iter);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 return result; 997 return result;
945 } 998 }
946 999
947 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1000 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
948 l->append("<MSG>"); 1001 l->append("<MSG>");
949 } 1002 }
950 1003
951 #endif // OS_WIN 1004 #endif // OS_WIN
952 1005
953 } // namespace IPC 1006 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | mojo/gles2/command_buffer_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698