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(
37 ContentBrowserPepperHostFactory* factory,
38 BrowserPpapiHostImpl* host,
42 static size_t GetNumInstances();
45 virtual ~PepperTCPServerSocketMessageFilter();
49 STATE_BEFORE_LISTENING,
50 STATE_LISTEN_IN_PROGRESS,
52 STATE_ACCEPT_IN_PROGRESS,
56 // ppapi::host::ResourceMessageFilter overrides.
57 virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
58 const IPC::Message& message) OVERRIDE;
59 virtual int32_t OnResourceMessageReceived(
60 const IPC::Message& msg,
61 ppapi::host::HostMessageContext* context) OVERRIDE;
63 int32_t OnMsgListen(const ppapi::host::HostMessageContext* context,
64 const PP_NetAddress_Private& addr,
66 int32_t OnMsgAccept(const ppapi::host::HostMessageContext* context);
67 int32_t OnMsgStopListening(const ppapi::host::HostMessageContext* context);
69 void DoListen(const ppapi::host::ReplyMessageContext& context,
70 const PP_NetAddress_Private& addr,
73 void OnListenCompleted(const ppapi::host::ReplyMessageContext& context,
75 void OnAcceptCompleted(const ppapi::host::ReplyMessageContext& context,
78 void SendListenReply(const ppapi::host::ReplyMessageContext& context,
80 const PP_NetAddress_Private& local_addr);
81 void SendListenError(const ppapi::host::ReplyMessageContext& context,
83 void SendAcceptReply(const ppapi::host::ReplyMessageContext& context,
85 int pending_resource_id,
86 const PP_NetAddress_Private& local_addr,
87 const PP_NetAddress_Private& remote_addr);
88 void SendAcceptError(const ppapi::host::ReplyMessageContext& context,
91 // Following fields are initialized and used only on the IO thread.
93 ppapi::host::PpapiHost* ppapi_host_;
95 ContentBrowserPepperHostFactory* factory_;
96 PP_Instance instance_;
99 scoped_ptr<net::TCPSocket> socket_;
100 scoped_ptr<net::TCPSocket> accepted_socket_;
101 net::IPEndPoint accepted_address_;
103 // Following fields are initialized on the IO thread but used only
105 const bool external_plugin_;
106 const bool private_api_;
107 int render_process_id_;
110 DISALLOW_COPY_AND_ASSIGN(PepperTCPServerSocketMessageFilter);
113 } // namespace content
115 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TCP_SERVER_SOCKET_MESSAGE_FILTER_H_