| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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_tcp_server_socket_private_impl.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "webkit/plugins/ppapi/host_globals.h" |
| 9 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 11 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" |
| 12 #include "webkit/plugins/ppapi/resource_helper.h" |
| 13 |
| 14 namespace webkit { |
| 15 namespace ppapi { |
| 16 |
| 17 PPB_TCPServerSocket_Private_Impl::PPB_TCPServerSocket_Private_Impl( |
| 18 PP_Instance instance) |
| 19 : ::ppapi::PPB_TCPServerSocket_Shared(instance) { |
| 20 } |
| 21 |
| 22 PPB_TCPServerSocket_Private_Impl::~PPB_TCPServerSocket_Private_Impl() { |
| 23 StopListening(); |
| 24 } |
| 25 |
| 26 int32_t PPB_TCPServerSocket_Private_Impl::CreateResource( |
| 27 PP_Instance instance, |
| 28 PP_Resource* tcp_server_socket, |
| 29 PP_CompletionCallback callback) { |
| 30 PPB_TCPServerSocket_Private_Impl* socket = |
| 31 new PPB_TCPServerSocket_Private_Impl(instance); |
| 32 *tcp_server_socket = socket->GetReference(); |
| 33 return socket->Initialize(callback); |
| 34 } |
| 35 |
| 36 void PPB_TCPServerSocket_Private_Impl::OnAcceptCompleted( |
| 37 bool succeeded, |
| 38 uint32 tcp_socket_id, |
| 39 const PP_NetAddress_Private& local_addr, |
| 40 const PP_NetAddress_Private& remote_addr) { |
| 41 if (!::ppapi::TrackedCallback::IsPending(accept_callback_) || |
| 42 !tcp_socket_buffer_) { |
| 43 NOTREACHED(); |
| 44 return; |
| 45 } |
| 46 |
| 47 if (succeeded) { |
| 48 PP_Resource tcp_socket = |
| 49 PPB_TCPSocket_Private_Impl::CreateConnectedSocket(instance_, |
| 50 tcp_socket_id, |
| 51 local_addr, |
| 52 remote_addr); |
| 53 memcpy(tcp_socket_buffer_, &tcp_socket, sizeof(tcp_socket)); |
| 54 } |
| 55 tcp_socket_buffer_ = NULL; |
| 56 |
| 57 ::ppapi::TrackedCallback::ClearAndRun(&accept_callback_, |
| 58 succeeded ? PP_OK : PP_ERROR_FAILED); |
| 59 } |
| 60 |
| 61 void PPB_TCPServerSocket_Private_Impl::SendInitialize() { |
| 62 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 63 if (!plugin_delegate) |
| 64 return; |
| 65 |
| 66 plugin_delegate->TCPServerSocketInitialize(this); |
| 67 } |
| 68 |
| 69 void PPB_TCPServerSocket_Private_Impl::SendListen( |
| 70 const PP_NetAddress_Private& addr, |
| 71 int32_t backlog) { |
| 72 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 73 if (!plugin_delegate) |
| 74 return; |
| 75 |
| 76 plugin_delegate->TCPServerSocketListen(this, socket_id_, addr, backlog); |
| 77 } |
| 78 |
| 79 void PPB_TCPServerSocket_Private_Impl::SendAccept() { |
| 80 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 81 if (!plugin_delegate) |
| 82 return; |
| 83 |
| 84 plugin_delegate->TCPServerSocketAccept(socket_id_); |
| 85 } |
| 86 |
| 87 void PPB_TCPServerSocket_Private_Impl::SendStopListening() { |
| 88 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 89 if (!plugin_delegate) |
| 90 return; |
| 91 |
| 92 plugin_delegate->TCPServerSocketStopListening(socket_id_); |
| 93 } |
| 94 |
| 95 } // namespace ppapi |
| 96 } // namespace webkit |
| OLD | NEW |