| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "mojo/edk/embedder/multiprocess_embedder.h" | 5 #include "mojo/edk/embedder/multiprocess_embedder.h" |
| 6 | 6 |
| 7 #include <atomic> | 7 #include <atomic> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "mojo/edk/embedder/embedder_internal.h" | 11 #include "mojo/edk/embedder/embedder_internal.h" |
| 12 #include "mojo/edk/embedder/master_process_delegate.h" | 12 #include "mojo/edk/embedder/master_process_delegate.h" |
| 13 #include "mojo/edk/embedder/process_delegate.h" | 13 #include "mojo/edk/embedder/process_delegate.h" |
| 14 #include "mojo/edk/embedder/slave_process_delegate.h" | 14 #include "mojo/edk/embedder/slave_process_delegate.h" |
| 15 #include "mojo/edk/system/channel.h" | 15 #include "mojo/edk/system/channel.h" |
| 16 #include "mojo/edk/system/channel_manager.h" | 16 #include "mojo/edk/system/channel_manager.h" |
| 17 #include "mojo/edk/system/core.h" | 17 #include "mojo/edk/system/core.h" |
| 18 #include "mojo/edk/system/handle.h" |
| 18 #include "mojo/edk/system/ipc_support.h" | 19 #include "mojo/edk/system/ipc_support.h" |
| 19 #include "mojo/edk/system/message_pipe_dispatcher.h" | 20 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 20 #include "mojo/edk/system/raw_channel.h" | 21 #include "mojo/edk/system/raw_channel.h" |
| 21 #include "mojo/edk/util/ref_ptr.h" | 22 #include "mojo/edk/util/ref_ptr.h" |
| 22 | 23 |
| 23 using mojo::platform::PlatformHandleWatcher; | 24 using mojo::platform::PlatformHandleWatcher; |
| 24 using mojo::platform::ScopedPlatformHandle; | 25 using mojo::platform::ScopedPlatformHandle; |
| 25 using mojo::platform::TaskRunner; | 26 using mojo::platform::TaskRunner; |
| 26 using mojo::util::RefPtr; | 27 using mojo::util::RefPtr; |
| 27 | 28 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 internal::g_ipc_support->GenerateConnectionIdentifier(); | 122 internal::g_ipc_support->GenerateConnectionIdentifier(); |
| 122 *platform_connection_id = connection_id.ToString(); | 123 *platform_connection_id = connection_id.ToString(); |
| 123 system::ChannelId channel_id = system::kInvalidChannelId; | 124 system::ChannelId channel_id = system::kInvalidChannelId; |
| 124 RefPtr<system::MessagePipeDispatcher> dispatcher = | 125 RefPtr<system::MessagePipeDispatcher> dispatcher = |
| 125 internal::g_ipc_support->ConnectToSlave( | 126 internal::g_ipc_support->ConnectToSlave( |
| 126 connection_id, slave_info, platform_handle.Pass(), | 127 connection_id, slave_info, platform_handle.Pass(), |
| 127 std::move(did_connect_to_slave_callback), | 128 std::move(did_connect_to_slave_callback), |
| 128 std::move(did_connect_to_slave_runner), &channel_id); | 129 std::move(did_connect_to_slave_runner), &channel_id); |
| 129 *channel_info = new ChannelInfo(channel_id); | 130 *channel_info = new ChannelInfo(channel_id); |
| 130 | 131 |
| 131 ScopedMessagePipeHandle rv( | 132 ScopedMessagePipeHandle rv(MessagePipeHandle(internal::g_core->AddHandle( |
| 132 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); | 133 system::Handle(std::move(dispatcher), |
| 134 system::MessagePipeDispatcher::kDefaultHandleRights)))); |
| 133 CHECK(rv.is_valid()); | 135 CHECK(rv.is_valid()); |
| 134 return rv; | 136 return rv; |
| 135 } | 137 } |
| 136 | 138 |
| 137 ScopedMessagePipeHandle ConnectToMaster( | 139 ScopedMessagePipeHandle ConnectToMaster( |
| 138 const std::string& platform_connection_id, | 140 const std::string& platform_connection_id, |
| 139 std::function<void()>&& did_connect_to_master_callback, | 141 std::function<void()>&& did_connect_to_master_callback, |
| 140 RefPtr<TaskRunner>&& did_connect_to_master_runner, | 142 RefPtr<TaskRunner>&& did_connect_to_master_runner, |
| 141 ChannelInfo** channel_info) { | 143 ChannelInfo** channel_info) { |
| 142 DCHECK(channel_info); | 144 DCHECK(channel_info); |
| 143 DCHECK(internal::g_ipc_support); | 145 DCHECK(internal::g_ipc_support); |
| 144 | 146 |
| 145 bool ok = false; | 147 bool ok = false; |
| 146 system::ConnectionIdentifier connection_id = | 148 system::ConnectionIdentifier connection_id = |
| 147 system::ConnectionIdentifier::FromString(platform_connection_id, &ok); | 149 system::ConnectionIdentifier::FromString(platform_connection_id, &ok); |
| 148 CHECK(ok); | 150 CHECK(ok); |
| 149 | 151 |
| 150 system::ChannelId channel_id = system::kInvalidChannelId; | 152 system::ChannelId channel_id = system::kInvalidChannelId; |
| 151 RefPtr<system::MessagePipeDispatcher> dispatcher = | 153 RefPtr<system::MessagePipeDispatcher> dispatcher = |
| 152 internal::g_ipc_support->ConnectToMaster( | 154 internal::g_ipc_support->ConnectToMaster( |
| 153 connection_id, std::move(did_connect_to_master_callback), | 155 connection_id, std::move(did_connect_to_master_callback), |
| 154 std::move(did_connect_to_master_runner), &channel_id); | 156 std::move(did_connect_to_master_runner), &channel_id); |
| 155 *channel_info = new ChannelInfo(channel_id); | 157 *channel_info = new ChannelInfo(channel_id); |
| 156 | 158 |
| 157 ScopedMessagePipeHandle rv( | 159 ScopedMessagePipeHandle rv(MessagePipeHandle(internal::g_core->AddHandle( |
| 158 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); | 160 system::Handle(std::move(dispatcher), |
| 161 system::MessagePipeDispatcher::kDefaultHandleRights)))); |
| 159 CHECK(rv.is_valid()); | 162 CHECK(rv.is_valid()); |
| 160 return rv; | 163 return rv; |
| 161 } | 164 } |
| 162 | 165 |
| 163 // TODO(vtl): Write tests for this. | 166 // TODO(vtl): Write tests for this. |
| 164 ScopedMessagePipeHandle CreateChannelOnIOThread( | 167 ScopedMessagePipeHandle CreateChannelOnIOThread( |
| 165 ScopedPlatformHandle platform_handle, | 168 ScopedPlatformHandle platform_handle, |
| 166 ChannelInfo** channel_info) { | 169 ChannelInfo** channel_info) { |
| 167 DCHECK(platform_handle.is_valid()); | 170 DCHECK(platform_handle.is_valid()); |
| 168 DCHECK(channel_info); | 171 DCHECK(channel_info); |
| 169 DCHECK(internal::g_ipc_support); | 172 DCHECK(internal::g_ipc_support); |
| 170 | 173 |
| 171 system::ChannelManager* channel_manager = | 174 system::ChannelManager* channel_manager = |
| 172 internal::g_ipc_support->channel_manager(); | 175 internal::g_ipc_support->channel_manager(); |
| 173 | 176 |
| 174 *channel_info = new ChannelInfo(MakeChannelId()); | 177 *channel_info = new ChannelInfo(MakeChannelId()); |
| 175 RefPtr<system::MessagePipeDispatcher> dispatcher = | 178 RefPtr<system::MessagePipeDispatcher> dispatcher = |
| 176 channel_manager->CreateChannelOnIOThread((*channel_info)->channel_id, | 179 channel_manager->CreateChannelOnIOThread((*channel_info)->channel_id, |
| 177 platform_handle.Pass()); | 180 platform_handle.Pass()); |
| 178 | 181 |
| 179 ScopedMessagePipeHandle rv( | 182 ScopedMessagePipeHandle rv(MessagePipeHandle(internal::g_core->AddHandle( |
| 180 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); | 183 system::Handle(std::move(dispatcher), |
| 184 system::MessagePipeDispatcher::kDefaultHandleRights)))); |
| 181 CHECK(rv.is_valid()); | 185 CHECK(rv.is_valid()); |
| 182 return rv; | 186 return rv; |
| 183 } | 187 } |
| 184 | 188 |
| 185 ScopedMessagePipeHandle CreateChannel( | 189 ScopedMessagePipeHandle CreateChannel( |
| 186 ScopedPlatformHandle platform_handle, | 190 ScopedPlatformHandle platform_handle, |
| 187 std::function<void(ChannelInfo*)>&& did_create_channel_callback, | 191 std::function<void(ChannelInfo*)>&& did_create_channel_callback, |
| 188 RefPtr<TaskRunner>&& did_create_channel_runner) { | 192 RefPtr<TaskRunner>&& did_create_channel_runner) { |
| 189 DCHECK(platform_handle.is_valid()); | 193 DCHECK(platform_handle.is_valid()); |
| 190 DCHECK(did_create_channel_callback); | 194 DCHECK(did_create_channel_callback); |
| 191 DCHECK(internal::g_ipc_support); | 195 DCHECK(internal::g_ipc_support); |
| 192 | 196 |
| 193 system::ChannelManager* channel_manager = | 197 system::ChannelManager* channel_manager = |
| 194 internal::g_ipc_support->channel_manager(); | 198 internal::g_ipc_support->channel_manager(); |
| 195 | 199 |
| 196 system::ChannelId channel_id = MakeChannelId(); | 200 system::ChannelId channel_id = MakeChannelId(); |
| 197 // Ownership gets passed back to the caller via |did_create_channel_callback|. | 201 // Ownership gets passed back to the caller via |did_create_channel_callback|. |
| 198 ChannelInfo* channel_info = new ChannelInfo(channel_id); | 202 ChannelInfo* channel_info = new ChannelInfo(channel_id); |
| 199 RefPtr<system::MessagePipeDispatcher> dispatcher = | 203 RefPtr<system::MessagePipeDispatcher> dispatcher = |
| 200 channel_manager->CreateChannel( | 204 channel_manager->CreateChannel( |
| 201 channel_id, platform_handle.Pass(), | 205 channel_id, platform_handle.Pass(), |
| 202 [did_create_channel_callback, channel_info]() { | 206 [did_create_channel_callback, channel_info]() { |
| 203 did_create_channel_callback(channel_info); | 207 did_create_channel_callback(channel_info); |
| 204 }, | 208 }, |
| 205 std::move(did_create_channel_runner)); | 209 std::move(did_create_channel_runner)); |
| 206 | 210 |
| 207 ScopedMessagePipeHandle rv( | 211 ScopedMessagePipeHandle rv(MessagePipeHandle(internal::g_core->AddHandle( |
| 208 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); | 212 system::Handle(std::move(dispatcher), |
| 213 system::MessagePipeDispatcher::kDefaultHandleRights)))); |
| 209 CHECK(rv.is_valid()); | 214 CHECK(rv.is_valid()); |
| 210 return rv; | 215 return rv; |
| 211 } | 216 } |
| 212 | 217 |
| 213 // TODO(vtl): Write tests for this. | 218 // TODO(vtl): Write tests for this. |
| 214 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { | 219 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { |
| 215 DCHECK(channel_info); | 220 DCHECK(channel_info); |
| 216 DCHECK(channel_info->channel_id); | 221 DCHECK(channel_info->channel_id); |
| 217 DCHECK(internal::g_ipc_support); | 222 DCHECK(internal::g_ipc_support); |
| 218 | 223 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 243 DCHECK(channel_info); | 248 DCHECK(channel_info); |
| 244 DCHECK(internal::g_ipc_support); | 249 DCHECK(internal::g_ipc_support); |
| 245 | 250 |
| 246 system::ChannelManager* channel_manager = | 251 system::ChannelManager* channel_manager = |
| 247 internal::g_ipc_support->channel_manager(); | 252 internal::g_ipc_support->channel_manager(); |
| 248 channel_manager->WillShutdownChannel(channel_info->channel_id); | 253 channel_manager->WillShutdownChannel(channel_info->channel_id); |
| 249 } | 254 } |
| 250 | 255 |
| 251 } // namespace embedder | 256 } // namespace embedder |
| 252 } // namespace mojo | 257 } // namespace mojo |
| OLD | NEW |