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

Side by Side Diff: ppapi/proxy/ppb_buffer_proxy.cc

Issue 10828023: PPAPI/NaCl: Make NaClIPCAdapter transfer handles more generally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-add gyp files Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_buffer_proxy.h ('k') | ppapi/proxy/ppb_graphics_3d_proxy.h » ('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 "ppapi/proxy/ppb_buffer_proxy.h" 5 #include "ppapi/proxy/ppb_buffer_proxy.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 // static 70 // static
71 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, 71 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance,
72 uint32_t size) { 72 uint32_t size) {
73 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 73 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
74 if (!dispatcher) 74 if (!dispatcher)
75 return 0; 75 return 0;
76 76
77 HostResource result; 77 HostResource result;
78 base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); 78 ppapi::proxy::SerializedHandle shm_handle;
79 dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( 79 dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create(
80 API_ID_PPB_BUFFER, instance, size, 80 API_ID_PPB_BUFFER, instance, size, &result, &shm_handle));
81 &result, &shm_handle)); 81 if (result.is_null() || !shm_handle.IsHandleValid() ||
82 if (result.is_null() || !base::SharedMemory::IsHandleValid(shm_handle)) 82 !shm_handle.is_shmem())
83 return 0; 83 return 0;
84 84
85 return AddProxyResource(result, shm_handle, size); 85 return AddProxyResource(result, shm_handle.shmem(), size);
86 } 86 }
87 87
88 // static 88 // static
89 PP_Resource PPB_Buffer_Proxy::AddProxyResource( 89 PP_Resource PPB_Buffer_Proxy::AddProxyResource(
90 const HostResource& resource, 90 const HostResource& resource,
91 base::SharedMemoryHandle shm_handle, 91 base::SharedMemoryHandle shm_handle,
92 uint32_t size) { 92 uint32_t size) {
93 return (new Buffer(resource, shm_handle, size))->GetReference(); 93 return (new Buffer(resource, shm_handle, size))->GetReference();
94 } 94 }
95 95
96 bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) { 96 bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) {
97 bool handled = true; 97 bool handled = true;
98 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) 98 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg)
99 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate) 99 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate)
100 IPC_MESSAGE_UNHANDLED(handled = false) 100 IPC_MESSAGE_UNHANDLED(handled = false)
101 IPC_END_MESSAGE_MAP() 101 IPC_END_MESSAGE_MAP()
102 // TODO(brettw) handle bad messages! 102 // TODO(brettw) handle bad messages!
103 return handled; 103 return handled;
104 } 104 }
105 105
106 void PPB_Buffer_Proxy::OnMsgCreate( 106 void PPB_Buffer_Proxy::OnMsgCreate(
107 PP_Instance instance, 107 PP_Instance instance,
108 uint32_t size, 108 uint32_t size,
109 HostResource* result_resource, 109 HostResource* result_resource,
110 base::SharedMemoryHandle* result_shm_handle) { 110 ppapi::proxy::SerializedHandle* result_shm_handle) {
111 // Overwritten below on success. 111 // Overwritten below on success.
112 *result_shm_handle = base::SharedMemory::NULLHandle(); 112 result_shm_handle->set_null_shmem();
113 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); 113 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
114 if (!dispatcher) 114 if (!dispatcher)
115 return; 115 return;
116 116
117 thunk::EnterResourceCreation enter(instance); 117 thunk::EnterResourceCreation enter(instance);
118 if (enter.failed()) 118 if (enter.failed())
119 return; 119 return;
120 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, 120 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance,
121 size); 121 size);
122 if (local_buffer_resource == 0) 122 if (local_buffer_resource == 0)
(...skipping 12 matching lines...) Expand all
135 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, 135 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle,
136 // those casts are ugly. 136 // those casts are ugly.
137 base::PlatformFile platform_file = 137 base::PlatformFile platform_file =
138 #if defined(OS_WIN) 138 #if defined(OS_WIN)
139 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); 139 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd));
140 #elif defined(OS_POSIX) 140 #elif defined(OS_POSIX)
141 local_fd; 141 local_fd;
142 #else 142 #else
143 #error Not implemented. 143 #error Not implemented.
144 #endif 144 #endif
145 *result_shm_handle = dispatcher->ShareHandleWithRemote(platform_file, false); 145 result_shm_handle->set_shmem(
146 dispatcher->ShareHandleWithRemote(platform_file, false), size);
146 } 147 }
147 148
148 } // namespace proxy 149 } // namespace proxy
149 } // namespace ppapi 150 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_buffer_proxy.h ('k') | ppapi/proxy/ppb_graphics_3d_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698