Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ipc / ipc_channel_proxy.h
index b0247c4..e76e56f 100644 (file)
@@ -22,6 +22,9 @@ class SingleThreadTaskRunner;
 
 namespace IPC {
 
+class ChannelFactory;
+class MessageFilter;
+class MessageFilterRouter;
 class SendCallbackHelper;
 
 //-----------------------------------------------------------------------------
@@ -54,54 +57,6 @@ class SendCallbackHelper;
 //
 class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
  public:
-
-  // A class that receives messages on the thread where the IPC channel is
-  // running.  It can choose to prevent the default action for an IPC message.
-  class IPC_EXPORT MessageFilter
-      : public base::RefCountedThreadSafe<MessageFilter> {
-   public:
-    MessageFilter();
-
-    // Called on the background thread to provide the filter with access to the
-    // channel.  Called when the IPC channel is initialized or when AddFilter
-    // is called if the channel is already initialized.
-    virtual void OnFilterAdded(Channel* channel);
-
-    // Called on the background thread when the filter has been removed from
-    // the ChannelProxy and when the Channel is closing.  After a filter is
-    // removed, it will not be called again.
-    virtual void OnFilterRemoved();
-
-    // Called to inform the filter that the IPC channel is connected and we
-    // have received the internal Hello message from the peer.
-    virtual void OnChannelConnected(int32 peer_pid);
-
-    // Called when there is an error on the channel, typically that the channel
-    // has been closed.
-    virtual void OnChannelError();
-
-    // Called to inform the filter that the IPC channel will be destroyed.
-    // OnFilterRemoved is called immediately after this.
-    virtual void OnChannelClosing();
-
-    // Return true to indicate that the message was handled, or false to let
-    // the message be handled in the default way.
-    virtual bool OnMessageReceived(const Message& message);
-
-    // Called to query the Message classes supported by the filter.  Return
-    // false to indicate that all message types should reach the filter, or true
-    // if the resulting contents of |supported_message_classes| may be used to
-    // selectively offer messages of a particular class to the filter.
-    virtual bool GetSupportedMessageClasses(
-        std::vector<uint32>* supported_message_classes) const;
-
-   protected:
-    virtual ~MessageFilter();
-
-   private:
-    friend class base::RefCountedThreadSafe<MessageFilter>;
-  };
-
   // Initializes a channel proxy.  The channel_handle and mode parameters are
   // passed directly to the underlying IPC::Channel.  The listener is called on
   // the thread that creates the ChannelProxy.  The filter's OnMessageReceived
@@ -110,10 +65,16 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
   // on the background thread.  Any message not handled by the filter will be
   // dispatched to the listener.  The given task runner correspond to a thread
   // on which IPC::Channel is created and used (e.g. IO thread).
-  ChannelProxy(const IPC::ChannelHandle& channel_handle,
-               Channel::Mode mode,
-               Listener* listener,
-               base::SingleThreadTaskRunner* ipc_task_runner);
+  static scoped_ptr<ChannelProxy> Create(
+      const IPC::ChannelHandle& channel_handle,
+      Channel::Mode mode,
+      Listener* listener,
+      base::SingleThreadTaskRunner* ipc_task_runner);
+
+  static scoped_ptr<ChannelProxy> Create(
+      scoped_ptr<ChannelFactory> factory,
+      Listener* listener,
+      base::SingleThreadTaskRunner* ipc_task_runner);
 
   virtual ~ChannelProxy();
 
@@ -123,12 +84,13 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
   // thread.
   void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode,
             bool create_pipe_now);
+  void Init(scoped_ptr<ChannelFactory> factory, bool create_pipe_now);
 
   // Close the IPC::Channel.  This operation completes asynchronously, once the
   // background thread processes the command to close the channel.  It is ok to
   // call this method multiple times.  Redundant calls are ignored.
   //
-  // WARNING: The MessageFilter object held by the ChannelProxy is also
+  // WARNING: MessageFilter objects held by the ChannelProxy is also
   // released asynchronously, and it may in fact have its final reference
   // released on the background thread.  The caller should be careful to deal
   // with / allow for this possibility.
@@ -155,13 +117,12 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
 
   // Get the process ID for the connected peer.
   // Returns base::kNullProcessId if the peer is not connected yet.
-  base::ProcessId peer_pid() const { return context_->peer_pid_; }
+  base::ProcessId GetPeerPID() const { return context_->peer_pid_; }
 
 #if defined(OS_POSIX) && !defined(OS_NACL)
   // Calls through to the underlying channel's methods.
   int GetClientFileDescriptor();
   int TakeClientFileDescriptor();
-  bool GetPeerEuid(uid_t* peer_euid) const;
 #endif  // defined(OS_POSIX)
 
  protected:
@@ -170,6 +131,9 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
   // to the internal state.
   ChannelProxy(Context* context);
 
+  ChannelProxy(Listener* listener,
+               base::SingleThreadTaskRunner* ipc_task_runner);
+
   // Used internally to hold state that is referenced on the IPC thread.
   class Context : public base::RefCountedThreadSafe<Context>,
                   public Listener {
@@ -214,8 +178,7 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
     friend class SendCallbackHelper;
 
     // Create the Channel
-    void CreateChannel(const IPC::ChannelHandle& channel_handle,
-                       const Channel::Mode& mode);
+    void CreateChannel(scoped_ptr<ChannelFactory> factory);
 
     // Methods called on the IO thread.
     void OnSendMessage(scoped_ptr<Message> message_ptr);
@@ -226,6 +189,7 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
     void AddFilter(MessageFilter* filter);
     void OnDispatchConnected();
     void OnDispatchError();
+    void OnDispatchBadMessage(const Message& message);
 
     scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_;
     Listener* listener_;
@@ -243,7 +207,6 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
 
     // Routes a given message to a proper subset of |filters_|, depending
     // on which message classes a filter might support.
-    class MessageFilterRouter;
     scoped_ptr<MessageFilterRouter> message_filter_router_;
 
     // Holds filters between the AddFilter call on the listerner thread and the