Home | History | Annotate | Download | only in pepper
      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.
      4 
      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_
      7 
      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/browser/renderer_host/pepper/pepper_message_filter.h"
     13 #include "content/common/content_export.h"
     14 #include "ppapi/c/pp_instance.h"
     15 #include "ppapi/host/resource_message_filter.h"
     16 
     17 struct PP_NetAddress_Private;
     18 
     19 namespace net {
     20 class ServerSocket;
     21 class StreamSocket;
     22 }
     23 
     24 namespace content {
     25 
     26 class BrowserPpapiHostImpl;
     27 
     28 class CONTENT_EXPORT PepperTCPServerSocketMessageFilter
     29     : public ppapi::host::ResourceMessageFilter {
     30  public:
     31   PepperTCPServerSocketMessageFilter(
     32       BrowserPpapiHostImpl* host,
     33       PP_Instance instance,
     34       bool private_api,
     35       const scoped_refptr<PepperMessageFilter>& pepper_message_filter);
     36 
     37   static size_t GetNumInstances();
     38 
     39  protected:
     40   virtual ~PepperTCPServerSocketMessageFilter();
     41 
     42  private:
     43   enum State {
     44     STATE_BEFORE_LISTENING,
     45     STATE_LISTEN_IN_PROGRESS,
     46     STATE_LISTENING,
     47     STATE_ACCEPT_IN_PROGRESS,
     48     STATE_CLOSED
     49   };
     50 
     51   // ppapi::host::ResourceMessageFilter overrides.
     52   virtual scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(
     53       const IPC::Message& message) OVERRIDE;
     54   virtual int32_t OnResourceMessageReceived(
     55       const IPC::Message& msg,
     56       ppapi::host::HostMessageContext* context) OVERRIDE;
     57 
     58   int32_t OnMsgListen(const ppapi::host::HostMessageContext* context,
     59                       const PP_NetAddress_Private& addr,
     60                       int32_t backlog);
     61   int32_t OnMsgAccept(const ppapi::host::HostMessageContext* context,
     62                       uint32 plugin_dispatcher_id);
     63   int32_t OnMsgStopListening(const ppapi::host::HostMessageContext* context);
     64 
     65   void DoListen(const ppapi::host::ReplyMessageContext& context,
     66                 const PP_NetAddress_Private& addr,
     67                 int32_t backlog);
     68 
     69   void OnListenCompleted(const ppapi::host::ReplyMessageContext& context,
     70                          int net_result);
     71   void OnAcceptCompleted(const ppapi::host::ReplyMessageContext& context,
     72                          uint32 plugin_dispatcher_id,
     73                          int net_result);
     74 
     75   void SendListenReply(const ppapi::host::ReplyMessageContext& context,
     76                        int32_t pp_result,
     77                        const PP_NetAddress_Private& local_addr);
     78   void SendListenError(const ppapi::host::ReplyMessageContext& context,
     79                        int32_t pp_result);
     80   void SendAcceptReply(const ppapi::host::ReplyMessageContext& context,
     81                        int32_t pp_result,
     82                        uint32 accepted_socket_id,
     83                        const PP_NetAddress_Private& local_addr,
     84                        const PP_NetAddress_Private& remote_addr);
     85   void SendAcceptError(const ppapi::host::ReplyMessageContext& context,
     86                        int32_t pp_result);
     87 
     88   // Following fields are initialized and used only on the IO thread.
     89   State state_;
     90   scoped_ptr<net::ServerSocket> socket_;
     91   scoped_ptr<net::StreamSocket> socket_buffer_;
     92   scoped_refptr<PepperMessageFilter> pepper_message_filter_;
     93 
     94   // Following fields are initialized on the IO thread but used only
     95   // on the UI thread.
     96   const bool external_plugin_;
     97   const bool private_api_;
     98   int render_process_id_;
     99   int render_view_id_;
    100 
    101   DISALLOW_COPY_AND_ASSIGN(PepperTCPServerSocketMessageFilter);
    102 };
    103 
    104 }  // namespace content
    105 
    106 #endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_TCP_SERVER_SOCKET_MESSAGE_FILTER_H_
    107