Chromium Code Reviews| Index: ppapi/proxy/io_stream_resource.cc |
| diff --git a/ppapi/proxy/io_stream_resource.cc b/ppapi/proxy/io_stream_resource.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..183714610968c60992b8c65bb96a5e43c5d48db8 |
| --- /dev/null |
| +++ b/ppapi/proxy/io_stream_resource.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/proxy/io_stream_resource.h" |
| + |
| +#include "ppapi/proxy/ppapi_messages.h" |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +IOStreamResource::IOStreamResource(Connection connection, |
| + PP_Instance instance, |
| + bool input) |
| + : PluginResource(connection, instance), |
| + IOStreamShared(input) { |
| +} |
| + |
| +IOStreamResource::IOStreamResource(Connection connection, |
| + PP_Instance instance, |
| + int pending_renderer_id, |
| + bool input) |
| + : PluginResource(connection, instance), |
| + IOStreamShared(input) { |
| + AttachToPendingHost(RENDERER, pending_renderer_id); |
| +} |
| + |
| +IOStreamResource::~IOStreamResource() { |
| +} |
| + |
| +int32_t IOStreamResource::Init(uint32_t size) { |
| + CHECK(size); |
|
bbudge
2013/12/31 00:51:53
You should probably return PP_ERROR_BADARGUMENT in
Peng
2013/12/31 23:33:54
Done.
|
| + IPC::Message unused; |
| + ResourceMessageReplyParams reply_params; |
| + int32_t result = GenericSyncCall(RENDERER, |
| + PpapiHostMsg_IOStream_Init(size), &unused, &reply_params); |
| + if (result != PP_OK) |
| + return result; |
| + |
| + base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); |
| + reply_params.TakeSharedMemoryHandleAtIndex(0, &shm_handle); |
| + |
| + SetBuffer(scoped_ptr<base::SharedMemory>( |
| + new base::SharedMemory(shm_handle, true)), size); |
| + return PP_OK; |
| +} |
| + |
| +void IOStreamResource::MovePeerLimit(uint32_t offset) { |
| + Post(RENDERER, PpapiHostMsg_IOStream_MoveLimit(offset)); |
| +} |
| + |
| +void IOStreamResource::OnReplyReceived( |
| + const proxy::ResourceMessageReplyParams& params, const IPC::Message& msg) { |
| + IPC_BEGIN_MESSAGE_MAP(IOStreamResource, msg) |
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
| + PpapiPluginMsg_IOStream_Init, |
| + OnPluginMsgInit) |
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
| + PpapiPluginMsg_IOStream_MoveLimit, |
| + OnPluginMsgMoveLimit) |
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( |
| + PluginResource::OnReplyReceived(params, msg)) |
| + IPC_END_MESSAGE_MAP() |
| +} |
| + |
| +void IOStreamResource::OnPluginMsgInit( |
| + const ResourceMessageReplyParams& params, uint32_t size) { |
| + base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); |
| + params.TakeSharedMemoryHandleAtIndex(0, &shm_handle); |
| + SetBuffer(scoped_ptr<base::SharedMemory>( |
| + new base::SharedMemory(shm_handle, input())), size); |
| +} |
| + |
| +void IOStreamResource::OnPluginMsgMoveLimit( |
| + const ResourceMessageReplyParams& params, uint32_t offset) { |
| + MoveLimit(offset); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |