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 PP_Resource PPB_TCPServerSocket_Private_Impl::CreateResource( | |
27 PP_Instance instance) { | |
28 PPB_TCPServerSocket_Private_Impl* socket = | |
29 new PPB_TCPServerSocket_Private_Impl(instance); | |
30 return socket->GetReference(); | |
31 } | |
32 | |
33 void PPB_TCPServerSocket_Private_Impl::OnAcceptCompleted( | |
34 bool succeeded, | |
35 uint32 accepted_socket_id, | |
36 const PP_NetAddress_Private& local_addr, | |
37 const PP_NetAddress_Private& remote_addr) { | |
38 if (!::ppapi::TrackedCallback::IsPending(accept_callback_) || | |
39 !tcp_socket_buffer_) { | |
40 NOTREACHED(); | |
41 return; | |
42 } | |
43 | |
44 if (succeeded) { | |
45 *tcp_socket_buffer_ = | |
46 PPB_TCPSocket_Private_Impl::CreateConnectedSocket(pp_instance(), | |
47 accepted_socket_id, | |
48 local_addr, | |
49 remote_addr); | |
50 } | |
51 tcp_socket_buffer_ = NULL; | |
52 | |
53 accept_callback_->Run(succeeded ? PP_OK : PP_ERROR_FAILED); | |
54 } | |
55 | |
56 void PPB_TCPServerSocket_Private_Impl::SendListen( | |
57 const PP_NetAddress_Private& addr, | |
58 int32_t backlog) { | |
59 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
60 if (!plugin_delegate) | |
61 return; | |
62 | |
63 plugin_delegate->TCPServerSocketListen(pp_resource(), addr, backlog); | |
64 } | |
65 | |
66 void PPB_TCPServerSocket_Private_Impl::SendAccept() { | |
67 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
68 if (!plugin_delegate) | |
69 return; | |
70 | |
71 plugin_delegate->TCPServerSocketAccept(socket_id_); | |
72 } | |
73 | |
74 void PPB_TCPServerSocket_Private_Impl::SendStopListening() { | |
75 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
76 if (!plugin_delegate) | |
77 return; | |
78 | |
79 plugin_delegate->TCPServerSocketStopListening(pp_resource(), socket_id_); | |
80 } | |
81 | |
82 } // namespace ppapi | |
83 } // namespace webkit | |
OLD | NEW |