Chromium Code Reviews| Index: webkit/plugins/ppapi/ppb_udp_socket_private_impl.cc |
| diff --git a/webkit/plugins/ppapi/ppb_udp_socket_private_impl.cc b/webkit/plugins/ppapi/ppb_udp_socket_private_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..68ab789a5575aef689f4cfbc59b7f87600f90a8a |
| --- /dev/null |
| +++ b/webkit/plugins/ppapi/ppb_udp_socket_private_impl.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h" |
| + |
| +#include "base/message_loop.h" |
| +#include "base/task.h" |
| +#include "ppapi/c/pp_completion_callback.h" |
| +#include "webkit/plugins/ppapi/common.h" |
|
yzshen1
2011/11/28 20:59:16
Not needed.
ygorshenin
2011/11/29 18:30:09
Done.
|
| +#include "webkit/plugins/ppapi/host_globals.h" |
| +#include "webkit/plugins/ppapi/plugin_delegate.h" |
| +#include "webkit/plugins/ppapi/plugin_module.h" |
|
yzshen1
2011/11/28 20:59:16
Not needed.
ygorshenin
2011/11/29 18:30:09
Done.
|
| +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| +#include "webkit/plugins/ppapi/resource_helper.h" |
| + |
| +namespace webkit { |
| +namespace ppapi { |
| + |
| +namespace { |
| + |
| +class AbortCallbackTask : public Task { |
| + public: |
| + explicit AbortCallbackTask(PP_CompletionCallback callback) |
| + : callback_(callback) {} |
| + virtual ~AbortCallbackTask() {} |
| + virtual void Run() { |
| + if (callback_.func) |
| + PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED); |
| + } |
| + |
| + private: |
| + PP_CompletionCallback callback_; |
| +}; |
| + |
| +} // namespace |
| + |
| +PPB_UDPSocket_Private_Impl::PPB_UDPSocket_Private_Impl( |
| + PP_Instance instance, uint32 socket_id) |
| + : ::ppapi::UDPSocketImpl(instance, socket_id) { |
| +} |
| + |
| +PPB_UDPSocket_Private_Impl::~PPB_UDPSocket_Private_Impl() { |
|
yzshen1
2011/11/28 20:59:16
Call Close(), please.
ygorshenin
2011/11/29 18:30:09
Done.
|
| +} |
| + |
| +PP_Resource PPB_UDPSocket_Private_Impl::CreateResource(PP_Instance instance) { |
| + PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); |
| + if (!plugin_instance) |
| + return 0; |
| + |
| + PluginDelegate* pluign_delegate = plugin_instance->delegate(); |
| + uint32 socket_id = pluign_delegate->UDPSocketCreate(); |
| + if (!socket_id) |
| + return 0; |
| + |
| + return (new PPB_UDPSocket_Private_Impl(instance, socket_id))->GetReference(); |
| +} |
| + |
| +void PPB_UDPSocket_Private_Impl::SendBind(const PP_NetAddress_Private& addr) { |
| + PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!pluign_delegate) |
| + return; |
| + |
| + pluign_delegate->UDPSocketBind(this, socket_id_, addr); |
| +} |
| + |
| +void PPB_UDPSocket_Private_Impl::SendRecvFrom(int32_t num_bytes) { |
| + PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!pluign_delegate) |
| + return; |
| + |
| + pluign_delegate->UDPSocketRecvFrom(socket_id_, num_bytes); |
| +} |
| + |
| +void PPB_UDPSocket_Private_Impl::SendSendTo(const std::string& buffer, |
| + const PP_NetAddress_Private& addr) { |
| + PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!pluign_delegate) |
| + return; |
| + |
| + pluign_delegate->UDPSocketSendTo(socket_id_, buffer, addr); |
| +} |
| + |
| +void PPB_UDPSocket_Private_Impl::SendClose() { |
| + PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!pluign_delegate) |
| + return; |
| + |
| + pluign_delegate->UDPSocketClose(socket_id_); |
| +} |
| + |
| +void PPB_UDPSocket_Private_Impl::PostAbort(PP_CompletionCallback callback) { |
| + MessageLoop::current()->PostTask(FROM_HERE, new AbortCallbackTask(callback)); |
| +} |
| + |
| +} // namespace ppapi |
| +} // namespace webkit |