| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/system/core.h" | 5 #include "mojo/edk/system/core.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if (base::ThreadTaskRunnerHandle::IsSet()) { | 153 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 154 on_shutdown = base::Bind(base::IgnoreResult(&base::TaskRunner::PostTask), | 154 on_shutdown = base::Bind(base::IgnoreResult(&base::TaskRunner::PostTask), |
| 155 base::ThreadTaskRunnerHandle::Get(), | 155 base::ThreadTaskRunnerHandle::Get(), |
| 156 FROM_HERE, callback); | 156 FROM_HERE, callback); |
| 157 } else { | 157 } else { |
| 158 on_shutdown = callback; | 158 on_shutdown = callback; |
| 159 } | 159 } |
| 160 GetNodeController()->RequestShutdown(on_shutdown); | 160 GetNodeController()->RequestShutdown(on_shutdown); |
| 161 } | 161 } |
| 162 | 162 |
| 163 ScopedMessagePipeHandle Core::CreateMessagePipe( |
| 164 ScopedPlatformHandle platform_handle) { |
| 165 ports::PortRef port0, port1; |
| 166 GetNodeController()->node()->CreatePortPair(&port0, &port1); |
| 167 MojoHandle handle = AddDispatcher( |
| 168 new MessagePipeDispatcher(GetNodeController(), port0, |
| 169 0x7f7f7f7f7f7f7f7fUL, 0)); |
| 170 RemoteMessagePipeBootstrap::Create( |
| 171 GetNodeController(), std::move(platform_handle), port1); |
| 172 return ScopedMessagePipeHandle(MessagePipeHandle(handle)); |
| 173 } |
| 174 |
| 163 void Core::CreateMessagePipe( | 175 void Core::CreateMessagePipe( |
| 164 ScopedPlatformHandle platform_handle, | 176 ScopedPlatformHandle platform_handle, |
| 165 const base::Callback<void(ScopedMessagePipeHandle)>& callback) { | 177 const base::Callback<void(ScopedMessagePipeHandle)>& callback) { |
| 166 ports::PortRef port; | 178 callback.Run(CreateMessagePipe(std::move(platform_handle))); |
| 167 GetNodeController()->node()->CreateUninitializedPort(&port); | |
| 168 RemoteMessagePipeBootstrap::Create( | |
| 169 GetNodeController(), std::move(platform_handle), port, | |
| 170 base::Bind(&OnPortConnected, base::Unretained(this), 0, callback, port)); | |
| 171 } | 179 } |
| 172 | 180 |
| 173 void Core::CreateParentMessagePipe( | 181 void Core::CreateParentMessagePipe( |
| 174 const std::string& token, | 182 const std::string& token, |
| 175 const base::Callback<void(ScopedMessagePipeHandle)>& callback) { | 183 const base::Callback<void(ScopedMessagePipeHandle)>& callback) { |
| 176 GetNodeController()->ReservePort( | 184 GetNodeController()->ReservePort( |
| 177 token, | 185 token, |
| 178 base::Bind(&OnPortConnected, base::Unretained(this), 0, callback)); | 186 base::Bind(&OnPortConnected, base::Unretained(this), 0, callback)); |
| 179 } | 187 } |
| 180 | 188 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 scoped_ptr<NodeController> node_controller) { | 712 scoped_ptr<NodeController> node_controller) { |
| 705 // It's OK to leak this reference. At this point we know the IO loop is still | 713 // It's OK to leak this reference. At this point we know the IO loop is still |
| 706 // running, and we know the NodeController will observe its eventual | 714 // running, and we know the NodeController will observe its eventual |
| 707 // destruction. This tells the NodeController to delete itself when that | 715 // destruction. This tells the NodeController to delete itself when that |
| 708 // happens. | 716 // happens. |
| 709 node_controller.release()->DestroyOnIOThreadShutdown(); | 717 node_controller.release()->DestroyOnIOThreadShutdown(); |
| 710 } | 718 } |
| 711 | 719 |
| 712 } // namespace edk | 720 } // namespace edk |
| 713 } // namespace mojo | 721 } // namespace mojo |
| OLD | NEW |