Chromium Code Reviews| Index: ppapi/proxy/ppb_buffer_proxy.cc |
| diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc |
| index 5c2fd8a89be9c95086b775135d13580db6e3f6c4..22d21e718c15051e17922ae5fdf9e1c569d91f7e 100644 |
| --- a/ppapi/proxy/ppb_buffer_proxy.cc |
| +++ b/ppapi/proxy/ppb_buffer_proxy.cc |
| @@ -11,10 +11,13 @@ |
| #include "ppapi/c/pp_completion_callback.h" |
| #include "ppapi/c/pp_resource.h" |
| #include "ppapi/c/dev/ppb_buffer_dev.h" |
| +#include "ppapi/proxy/host_dispatcher.h" |
| #include "ppapi/proxy/plugin_dispatcher.h" |
| #include "ppapi/proxy/plugin_resource.h" |
| #include "ppapi/proxy/ppapi_messages.h" |
| +#include "ppapi/thunk/enter.h" |
| #include "ppapi/thunk/ppb_buffer_api.h" |
| +#include "ppapi/thunk/ppb_buffer_trusted_api.h" |
| #include "ppapi/thunk/thunk.h" |
| namespace pp { |
| @@ -33,7 +36,7 @@ class Buffer : public ppapi::thunk::PPB_Buffer_API, |
| public PluginResource { |
| public: |
| Buffer(const HostResource& resource, |
| - int memory_handle, |
| + const base::SharedMemoryHandle& shm_handle, |
| uint32_t size); |
| virtual ~Buffer(); |
| @@ -50,19 +53,18 @@ class Buffer : public ppapi::thunk::PPB_Buffer_API, |
| virtual void Unmap() OVERRIDE; |
| private: |
| - int memory_handle_; |
| + base::SharedMemory shm_; |
| uint32_t size_; |
| - |
| void* mapped_data_; |
| DISALLOW_COPY_AND_ASSIGN(Buffer); |
| }; |
| Buffer::Buffer(const HostResource& resource, |
| - int memory_handle, |
| + const base::SharedMemoryHandle& shm_handle, |
| uint32_t size) |
| : PluginResource(resource), |
| - memory_handle_(memory_handle), |
| + shm_(shm_handle, false), |
| size_(size), |
| mapped_data_(NULL) { |
| } |
| @@ -89,12 +91,13 @@ PP_Bool Buffer::IsMapped() { |
| } |
| void* Buffer::Map() { |
| - // TODO(brettw) implement this. |
| - return mapped_data_; |
| + if (!shm_.memory()) |
| + shm_.Map(size_); |
| + return shm_.memory(); |
| } |
| void Buffer::Unmap() { |
| - // TODO(brettw) implement this. |
| + shm_.Unmap(); |
| } |
| PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher, |
| @@ -125,15 +128,14 @@ PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, |
| return 0; |
| HostResource result; |
| - int32_t shm_handle = -1; |
| + base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); |
| dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( |
| INTERFACE_ID_PPB_BUFFER, instance, size, |
| &result, &shm_handle)); |
| - if (result.is_null()) |
| + if (result.is_null() || !base::SharedMemory::IsHandleValid(shm_handle)) |
| return 0; |
| - linked_ptr<Buffer> object(new Buffer(result, |
| - static_cast<int>(shm_handle), size)); |
| + linked_ptr<Buffer> object(new Buffer(result, shm_handle, size)); |
| return PluginResourceTracker::GetInstance()->AddResource(object); |
| } |
| @@ -147,15 +149,30 @@ bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| return handled; |
| } |
| -void PPB_Buffer_Proxy::OnMsgCreate(PP_Instance instance, |
| - uint32_t size, |
| - HostResource* result_resource, |
| - int* result_shm_handle) { |
| - result_resource->SetHostResource( |
| - instance, |
| - ppb_buffer_target()->Create(instance, size)); |
| - // TODO(brettw) set the shm handle from a trusted interface. |
| - *result_shm_handle = 0; |
| +void PPB_Buffer_Proxy::OnMsgCreate( |
| + PP_Instance instance, |
| + uint32_t size, |
| + HostResource* result_resource, |
| + base::SharedMemoryHandle* result_shm_handle) { |
| + // Overwritten below on success. |
| + *result_shm_handle = base::SharedMemory::NULLHandle(); |
| + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| + if (!dispatcher) |
| + return; |
| + PP_Resource local_buffer_resource = |
| + ppb_buffer_target()->Create(instance, size); |
| + if (local_buffer_resource == 0) |
| + return; |
| + ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_BufferTrusted_API> |
| + trusted_buffer(local_buffer_resource, false); |
| + if (trusted_buffer.failed()) |
| + return; |
| + int local_fd; |
| + if (trusted_buffer.object()->GetSharedMemory(&local_fd)) |
|
piman
2011/06/09 23:11:32
nit: if (... != PP_OK)
I think that's more readabl
Ami GONE FROM CHROMIUM
2011/06/09 23:35:28
Done.
|
| + return; |
| + |
| + result_resource->SetHostResource(instance, local_buffer_resource); |
| + *result_shm_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
| } |
| } // namespace proxy |