1 // Copyright 2014 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 IPC_MOJO_IPC_CHANNEL_MOJO_READERS_H_ 6 #define IPC_MOJO_IPC_CHANNEL_MOJO_READERS_H_ 7 8 #include <vector> 9 10 #include "base/macros.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "ipc/mojo/ipc_message_pipe_reader.h" 13 #include "mojo/public/cpp/system/core.h" 14 15 namespace mojo { 16 namespace embedder { 17 struct ChannelInfo; 18 } 19 } 20 21 namespace IPC { 22 23 class ChannelMojo; 24 class Message; 25 26 namespace internal { 27 28 // A MessagePipeReader implementation for IPC::Message communication. 29 class MessageReader : public MessagePipeReader { 30 public: 31 MessageReader(mojo::ScopedMessagePipeHandle pipe, ChannelMojo* owner); 32 33 bool Send(scoped_ptr<Message> message); 34 35 // MessagePipeReader implementation 36 virtual void OnMessageReceived() OVERRIDE; 37 virtual void OnPipeClosed() OVERRIDE; 38 virtual void OnPipeError(MojoResult error) OVERRIDE; 39 40 private: 41 ChannelMojo* owner_; 42 43 DISALLOW_COPY_AND_ASSIGN(MessageReader); 44 }; 45 46 // MessagePipeReader implementation for control messages. 47 // Actual message handling is implemented by sublcasses. 48 class ControlReader : public MessagePipeReader { 49 public: 50 ControlReader(mojo::ScopedMessagePipeHandle pipe, ChannelMojo* owner); 51 52 virtual bool Connect(); 53 54 // MessagePipeReader implementation 55 virtual void OnPipeClosed() OVERRIDE; 56 virtual void OnPipeError(MojoResult error) OVERRIDE; 57 58 protected: 59 ChannelMojo* owner_; 60 61 DISALLOW_COPY_AND_ASSIGN(ControlReader); 62 }; 63 64 // ControlReader for server-side ChannelMojo. 65 class ServerControlReader : public ControlReader { 66 public: 67 ServerControlReader(mojo::ScopedMessagePipeHandle pipe, ChannelMojo* owner); 68 virtual ~ServerControlReader(); 69 70 // ControlReader override 71 virtual bool Connect() OVERRIDE; 72 73 // MessagePipeReader implementation 74 virtual void OnMessageReceived() OVERRIDE; 75 76 private: 77 MojoResult SendHelloRequest(); 78 MojoResult RespondHelloResponse(); 79 80 mojo::ScopedMessagePipeHandle message_pipe_; 81 82 DISALLOW_COPY_AND_ASSIGN(ServerControlReader); 83 }; 84 85 // ControlReader for client-side ChannelMojo. 86 class ClientControlReader : public ControlReader { 87 public: 88 ClientControlReader(mojo::ScopedMessagePipeHandle pipe, ChannelMojo* owner); 89 90 // MessagePipeReader implementation 91 virtual void OnMessageReceived() OVERRIDE; 92 93 private: 94 MojoResult RespondHelloRequest(MojoHandle message_channel); 95 96 DISALLOW_COPY_AND_ASSIGN(ClientControlReader); 97 }; 98 99 } // namespace internal 100 } // namespace IPC 101 102 #endif // IPC_MOJO_IPC_CHANNEL_MOJO_READERS_H_ 103