Chromium Code Reviews| Index: webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc |
| diff --git a/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc b/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7967655458a36a15d89d7654b3fab0372102ba6e |
| --- /dev/null |
| +++ b/webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc |
| @@ -0,0 +1,96 @@ |
| +// 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 "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" |
| + |
| +#include "base/logging.h" |
| +#include "webkit/plugins/ppapi/host_globals.h" |
| +#include "webkit/plugins/ppapi/plugin_delegate.h" |
| +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| +#include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" |
| +#include "webkit/plugins/ppapi/resource_helper.h" |
| + |
| +namespace webkit { |
| +namespace ppapi { |
| + |
| +PPB_TCPServerSocket_Private_Impl::PPB_TCPServerSocket_Private_Impl( |
| + PP_Instance instance) |
| + : ::ppapi::PPB_TCPServerSocket_Shared(instance) { |
| +} |
| + |
| +PPB_TCPServerSocket_Private_Impl::~PPB_TCPServerSocket_Private_Impl() { |
| + StopListening(); |
| +} |
| + |
| +int32_t PPB_TCPServerSocket_Private_Impl::CreateResource( |
| + PP_Instance instance, |
| + PP_Resource* tcp_server_socket, |
| + PP_CompletionCallback callback) { |
| + PPB_TCPServerSocket_Private_Impl* socket = |
| + new PPB_TCPServerSocket_Private_Impl(instance); |
| + *tcp_server_socket = socket->GetReference(); |
| + return socket->Initialize(callback); |
| +} |
| + |
| +void PPB_TCPServerSocket_Private_Impl::OnAcceptCompleted( |
| + bool succeeded, |
| + uint32 tcp_socket_id, |
| + const PP_NetAddress_Private& local_addr, |
| + const PP_NetAddress_Private& remote_addr) { |
| + if (!::ppapi::TrackedCallback::IsPending(accept_callback_) || |
| + !tcp_socket_buffer_) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + if (succeeded) { |
| + PP_Resource tcp_socket = |
|
yzshen1
2012/02/09 02:31:50
nit: Why not directly *tcp_socket_buffer_ = ...?
ygorshenin1
2012/02/09 15:00:10
Done.
|
| + PPB_TCPSocket_Private_Impl::CreateConnectedSocket(instance_, |
| + tcp_socket_id, |
| + local_addr, |
| + remote_addr); |
| + *tcp_socket_buffer_ = tcp_socket; |
| + } |
| + tcp_socket_buffer_ = NULL; |
| + |
| + ::ppapi::TrackedCallback::ClearAndRun(&accept_callback_, |
| + succeeded ? PP_OK : PP_ERROR_FAILED); |
| +} |
| + |
| +void PPB_TCPServerSocket_Private_Impl::SendInitialize() { |
| + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!plugin_delegate) |
| + return; |
| + |
| + plugin_delegate->TCPServerSocketInitialize(this); |
| +} |
| + |
| +void PPB_TCPServerSocket_Private_Impl::SendListen( |
| + const PP_NetAddress_Private& addr, |
| + int32_t backlog) { |
| + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!plugin_delegate) |
| + return; |
| + |
| + plugin_delegate->TCPServerSocketListen(this, socket_id_, addr, backlog); |
| +} |
| + |
| +void PPB_TCPServerSocket_Private_Impl::SendAccept() { |
| + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!plugin_delegate) |
| + return; |
| + |
| + plugin_delegate->TCPServerSocketAccept(socket_id_); |
| +} |
| + |
| +void PPB_TCPServerSocket_Private_Impl::SendStopListening() { |
| + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| + if (!plugin_delegate) |
| + return; |
| + |
| + plugin_delegate->TCPServerSocketStopListening(socket_id_); |
| +} |
| + |
| +} // namespace ppapi |
| +} // namespace webkit |