1 // Copyright 2013 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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TCP_SERVER_SOCKET_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TCP_SERVER_SOCKET_MESSAGE_FILTER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/socket/tcp_socket.h"
15 #include "ppapi/c/pp_instance.h"
16 #include "ppapi/host/resource_message_filter.h"
18 struct PP_NetAddress_Private;
28 class BrowserPpapiHostImpl;
29 class ContentBrowserPepperHostFactory;
31 // TODO(yzshen): Remove this class entirely and let
32 // TCPServerSocketPrivateResource inherit TCPSocketResourceBase.
33 class CONTENT_EXPORT PepperTCPServerSocketMessageFilter
34 : public ppapi::host::ResourceMessageFilter {
36 PepperTCPServerSocketMessageFilter(ContentBrowserPepperHostFactory* factory,
37 BrowserPpapiHostImpl* host,
41 static size_t GetNumInstances();
44 virtual ~PepperTCPServerSocketMessageFilter();
48 STATE_BEFORE_LISTENING,
49 STATE_LISTEN_IN_PROGRESS,
51 STATE_ACCEPT_IN_PROGRESS,
55 // ppapi::host::ResourceMessageFilter overrides.
56 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
57 const IPC::Message& message) OVERRIDE;
58 virtual int32_t OnResourceMessageReceived(
59 const IPC::Message& msg,
60 ppapi::host::HostMessageContext* context) OVERRIDE;
62 int32_t OnMsgListen(const ppapi::host::HostMessageContext* context,
63 const PP_NetAddress_Private& addr,
65 int32_t OnMsgAccept(const ppapi::host::HostMessageContext* context);
66 int32_t OnMsgStopListening(const ppapi::host::HostMessageContext* context);
68 void DoListen(const ppapi::host::ReplyMessageContext& context,
69 const PP_NetAddress_Private& addr,
72 void OnListenCompleted(const ppapi::host::ReplyMessageContext& context,
74 void OnAcceptCompleted(const ppapi::host::ReplyMessageContext& context,
77 void SendListenReply(const ppapi::host::ReplyMessageContext& context,
79 const PP_NetAddress_Private& local_addr);
80 void SendListenError(const ppapi::host::ReplyMessageContext& context,
82 void SendAcceptReply(const ppapi::host::ReplyMessageContext& context,
84 int pending_resource_id,
85 const PP_NetAddress_Private& local_addr,
86 const PP_NetAddress_Private& remote_addr);
87 void SendAcceptError(const ppapi::host::ReplyMessageContext& context,
90 // Following fields are initialized and used only on the IO thread.
92 ppapi::host::PpapiHost* ppapi_host_;
94 ContentBrowserPepperHostFactory* factory_;
95 PP_Instance instance_;
98 scoped_ptr<net::TCPSocket> socket_;
99 scoped_ptr<net::TCPSocket> accepted_socket_;
100 net::IPEndPoint accepted_address_;
102 // Following fields are initialized on the IO thread but used only
104 const bool external_plugin_;
105 const bool private_api_;
106 int render_process_id_;
107 int render_frame_id_;
109 DISALLOW_COPY_AND_ASSIGN(PepperTCPServerSocketMessageFilter);
112 } // namespace content
114 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TCP_SERVER_SOCKET_MESSAGE_FILTER_H_