| 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 "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
| 15 #include "ipc/ipc_channel_factory.h" | 15 #include "ipc/ipc_channel_factory.h" |
| 16 #include "ipc/ipc_export.h" | 16 #include "ipc/ipc_export.h" |
| 17 #include "ipc/mojo/ipc_message_pipe_reader.h" | 17 #include "ipc/mojo/ipc_message_pipe_reader.h" |
| 18 #include "ipc/mojo/ipc_mojo_bootstrap.h" | 18 #include "ipc/mojo/ipc_mojo_bootstrap.h" |
| 19 #include "ipc/mojo/scoped_ipc_support.h" | 19 #include "ipc/mojo/scoped_ipc_support.h" |
| 20 #include "third_party/mojo/src/mojo/public/cpp/system/core.h" |
| 21 |
| 22 #if !defined(USE_CHROME_EDK) |
| 20 #include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h" | 23 #include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h" |
| 21 #include "third_party/mojo/src/mojo/public/cpp/system/core.h" | 24 #endif |
| 22 | 25 |
| 23 namespace IPC { | 26 namespace IPC { |
| 24 | 27 |
| 25 // Mojo-based IPC::Channel implementation over a platform handle. | 28 // Mojo-based IPC::Channel implementation over a platform handle. |
| 26 // | 29 // |
| 27 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by | 30 // ChannelMojo builds Mojo MessagePipe using underlying pipe given by |
| 28 // "bootstrap" IPC::Channel which creates and owns platform pipe like | 31 // "bootstrap" IPC::Channel which creates and owns platform pipe like |
| 29 // named socket. The bootstrap Channel is used only for establishing | 32 // named socket. The bootstrap Channel is used only for establishing |
| 30 // the underlying connection. ChannelMojo takes its handle over once | 33 // the underlying connection. ChannelMojo takes its handle over once |
| 31 // the it is made and puts MessagePipe on it. | 34 // the it is made and puts MessagePipe on it. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 // TODO(morrita): Add APIs to create extra MessagePipes to let | 49 // TODO(morrita): Add APIs to create extra MessagePipes to let |
| 47 // Mojo-based objects talk over this Channel. | 50 // Mojo-based objects talk over this Channel. |
| 48 // | 51 // |
| 49 class IPC_MOJO_EXPORT ChannelMojo | 52 class IPC_MOJO_EXPORT ChannelMojo |
| 50 : public Channel, | 53 : public Channel, |
| 51 public MojoBootstrap::Delegate, | 54 public MojoBootstrap::Delegate, |
| 52 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { | 55 public NON_EXPORTED_BASE(internal::MessagePipeReader::Delegate) { |
| 53 public: | 56 public: |
| 54 using CreateMessagingPipeCallback = | 57 using CreateMessagingPipeCallback = |
| 55 base::Callback<void(mojo::ScopedMessagePipeHandle)>; | 58 base::Callback<void(mojo::ScopedMessagePipeHandle)>; |
| 59 #if !defined(USE_CHROME_EDK) |
| 56 using CreateMessagingPipeOnIOThreadCallback = | 60 using CreateMessagingPipeOnIOThreadCallback = |
| 57 base::Callback<void(mojo::ScopedMessagePipeHandle, | 61 base::Callback<void(mojo::ScopedMessagePipeHandle, |
| 58 mojo::embedder::ChannelInfo*)>; | 62 mojo::embedder::ChannelInfo*)>; |
| 63 #endif |
| 59 | 64 |
| 60 // True if ChannelMojo should be used regardless of the flag. | 65 // True if ChannelMojo should be used regardless of the flag. |
| 61 static bool ShouldBeUsed(); | 66 static bool ShouldBeUsed(); |
| 62 | 67 |
| 63 // Create ChannelMojo. A bootstrap channel is created as well. | 68 // Create ChannelMojo. A bootstrap channel is created as well. |
| 64 // |broker| must outlive the newly created channel. | 69 // |broker| must outlive the newly created channel. |
| 65 static scoped_ptr<ChannelMojo> Create( | 70 static scoped_ptr<ChannelMojo> Create( |
| 66 scoped_refptr<base::TaskRunner> io_runner, | 71 scoped_refptr<base::TaskRunner> io_runner, |
| 67 const ChannelHandle& channel_handle, | 72 const ChannelHandle& channel_handle, |
| 68 Mode mode, | 73 Mode mode, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 AttachmentBroker* broker); | 135 AttachmentBroker* broker); |
| 131 | 136 |
| 132 void CreateMessagingPipe(mojo::embedder::ScopedPlatformHandle handle, | 137 void CreateMessagingPipe(mojo::embedder::ScopedPlatformHandle handle, |
| 133 const CreateMessagingPipeCallback& callback); | 138 const CreateMessagingPipeCallback& callback); |
| 134 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); | 139 void InitMessageReader(mojo::ScopedMessagePipeHandle pipe, int32_t peer_pid); |
| 135 | 140 |
| 136 Listener* listener() const { return listener_; } | 141 Listener* listener() const { return listener_; } |
| 137 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } | 142 void set_peer_pid(base::ProcessId pid) { peer_pid_ = pid; } |
| 138 | 143 |
| 139 private: | 144 private: |
| 145 #if !defined(USE_CHROME_EDK) |
| 140 struct ChannelInfoDeleter { | 146 struct ChannelInfoDeleter { |
| 141 explicit ChannelInfoDeleter(scoped_refptr<base::TaskRunner> io_runner); | 147 explicit ChannelInfoDeleter(scoped_refptr<base::TaskRunner> io_runner); |
| 142 ~ChannelInfoDeleter(); | 148 ~ChannelInfoDeleter(); |
| 143 | 149 |
| 144 void operator()(mojo::embedder::ChannelInfo* ptr) const; | 150 void operator()(mojo::embedder::ChannelInfo* ptr) const; |
| 145 | 151 |
| 146 scoped_refptr<base::TaskRunner> io_runner; | 152 scoped_refptr<base::TaskRunner> io_runner; |
| 147 }; | 153 }; |
| 154 #endif |
| 148 | 155 |
| 149 // ChannelMojo needs to kill its MessagePipeReader in delayed manner | 156 // ChannelMojo needs to kill its MessagePipeReader in delayed manner |
| 150 // because the channel wants to kill these readers during the | 157 // because the channel wants to kill these readers during the |
| 151 // notifications invoked by them. | 158 // notifications invoked by them. |
| 152 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; | 159 typedef internal::MessagePipeReader::DelayedDeleter ReaderDeleter; |
| 153 | 160 |
| 154 void InitOnIOThread(); | 161 void InitOnIOThread(); |
| 155 | 162 |
| 163 #if !defined(USE_CHROME_EDK) |
| 156 static void CreateMessagingPipeOnIOThread( | 164 static void CreateMessagingPipeOnIOThread( |
| 157 mojo::embedder::ScopedPlatformHandle handle, | 165 mojo::embedder::ScopedPlatformHandle handle, |
| 158 scoped_refptr<base::TaskRunner> callback_runner, | 166 scoped_refptr<base::TaskRunner> callback_runner, |
| 159 const CreateMessagingPipeOnIOThreadCallback& callback); | 167 const CreateMessagingPipeOnIOThreadCallback& callback); |
| 160 void OnMessagingPipeCreated(const CreateMessagingPipeCallback& callback, | 168 void OnMessagingPipeCreated(const CreateMessagingPipeCallback& callback, |
| 161 mojo::ScopedMessagePipeHandle handle, | 169 mojo::ScopedMessagePipeHandle handle, |
| 162 mojo::embedder::ChannelInfo* channel_info); | 170 mojo::embedder::ChannelInfo* channel_info); |
| 171 #endif |
| 163 | 172 |
| 164 scoped_ptr<MojoBootstrap> bootstrap_; | 173 scoped_ptr<MojoBootstrap> bootstrap_; |
| 165 Listener* listener_; | 174 Listener* listener_; |
| 166 base::ProcessId peer_pid_; | 175 base::ProcessId peer_pid_; |
| 167 scoped_refptr<base::TaskRunner> io_runner_; | 176 scoped_refptr<base::TaskRunner> io_runner_; |
| 177 #if !defined(USE_CHROME_EDK) |
| 168 scoped_ptr<mojo::embedder::ChannelInfo, | 178 scoped_ptr<mojo::embedder::ChannelInfo, |
| 169 ChannelInfoDeleter> channel_info_; | 179 ChannelInfoDeleter> channel_info_; |
| 180 #endif |
| 170 | 181 |
| 171 // Guards |message_reader_|, |waiting_connect_| and |pending_messages_| | 182 // Guards |message_reader_|, |waiting_connect_| and |pending_messages_| |
| 172 // | 183 // |
| 173 // * The contents of |pending_messages_| can be modified from any thread. | 184 // * The contents of |pending_messages_| can be modified from any thread. |
| 174 // * |message_reader_| is modified only from the IO thread, | 185 // * |message_reader_| is modified only from the IO thread, |
| 175 // but they can be referenced from other threads. | 186 // but they can be referenced from other threads. |
| 176 base::Lock lock_; | 187 base::Lock lock_; |
| 177 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; | 188 scoped_ptr<internal::MessagePipeReader, ReaderDeleter> message_reader_; |
| 178 ScopedVector<Message> pending_messages_; | 189 ScopedVector<Message> pending_messages_; |
| 179 bool waiting_connect_; | 190 bool waiting_connect_; |
| 180 | 191 |
| 181 scoped_ptr<ScopedIPCSupport> ipc_support_; | 192 scoped_ptr<ScopedIPCSupport> ipc_support_; |
| 182 | 193 |
| 183 base::WeakPtrFactory<ChannelMojo> weak_factory_; | 194 base::WeakPtrFactory<ChannelMojo> weak_factory_; |
| 184 | 195 |
| 185 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); | 196 DISALLOW_COPY_AND_ASSIGN(ChannelMojo); |
| 186 }; | 197 }; |
| 187 | 198 |
| 188 } // namespace IPC | 199 } // namespace IPC |
| 189 | 200 |
| 190 #endif // IPC_IPC_CHANNEL_MOJO_H_ | 201 #endif // IPC_IPC_CHANNEL_MOJO_H_ |
| OLD | NEW |