OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/renderer/pepper/pepper_shared_memory_message_filter.h" | 5 #include "chrome/renderer/pepper/pepper_shared_memory_message_filter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 uint32_t size, | 42 uint32_t size, |
43 int* host_handle_id, | 43 int* host_handle_id, |
44 ppapi::proxy::SerializedHandle* plugin_handle) { | 44 ppapi::proxy::SerializedHandle* plugin_handle) { |
45 plugin_handle->set_null_shmem(); | 45 plugin_handle->set_null_shmem(); |
46 *host_handle_id = -1; | 46 *host_handle_id = -1; |
47 std::unique_ptr<base::SharedMemory> shm( | 47 std::unique_ptr<base::SharedMemory> shm( |
48 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(size)); | 48 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(size)); |
49 if (!shm.get()) | 49 if (!shm.get()) |
50 return; | 50 return; |
51 | 51 |
52 base::SharedMemoryHandle host_shm_handle; | 52 base::SharedMemoryHandle host_shm_handle = shm->handle().Duplicate(); |
53 shm->ShareToProcess(base::GetCurrentProcessHandle(), &host_shm_handle); | |
54 *host_handle_id = | 53 *host_handle_id = |
55 content::PepperPluginInstance::Get(instance) | 54 content::PepperPluginInstance::Get(instance) |
56 ->GetVarTracker() | 55 ->GetVarTracker() |
57 ->TrackSharedMemoryHandle(instance, host_shm_handle, size); | 56 ->TrackSharedMemoryHandle(instance, host_shm_handle, size); |
Nico
2017/05/02 20:08:00
I assume this assumes ownership too. I didn't chec
erikchen
2017/05/02 21:33:10
I don't think it always does. I added a TODO.
| |
58 | 57 |
59 // We set auto_close to false since we need our file descriptor to | 58 // We set auto_close to false since we need our file descriptor to |
60 // actually be duplicated on linux. The shared memory destructor will | 59 // actually be duplicated on linux. The shared memory destructor will |
61 // close the original handle for us. | 60 // close the original handle for us. |
62 plugin_handle->set_shmem( | 61 plugin_handle->set_shmem( |
63 host_->ShareSharedMemoryHandleWithRemote(host_shm_handle), size); | 62 host_->ShareSharedMemoryHandleWithRemote(host_shm_handle), size); |
64 } | 63 } |
OLD | NEW |