Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.cc

Issue 9283022: Exposed Listen and Accept methods to plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added Destroy message for initialized but cancelled sockets. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 state_ = INITIALIZING;
21 SendInitialize();
22 }
23
24 PPB_TCPServerSocket_Private_Impl::~PPB_TCPServerSocket_Private_Impl() {
25 if (state_ == INITIALIZING) {
26 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
27 if (!plugin_delegate)
28 return;
29 plugin_delegate->CancelInitializationOfTCPServerSocket(this);
30 } else {
31 StopListening();
32 }
33 }
34
35 PP_Resource PPB_TCPServerSocket_Private_Impl::CreateResource(
36 PP_Instance instance) {
37 PPB_TCPServerSocket_Private_Impl* socket =
38 new PPB_TCPServerSocket_Private_Impl(instance);
39 return socket->GetReference();
40 }
41
42 void PPB_TCPServerSocket_Private_Impl::OnAcceptCompleted(
43 bool succeeded,
44 uint32 tcp_socket_id,
45 const PP_NetAddress_Private& local_addr,
46 const PP_NetAddress_Private& remote_addr) {
47 if (!::ppapi::TrackedCallback::IsPending(accept_callback_) ||
48 !tcp_socket_buffer_) {
49 NOTREACHED();
50 return;
51 }
52
53 if (succeeded) {
54 *tcp_socket_buffer_ =
55 PPB_TCPSocket_Private_Impl::CreateConnectedSocket(pp_instance(),
56 tcp_socket_id,
57 local_addr,
58 remote_addr);
59 }
60 tcp_socket_buffer_ = NULL;
61
62 ::ppapi::TrackedCallback::ClearAndRun(&accept_callback_,
63 succeeded ? PP_OK : PP_ERROR_FAILED);
64 }
65
66 void PPB_TCPServerSocket_Private_Impl::SendInitialize() {
67 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
68 if (!plugin_delegate)
69 return;
70
71 plugin_delegate->TCPServerSocketInitialize(this);
72 }
73
74 void PPB_TCPServerSocket_Private_Impl::SendListen(
75 const PP_NetAddress_Private& addr,
76 int32_t backlog) {
77 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
78 if (!plugin_delegate)
79 return;
80
81 plugin_delegate->TCPServerSocketListen(this, socket_id_, addr, backlog);
82 }
83
84 void PPB_TCPServerSocket_Private_Impl::SendAccept() {
85 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
86 if (!plugin_delegate)
87 return;
88
89 plugin_delegate->TCPServerSocketAccept(socket_id_);
90 }
91
92 void PPB_TCPServerSocket_Private_Impl::SendStopListening() {
93 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
94 if (!plugin_delegate)
95 return;
96
97 plugin_delegate->TCPServerSocketStopListening(socket_id_);
98 }
99
100 } // namespace ppapi
101 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698