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 "content/renderer/pepper/ppb_tcp_server_socket_private_impl.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "content/renderer/pepper/host_globals.h" | |
9 #include "content/renderer/pepper/plugin_delegate.h" | |
10 #include "content/renderer/pepper/ppb_tcp_socket_private_impl.h" | |
11 #include "content/renderer/pepper/resource_helper.h" | |
12 | |
13 namespace content { | |
14 | |
15 PPB_TCPServerSocket_Private_Impl::PPB_TCPServerSocket_Private_Impl( | |
16 PP_Instance instance) | |
17 : ::ppapi::PPB_TCPServerSocket_Shared(instance) { | |
18 } | |
19 | |
20 PPB_TCPServerSocket_Private_Impl::~PPB_TCPServerSocket_Private_Impl() { | |
21 StopListening(); | |
22 } | |
23 | |
24 PP_Resource PPB_TCPServerSocket_Private_Impl::CreateResource( | |
25 PP_Instance instance) { | |
26 PPB_TCPServerSocket_Private_Impl* socket = | |
27 new PPB_TCPServerSocket_Private_Impl(instance); | |
28 return socket->GetReference(); | |
29 } | |
30 | |
31 void PPB_TCPServerSocket_Private_Impl::OnAcceptCompleted( | |
32 bool succeeded, | |
33 uint32 accepted_socket_id, | |
34 const PP_NetAddress_Private& local_addr, | |
35 const PP_NetAddress_Private& remote_addr) { | |
36 if (!::ppapi::TrackedCallback::IsPending(accept_callback_) || | |
37 !tcp_socket_buffer_) { | |
38 NOTREACHED(); | |
39 return; | |
40 } | |
41 | |
42 if (succeeded) { | |
43 *tcp_socket_buffer_ = | |
44 PPB_TCPSocket_Private_Impl::CreateConnectedSocket(pp_instance(), | |
45 accepted_socket_id, | |
46 local_addr, | |
47 remote_addr); | |
48 } | |
49 tcp_socket_buffer_ = NULL; | |
50 | |
51 accept_callback_->Run(succeeded ? PP_OK : PP_ERROR_FAILED); | |
52 } | |
53 | |
54 void PPB_TCPServerSocket_Private_Impl::SendListen( | |
55 const PP_NetAddress_Private& addr, | |
56 int32_t backlog) { | |
57 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
58 if (!plugin_delegate) | |
59 return; | |
60 | |
61 plugin_delegate->TCPServerSocketListen(pp_resource(), addr, backlog); | |
62 } | |
63 | |
64 void PPB_TCPServerSocket_Private_Impl::SendAccept() { | |
65 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
66 if (!plugin_delegate) | |
67 return; | |
68 | |
69 plugin_delegate->TCPServerSocketAccept(socket_id_); | |
70 } | |
71 | |
72 void PPB_TCPServerSocket_Private_Impl::SendStopListening() { | |
73 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | |
74 if (!plugin_delegate) | |
75 return; | |
76 | |
77 plugin_delegate->TCPServerSocketStopListening(pp_resource(), socket_id_); | |
78 } | |
79 | |
80 } // namespace content | |
OLD | NEW |