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..33b48905bc80a7e38689c13747692a80b8f88b6a |
| --- /dev/null |
| +++ b/ppapi/proxy/io_stream_resource.cc |
| @@ -0,0 +1,89 @@ |
| +// Copyright (c) 2014 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 "base/bind.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +IOStreamResource::IOStreamResource(Connection connection, |
| + PP_Instance instance, |
| + bool is_input) |
| + : PluginResource(connection, instance), |
| + IOStreamShared(is_input), |
| + weak_factory_(this) { |
| +} |
| + |
| +IOStreamResource::IOStreamResource(Connection connection, |
| + PP_Instance instance, |
| + int pending_renderer_id, |
| + bool is_input) |
| + : PluginResource(connection, instance), |
| + IOStreamShared(is_input), |
| + weak_factory_(this) { |
| + AttachToPendingHost(RENDERER, pending_renderer_id); |
| +} |
| + |
| +IOStreamResource::~IOStreamResource() { |
| +} |
| + |
| +int32_t IOStreamResource::Init(uint32_t size, |
| + scoped_refptr<TrackedCallback> callback) { |
| + if (!size) |
| + return PP_ERROR_BADARGUMENT; |
| + Call<PpapiPluginMsg_IOStream_InitReply>( |
| + RENDERER, PpapiHostMsg_IOStream_Init(size), |
| + base::Bind( |
| + &IOStreamResource::OnPluginMsgInitReply, |
| + weak_factory_.GetWeakPtr(), size, callback)); |
|
yzshen1
2014/01/03 21:51:41
You don't need this weak_factory_. You could use b
|
| + |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +void IOStreamResource::MovePeerLimit(uint32_t offset) { |
| + Post(RENDERER, PpapiHostMsg_IOStream_MoveLimit(offset)); |
| +} |
| + |
| +void IOStreamResource::OnReplyReceived( |
| + const proxy::ResourceMessageReplyParams& params, const IPC::Message& msg) { |
|
yzshen1
2014/01/03 21:51:41
proxy:: is not needed.
|
| + 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) { |
|
dmichael (off chromium)
2014/01/03 18:05:29
Why is this "ResourceMessageReplyParams" instead o
yzshen1
2014/01/03 21:51:41
I thought we always use ResourceMessageReplyParams
|
| + base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); |
| + params.TakeSharedMemoryHandleAtIndex(0, &shm_handle); |
| + SetBuffer(scoped_ptr<base::SharedMemory>( |
|
dmichael (off chromium)
2014/01/03 18:05:29
Note I think this is only ever changing from an em
Peng
2014/01/03 21:01:49
Actually this function can be used more than once.
|
| + new base::SharedMemory(shm_handle, is_input())), size); |
|
yzshen1
2014/01/03 21:51:41
wrong indent
|
| +} |
| + |
| +void IOStreamResource::OnPluginMsgMoveLimit( |
| + const ResourceMessageReplyParams& params, uint32_t offset) { |
| + MoveLimit(offset); |
| +} |
| + |
| +void IOStreamResource::OnPluginMsgInitReply( |
|
dmichael (off chromium)
2014/01/03 18:05:29
Am I understanding correctly that there are two di
Peng
2014/01/03 21:01:49
There are different requirements for Track & Produ
|
| + uint32_t size, |
| + scoped_refptr<TrackedCallback> callback, |
| + const ResourceMessageReplyParams& params) { |
| + int32_t result = params.result(); |
| + if (result == PP_OK) |
| + OnPluginMsgInit(params, size); |
| + callback->Run(result);; |
|
dmichael (off chromium)
2014/01/03 18:05:29
nit: extra semicolon
|
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |