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

Side by Side Diff: mojo/public/cpp/system/platform_handle.cc

Issue 2843113002: make base::SharedMemoryHandle a class on POSIX. (Closed)
Patch Set: Fix test error. Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/public/cpp/system/platform_handle.h" 5 #include "mojo/public/cpp/system/platform_handle.h"
6 6
7 #if defined(OS_MACOSX) && !defined(OS_IOS) 7 #if defined(OS_MACOSX) && !defined(OS_IOS)
8 #include <mach/mach.h> 8 #include <mach/mach.h>
9 #include "base/mac/mach_logging.h" 9 #include "base/mac/mach_logging.h"
10 #endif 10 #endif
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 *file = PlatformFileFromPlatformHandleValue(platform_handle.value); 59 *file = PlatformFileFromPlatformHandleValue(platform_handle.value);
60 } 60 }
61 61
62 return MOJO_RESULT_OK; 62 return MOJO_RESULT_OK;
63 } 63 }
64 64
65 ScopedSharedBufferHandle WrapSharedMemoryHandle( 65 ScopedSharedBufferHandle WrapSharedMemoryHandle(
66 const base::SharedMemoryHandle& memory_handle, 66 const base::SharedMemoryHandle& memory_handle,
67 size_t size, 67 size_t size,
68 bool read_only) { 68 bool read_only) {
69 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS))
70 if (memory_handle.fd == base::kInvalidPlatformFile)
71 return ScopedSharedBufferHandle();
72 #else
73 if (!memory_handle.IsValid()) 69 if (!memory_handle.IsValid())
74 return ScopedSharedBufferHandle(); 70 return ScopedSharedBufferHandle();
75 #endif
76 MojoPlatformHandle platform_handle; 71 MojoPlatformHandle platform_handle;
77 platform_handle.struct_size = sizeof(MojoPlatformHandle); 72 platform_handle.struct_size = sizeof(MojoPlatformHandle);
78 platform_handle.type = kPlatformSharedBufferHandleType; 73 platform_handle.type = kPlatformSharedBufferHandleType;
79 #if defined(OS_MACOSX) && !defined(OS_IOS) 74 #if defined(OS_MACOSX) && !defined(OS_IOS)
80 platform_handle.value = 75 platform_handle.value =
81 static_cast<uint64_t>(memory_handle.GetMemoryObject()); 76 static_cast<uint64_t>(memory_handle.GetMemoryObject());
82 #elif defined(OS_POSIX) 77 #else
83 platform_handle.value = PlatformHandleValueFromPlatformFile(memory_handle.fd);
84 #elif defined(OS_WIN)
85 platform_handle.value = 78 platform_handle.value =
86 PlatformHandleValueFromPlatformFile(memory_handle.GetHandle()); 79 PlatformHandleValueFromPlatformFile(memory_handle.GetHandle());
87 #endif 80 #endif
88 81
89 MojoPlatformSharedBufferHandleFlags flags = 82 MojoPlatformSharedBufferHandleFlags flags =
90 MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE; 83 MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE;
91 if (read_only) 84 if (read_only)
92 flags |= MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY; 85 flags |= MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY;
93 86
94 MojoHandle mojo_handle; 87 MojoHandle mojo_handle;
(...skipping 27 matching lines...) Expand all
122 *read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY; 115 *read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY;
123 116
124 #if defined(OS_MACOSX) && !defined(OS_IOS) 117 #if defined(OS_MACOSX) && !defined(OS_IOS)
125 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT); 118 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT);
126 *memory_handle = base::SharedMemoryHandle( 119 *memory_handle = base::SharedMemoryHandle(
127 static_cast<mach_port_t>(platform_handle.value), num_bytes, 120 static_cast<mach_port_t>(platform_handle.value), num_bytes,
128 base::GetCurrentProcId()); 121 base::GetCurrentProcId());
129 #elif defined(OS_POSIX) 122 #elif defined(OS_POSIX)
130 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR); 123 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR);
131 *memory_handle = base::SharedMemoryHandle( 124 *memory_handle = base::SharedMemoryHandle(
132 static_cast<int>(platform_handle.value), false); 125 base::FileDescriptor(static_cast<int>(platform_handle.value), false));
133 #elif defined(OS_WIN) 126 #elif defined(OS_WIN)
134 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE); 127 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE);
135 *memory_handle = base::SharedMemoryHandle( 128 *memory_handle = base::SharedMemoryHandle(
136 reinterpret_cast<HANDLE>(platform_handle.value), 129 reinterpret_cast<HANDLE>(platform_handle.value),
137 base::GetCurrentProcId()); 130 base::GetCurrentProcId());
138 #endif 131 #endif
139 132
140 return MOJO_RESULT_OK; 133 return MOJO_RESULT_OK;
141 } 134 }
142 135
(...skipping 26 matching lines...) Expand all
169 if (result != MOJO_RESULT_OK) 162 if (result != MOJO_RESULT_OK)
170 return result; 163 return result;
171 164
172 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT); 165 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT);
173 *port = static_cast<mach_port_t>(platform_handle.value); 166 *port = static_cast<mach_port_t>(platform_handle.value);
174 return MOJO_RESULT_OK; 167 return MOJO_RESULT_OK;
175 } 168 }
176 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 169 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
177 170
178 } // namespace mojo 171 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698