OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/edk/embedder/platform_shared_buffer.h" | 5 #include "mojo/edk/embedder/platform_shared_buffer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 options.share_read_only = true; | 226 options.share_read_only = true; |
227 | 227 |
228 shared_memory_.reset(new base::SharedMemory); | 228 shared_memory_.reset(new base::SharedMemory); |
229 return shared_memory_->Create(options); | 229 return shared_memory_->Create(options); |
230 } | 230 } |
231 | 231 |
232 bool PlatformSharedBuffer::InitFromPlatformHandle( | 232 bool PlatformSharedBuffer::InitFromPlatformHandle( |
233 ScopedPlatformHandle platform_handle) { | 233 ScopedPlatformHandle platform_handle) { |
234 DCHECK(!shared_memory_); | 234 DCHECK(!shared_memory_); |
235 | 235 |
| 236 // TODO(rockot): Pass GUIDs through Mojo. https://crbug.com/713763. |
| 237 base::UnguessableToken guid = base::UnguessableToken::Create(); |
236 #if defined(OS_WIN) | 238 #if defined(OS_WIN) |
237 base::SharedMemoryHandle handle(platform_handle.release().handle); | 239 base::SharedMemoryHandle handle(platform_handle.release().handle, guid); |
238 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 240 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
239 base::SharedMemoryHandle handle; | 241 base::SharedMemoryHandle handle = base::SharedMemoryHandle( |
240 handle = base::SharedMemoryHandle(platform_handle.release().port, num_bytes_); | 242 platform_handle.release().port, num_bytes_, guid); |
241 #else | 243 #else |
242 base::SharedMemoryHandle handle( | 244 base::SharedMemoryHandle handle( |
243 base::FileDescriptor(platform_handle.release().handle, false)); | 245 base::FileDescriptor(platform_handle.release().handle, false), guid); |
244 #endif | 246 #endif |
245 | 247 |
246 shared_memory_.reset(new base::SharedMemory(handle, read_only_)); | 248 shared_memory_.reset(new base::SharedMemory(handle, read_only_)); |
247 return true; | 249 return true; |
248 } | 250 } |
249 | 251 |
250 bool PlatformSharedBuffer::InitFromPlatformHandlePair( | 252 bool PlatformSharedBuffer::InitFromPlatformHandlePair( |
251 ScopedPlatformHandle rw_platform_handle, | 253 ScopedPlatformHandle rw_platform_handle, |
252 ScopedPlatformHandle ro_platform_handle) { | 254 ScopedPlatformHandle ro_platform_handle) { |
253 #if defined(OS_MACOSX) | 255 #if defined(OS_MACOSX) |
254 NOTREACHED(); | 256 NOTREACHED(); |
255 return false; | 257 return false; |
256 #else // defined(OS_MACOSX) | 258 #else // defined(OS_MACOSX) |
257 | 259 |
| 260 // TODO(rockot): Pass GUIDs through Mojo. https://crbug.com/713763. |
| 261 base::UnguessableToken guid = base::UnguessableToken::Create(); |
258 #if defined(OS_WIN) | 262 #if defined(OS_WIN) |
259 base::SharedMemoryHandle handle(rw_platform_handle.release().handle); | 263 base::SharedMemoryHandle handle(rw_platform_handle.release().handle, guid); |
260 base::SharedMemoryHandle ro_handle(ro_platform_handle.release().handle); | 264 base::SharedMemoryHandle ro_handle(ro_platform_handle.release().handle, guid); |
261 #else // defined(OS_WIN) | 265 #else // defined(OS_WIN) |
262 base::SharedMemoryHandle handle( | 266 base::SharedMemoryHandle handle( |
263 base::FileDescriptor(rw_platform_handle.release().handle, false)); | 267 base::FileDescriptor(rw_platform_handle.release().handle, false), guid); |
264 base::SharedMemoryHandle ro_handle( | 268 base::SharedMemoryHandle ro_handle( |
265 base::FileDescriptor(ro_platform_handle.release().handle, false)); | 269 base::FileDescriptor(ro_platform_handle.release().handle, false), guid); |
266 #endif // defined(OS_WIN) | 270 #endif // defined(OS_WIN) |
267 | 271 |
268 DCHECK(!shared_memory_); | 272 DCHECK(!shared_memory_); |
269 shared_memory_.reset(new base::SharedMemory(handle, false)); | 273 shared_memory_.reset(new base::SharedMemory(handle, false)); |
270 ro_shared_memory_.reset(new base::SharedMemory(ro_handle, true)); | 274 ro_shared_memory_.reset(new base::SharedMemory(ro_handle, true)); |
271 return true; | 275 return true; |
272 | 276 |
273 #endif // defined(OS_MACOSX) | 277 #endif // defined(OS_MACOSX) |
274 } | 278 } |
275 | 279 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding; | 316 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding; |
313 return true; | 317 return true; |
314 } | 318 } |
315 | 319 |
316 void PlatformSharedBufferMapping::Unmap() { | 320 void PlatformSharedBufferMapping::Unmap() { |
317 shared_memory_.Unmap(); | 321 shared_memory_.Unmap(); |
318 } | 322 } |
319 | 323 |
320 } // namespace edk | 324 } // namespace edk |
321 } // namespace mojo | 325 } // namespace mojo |
OLD | NEW |