Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h" | |
| 6 | |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/task.h" | |
| 9 #include "ppapi/c/pp_completion_callback.h" | |
| 10 #include "webkit/plugins/ppapi/common.h" | |
|
yzshen1
2011/11/28 20:59:16
Not needed.
ygorshenin
2011/11/29 18:30:09
Done.
| |
| 11 #include "webkit/plugins/ppapi/host_globals.h" | |
| 12 #include "webkit/plugins/ppapi/plugin_delegate.h" | |
| 13 #include "webkit/plugins/ppapi/plugin_module.h" | |
|
yzshen1
2011/11/28 20:59:16
Not needed.
ygorshenin
2011/11/29 18:30:09
Done.
| |
| 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
| 15 #include "webkit/plugins/ppapi/resource_helper.h" | |
| 16 | |
| 17 namespace webkit { | |
| 18 namespace ppapi { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 class AbortCallbackTask : public Task { | |
| 23 public: | |
| 24 explicit AbortCallbackTask(PP_CompletionCallback callback) | |
| 25 : callback_(callback) {} | |
| 26 virtual ~AbortCallbackTask() {} | |
| 27 virtual void Run() { | |
| 28 if (callback_.func) | |
| 29 PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 PP_CompletionCallback callback_; | |
| 34 }; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 PPB_UDPSocket_Private_Impl::PPB_UDPSocket_Private_Impl( | |
| 39 PP_Instance instance, uint32 socket_id) | |
| 40 : ::ppapi::UDPSocketImpl(instance, socket_id) { | |
| 41 } | |
| 42 | |
| 43 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.
| |
| 44 } | |
| 45 | |
| 46 PP_Resource PPB_UDPSocket_Private_Impl::CreateResource(PP_Instance instance) { | |
| 47 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); | |
| 48 if (!plugin_instance) | |
| 49 return 0; | |
| 50 | |
| 51 PluginDelegate* pluign_delegate = plugin_instance->delegate(); | |
| 52 uint32 socket_id = pluign_delegate->UDPSocketCreate(); | |
| 53 if (!socket_id) | |
| 54 return 0; | |
| 55 | |
| 56 return (new PPB_UDPSocket_Private_Impl(instance, socket_id))->GetReference(); | |
| 57 } | |
| 58 | |
| 59 void PPB_UDPSocket_Private_Impl::SendBind(const PP_NetAddress_Private& addr) { | |
| 60 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 61 if (!pluign_delegate) | |
| 62 return; | |
| 63 | |
| 64 pluign_delegate->UDPSocketBind(this, socket_id_, addr); | |
| 65 } | |
| 66 | |
| 67 void PPB_UDPSocket_Private_Impl::SendRecvFrom(int32_t num_bytes) { | |
| 68 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 69 if (!pluign_delegate) | |
| 70 return; | |
| 71 | |
| 72 pluign_delegate->UDPSocketRecvFrom(socket_id_, num_bytes); | |
| 73 } | |
| 74 | |
| 75 void PPB_UDPSocket_Private_Impl::SendSendTo(const std::string& buffer, | |
| 76 const PP_NetAddress_Private& addr) { | |
| 77 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 78 if (!pluign_delegate) | |
| 79 return; | |
| 80 | |
| 81 pluign_delegate->UDPSocketSendTo(socket_id_, buffer, addr); | |
| 82 } | |
| 83 | |
| 84 void PPB_UDPSocket_Private_Impl::SendClose() { | |
| 85 PluginDelegate* pluign_delegate = ResourceHelper::GetPluginDelegate(this); | |
| 86 if (!pluign_delegate) | |
| 87 return; | |
| 88 | |
| 89 pluign_delegate->UDPSocketClose(socket_id_); | |
| 90 } | |
| 91 | |
| 92 void PPB_UDPSocket_Private_Impl::PostAbort(PP_CompletionCallback callback) { | |
| 93 MessageLoop::current()->PostTask(FROM_HERE, new AbortCallbackTask(callback)); | |
| 94 } | |
| 95 | |
| 96 } // namespace ppapi | |
| 97 } // namespace webkit | |
| OLD | NEW |