| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IPC_IPC_CHANNEL_MOJO_H_ | 5 #ifndef IPC_IPC_CHANNEL_MOJO_H_ |
| 6 #define IPC_IPC_CHANNEL_MOJO_H_ | 6 #define IPC_IPC_CHANNEL_MOJO_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "ipc/ipc_channel.h" | 13 #include "ipc/ipc_channel.h" |
| 14 #include "ipc/ipc_channel_factory.h" | 14 #include "ipc/ipc_channel_factory.h" |
| 15 #include "ipc/ipc_export.h" | 15 #include "ipc/ipc_export.h" |
| 16 #include "ipc/mojo/ipc_message_pipe_reader.h" | 16 #include "ipc/mojo/ipc_message_pipe_reader.h" |
| 17 #include "mojo/public/cpp/system/core.h" | 17 #include "mojo/public/cpp/system/core.h" |
| 18 | 18 |
| 19 namespace mojo { | 19 namespace mojo { |
| 20 namespace embedder { | 20 namespace embedder { |
| 21 struct ChannelInfo; | 21 struct ChannelInfo; |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace IPC { | 25 namespace IPC { |
| 26 | 26 |
| 27 namespace internal { |
| 28 class ControlReader; |
| 29 class ServerControlReader; |
| 30 class ClientControlReader; |
| 31 class MessageReader; |
| 32 } |
| 33 |
| 27 // Mojo-based IPC::Channel implementation over a platform handle. | 34 // Mojo-based IPC::Channel implementation over a platform handle. |
| 28 // | 35 // |
| 29 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by | 36 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by |
| 30 // "bootstrap" IPC::Channel which creates and owns platform pipe like | 37 // "bootstrap" IPC::Channel which creates and owns platform pipe like |
| 31 // named socket. The bootstrap Channel is used only for establishing | 38 // named socket. The bootstrap Channel is used only for establishing |
| 32 // the underlying connection. ChannelMojo takes its handle over once | 39 // the underlying connection. ChannelMojo takes its handle over once |
| 33 // the it is made and puts MessagePipe on it. | 40 // the it is made and puts MessagePipe on it. |
| 34 // | 41 // |
| 35 // ChannelMojo has a couple of MessagePipes: | 42 // ChannelMojo has a couple of MessagePipes: |
| 36 // | 43 // |
| (...skipping 30 matching lines...) Expand all Loading... |
| 67 virtual bool Connect() OVERRIDE; | 74 virtual bool Connect() OVERRIDE; |
| 68 virtual void Close() OVERRIDE; | 75 virtual void Close() OVERRIDE; |
| 69 virtual bool Send(Message* message) OVERRIDE; | 76 virtual bool Send(Message* message) OVERRIDE; |
| 70 virtual base::ProcessId GetPeerPID() const OVERRIDE; | 77 virtual base::ProcessId GetPeerPID() const OVERRIDE; |
| 71 virtual base::ProcessId GetSelfPID() const OVERRIDE; | 78 virtual base::ProcessId GetSelfPID() const OVERRIDE; |
| 72 virtual ChannelHandle TakePipeHandle() OVERRIDE; | 79 virtual ChannelHandle TakePipeHandle() OVERRIDE; |
| 73 | 80 |
| 74 #if defined(OS_POSIX) && !defined(OS_NACL) | 81 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 75 virtual int GetClientFileDescriptor() const OVERRIDE; | 82 virtual int GetClientFileDescriptor() const OVERRIDE; |
| 76 virtual int TakeClientFileDescriptor() OVERRIDE; | 83 virtual int TakeClientFileDescriptor() OVERRIDE; |
| 84 |
| 85 // These access protected API of IPC::Message, which has ChannelMojo |
| 86 // as a friend class. |
| 87 static MojoResult WriteToFileDescriptorSet( |
| 88 const std::vector<MojoHandle>& handle_buffer, |
| 89 Message* message); |
| 90 static MojoResult ReadFromFileDescriptorSet(const Message& message, |
| 91 std::vector<MojoHandle>* handles); |
| 92 |
| 77 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 93 #endif // defined(OS_POSIX) && !defined(OS_NACL) |
| 78 | 94 |
| 79 // Called from MessagePipeReader implementations | 95 // Called from MessagePipeReader implementations |
| 80 void OnMessageReceived(Message& message); | 96 void OnMessageReceived(Message& message); |
| 81 void OnConnected(mojo::ScopedMessagePipeHandle pipe); | 97 void OnConnected(mojo::ScopedMessagePipeHandle pipe); |
| 82 void OnPipeClosed(internal::MessagePipeReader* reader); | 98 void OnPipeClosed(internal::MessagePipeReader* reader); |
| 83 void OnPipeError(internal::MessagePipeReader* reader); | 99 void OnPipeError(internal::MessagePipeReader* reader); |
| 84 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } | 100 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } |
| 85 | 101 |
| 102 protected: |
| 103 ChannelMojo(const ChannelHandle& channel_handle, |
| 104 Mode mode, |
| 105 Listener* listener, |
| 106 scoped_refptr<base::TaskRunner> io_thread_task_runner); |
| 107 |
| 86 private: | 108 private: |
| 87 struct ChannelInfoDeleter { | 109 struct ChannelInfoDeleter { |
| 88 void operator()(mojo::embedder::ChannelInfo* ptr) const; | 110 void operator()(mojo::embedder::ChannelInfo* ptr) const; |
| 89 }; | 111 }; |
| 90 | 112 |
| 91 // ChannelMojo needs to kill its MessagePipeReader in delayed manner | 113 // ChannelMojo needs to kill its MessagePipeReader in delayed manner |
| 92 // because the channel wants to kill these readers during the | 114 // because the channel wants to kill these readers during the |
| 93 // notifications invoked by them. | 115 // notifications invoked by them. |
| 94 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; | 116 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; |
| 95 | 117 |
| 96 class ControlReader; | |
| 97 class ServerControlReader; | |
| 98 class ClientControlReader; | |
| 99 class MessageReader; | |
| 100 | |
| 101 ChannelMojo(scoped_ptr<Channel> bootstrap, Mode mode, Listener* listener, | |
| 102 scoped_refptr<base::TaskRunner> io_thread_task_runner); | |
| 103 | |
| 104 void InitOnIOThread(); | 118 void InitOnIOThread(); |
| 105 | 119 |
| 106 scoped_ptr<Channel> bootstrap_; | 120 scoped_ptr<Channel> bootstrap_; |
| 107 Mode mode_; | 121 Mode mode_; |
| 108 Listener* listener_; | 122 Listener* listener_; |
| 109 base::ProcessId peer_pid_; | 123 base::ProcessId peer_pid_; |
| 110 scoped_ptr<mojo::embedder::ChannelInfo, | 124 scoped_ptr<mojo::embedder::ChannelInfo, |
| 111 ChannelInfoDeleter> channel_info_; | 125 ChannelInfoDeleter> channel_info_; |
| 112 | 126 |
| 113 scoped_ptr<ControlReader, ReaderDeleter> control_reader_; | 127 scoped_ptr<internal::ControlReader, ReaderDeleter> control_reader_; |
| 114 scoped_ptr<MessageReader, ReaderDeleter> message_reader_; | 128 scoped_ptr<internal::MessageReader, ReaderDeleter> message_reader_; |
| 115 ScopedVector<Message> pending_messages_; | 129 ScopedVector<Message> pending_messages_; |
| 116 | 130 |
| 117 base::WeakPtrFactory<ChannelMojo> weak_factory_; | 131 base::WeakPtrFactory<ChannelMojo> weak_factory_; |
| 118 | 132 |
| 119 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); | 133 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); |
| 120 }; | 134 }; |
| 121 | 135 |
| 122 } // namespace IPC | 136 } // namespace IPC |
| 123 | 137 |
| 124 #endif // IPC_IPC_CHANNEL_MOJO_H_ | 138 #endif // IPC_IPC_CHANNEL_MOJO_H_ |
| OLD | NEW |