Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: mojo/edk/system/core.cc

Issue 2735113003: Changing SpawnChild to return a struct.
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/core.h ('k') | mojo/edk/system/message_pipe_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 #include "mojo/edk/system/message_for_transit.h" 29 #include "mojo/edk/system/message_for_transit.h"
30 #include "mojo/edk/system/message_pipe_dispatcher.h" 30 #include "mojo/edk/system/message_pipe_dispatcher.h"
31 #include "mojo/edk/system/platform_handle_dispatcher.h" 31 #include "mojo/edk/system/platform_handle_dispatcher.h"
32 #include "mojo/edk/system/ports/name.h" 32 #include "mojo/edk/system/ports/name.h"
33 #include "mojo/edk/system/ports/node.h" 33 #include "mojo/edk/system/ports/node.h"
34 #include "mojo/edk/system/request_context.h" 34 #include "mojo/edk/system/request_context.h"
35 #include "mojo/edk/system/shared_buffer_dispatcher.h" 35 #include "mojo/edk/system/shared_buffer_dispatcher.h"
36 #include "mojo/edk/system/wait_set_dispatcher.h" 36 #include "mojo/edk/system/wait_set_dispatcher.h"
37 #include "mojo/edk/system/waiter.h" 37 #include "mojo/edk/system/waiter.h"
38 38
39 #if defined(OS_ANDROID)
40 #include "base/android/jni_android.h"
41 #endif
42
39 namespace mojo { 43 namespace mojo {
40 namespace edk { 44 namespace edk {
41 45
42 namespace { 46 namespace {
43 47
44 // This is an unnecessarily large limit that is relatively easy to enforce. 48 // This is an unnecessarily large limit that is relatively easy to enforce.
45 const uint32_t kMaxHandlesPerMessage = 1024 * 1024; 49 const uint32_t kMaxHandlesPerMessage = 1024 * 1024;
46 50
47 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process 51 // TODO(rockot): Maybe we could negotiate a debugging pipe ID for cross-process
48 // pipes too; for now we just use a constant. This only affects bootstrap pipes. 52 // pipes too; for now we just use a constant. This only affects bootstrap pipes.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 handle.port = static_cast<mach_port_t>(platform_handle->value); 86 handle.port = static_cast<mach_port_t>(platform_handle->value);
83 break; 87 break;
84 #endif 88 #endif
85 89
86 #if defined(OS_WIN) 90 #if defined(OS_WIN)
87 case MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE: 91 case MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE:
88 handle.handle = reinterpret_cast<HANDLE>(platform_handle->value); 92 handle.handle = reinterpret_cast<HANDLE>(platform_handle->value);
89 break; 93 break;
90 #endif 94 #endif
91 95
96 #if defined(OS_ANDROID)
97 case MOJO_PLATFORM_HANDLE_TYPE_PARCELABLE:
98 handle.type = PlatformHandle::Type::PARCELABLE;
99 handle.parcelable.Reset(
100 base::android::AttachCurrentThread(),
101 reinterpret_cast<jobject>(platform_handle->value));
102 break;
103 #endif
104
92 default: 105 default:
93 return MOJO_RESULT_INVALID_ARGUMENT; 106 return MOJO_RESULT_INVALID_ARGUMENT;
94 } 107 }
95 108
96 out_handle->reset(handle); 109 out_handle->reset(handle);
97 return MOJO_RESULT_OK; 110 return MOJO_RESULT_OK;
98 } 111 }
99 112
100 MojoResult ScopedPlatformHandleToMojoPlatformHandle( 113 MojoResult ScopedPlatformHandleToMojoPlatformHandle(
101 ScopedPlatformHandle handle, 114 ScopedPlatformHandle handle,
(...skipping 13 matching lines...) Expand all
115 platform_handle->value = static_cast<uint64_t>(handle.release().handle); 128 platform_handle->value = static_cast<uint64_t>(handle.release().handle);
116 break; 129 break;
117 130
118 #if defined(OS_MACOSX) && !defined(OS_IOS) 131 #if defined(OS_MACOSX) && !defined(OS_IOS)
119 case PlatformHandle::Type::MACH: 132 case PlatformHandle::Type::MACH:
120 platform_handle->type = MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT; 133 platform_handle->type = MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT;
121 platform_handle->value = static_cast<uint64_t>(handle.release().port); 134 platform_handle->value = static_cast<uint64_t>(handle.release().port);
122 break; 135 break;
123 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 136 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
124 137
138 #if defined(OS_ANDROID)
139 case PlatformHandle::Type::PARCELABLE:
140 platform_handle->type = MOJO_PLATFORM_HANDLE_TYPE_PARCELABLE;
141 platform_handle->value =
142 reinterpret_cast<uint64_t>(handle.release().parcelable.Release());
143 break;
144 #endif // defined(OS_ANDROID)
145
125 default: 146 default:
126 return MOJO_RESULT_INVALID_ARGUMENT; 147 return MOJO_RESULT_INVALID_ARGUMENT;
127 } 148 }
128 #elif defined(OS_WIN) 149 #elif defined(OS_WIN)
129 platform_handle->type = MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE; 150 platform_handle->type = MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE;
130 platform_handle->value = reinterpret_cast<uint64_t>(handle.release().handle); 151 platform_handle->value = reinterpret_cast<uint64_t>(handle.release().handle);
131 #endif // defined(OS_WIN) 152 #endif // defined(OS_WIN)
132 153
133 return MOJO_RESULT_OK; 154 return MOJO_RESULT_OK;
134 } 155 }
(...skipping 30 matching lines...) Expand all
165 base::AutoLock lock(handles_lock_); 186 base::AutoLock lock(handles_lock_);
166 return handles_.GetDispatcher(handle); 187 return handles_.GetDispatcher(handle);
167 } 188 }
168 189
169 void Core::SetDefaultProcessErrorCallback( 190 void Core::SetDefaultProcessErrorCallback(
170 const ProcessErrorCallback& callback) { 191 const ProcessErrorCallback& callback) {
171 default_process_error_callback_ = callback; 192 default_process_error_callback_ = callback;
172 } 193 }
173 194
174 void Core::AddChild(base::ProcessHandle process_handle, 195 void Core::AddChild(base::ProcessHandle process_handle,
175 ScopedPlatformHandle platform_handle, 196 ConnectionParam connection_param,
176 const std::string& child_token, 197 const std::string& child_token,
177 const ProcessErrorCallback& process_error_callback) { 198 const ProcessErrorCallback& process_error_callback) {
178 GetNodeController()->ConnectToChild(process_handle, 199 GetNodeController()->ConnectToChild(process_handle,
179 std::move(platform_handle), 200 std::move(connection_param), child_token,
180 child_token,
181 process_error_callback); 201 process_error_callback);
182 } 202 }
183 203
184 void Core::ChildLaunchFailed(const std::string& child_token) { 204 void Core::ChildLaunchFailed(const std::string& child_token) {
185 RequestContext request_context; 205 RequestContext request_context;
186 GetNodeController()->CloseChildPorts(child_token); 206 GetNodeController()->CloseChildPorts(child_token);
187 } 207 }
188 208
189 ScopedMessagePipeHandle Core::ConnectToPeerProcess( 209 ScopedMessagePipeHandle Core::ConnectToPeerProcess(
190 ScopedPlatformHandle pipe_handle, 210 ScopedPlatformHandle pipe_handle,
191 const std::string& peer_token) { 211 const std::string& peer_token) {
192 RequestContext request_context; 212 RequestContext request_context;
193 ports::PortRef port0, port1; 213 ports::PortRef port0, port1;
194 GetNodeController()->node()->CreatePortPair(&port0, &port1); 214 GetNodeController()->node()->CreatePortPair(&port0, &port1);
195 MojoHandle handle = AddDispatcher(new MessagePipeDispatcher( 215 MojoHandle handle = AddDispatcher(new MessagePipeDispatcher(
196 GetNodeController(), port0, kUnknownPipeIdForDebug, 0)); 216 GetNodeController(), port0, kUnknownPipeIdForDebug, 0));
197 GetNodeController()->ConnectToPeer(std::move(pipe_handle), port1, peer_token); 217 ConnectionParam connection_param(std::move(pipe_handle));
218 GetNodeController()->ConnectToPeer(std::move(connection_param), port1,
219 peer_token);
198 return ScopedMessagePipeHandle(MessagePipeHandle(handle)); 220 return ScopedMessagePipeHandle(MessagePipeHandle(handle));
199 } 221 }
200 222
201 void Core::ClosePeerConnection(const std::string& peer_token) { 223 void Core::ClosePeerConnection(const std::string& peer_token) {
202 GetNodeController()->ClosePeerConnection(peer_token); 224 GetNodeController()->ClosePeerConnection(peer_token);
203 } 225 }
204 226
205 void Core::InitChild(ScopedPlatformHandle platform_handle) { 227 void Core::InitChild(ConnectionParam connection_param) {
206 GetNodeController()->ConnectToParent(std::move(platform_handle)); 228 GetNodeController()->ConnectToParent(std::move(connection_param));
207 } 229 }
208 230
209 void Core::SetMachPortProvider(base::PortProvider* port_provider) { 231 void Core::SetMachPortProvider(base::PortProvider* port_provider) {
210 #if defined(OS_MACOSX) && !defined(OS_IOS) 232 #if defined(OS_MACOSX) && !defined(OS_IOS)
211 GetNodeController()->CreateMachPortRelay(port_provider); 233 GetNodeController()->CreateMachPortRelay(port_provider);
212 #endif 234 #endif
213 } 235 }
214 236
215 MojoHandle Core::AddDispatcher(scoped_refptr<Dispatcher> dispatcher) { 237 MojoHandle Core::AddDispatcher(scoped_refptr<Dispatcher> dispatcher) {
216 base::AutoLock lock(handles_lock_); 238 base::AutoLock lock(handles_lock_);
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 uint32_t* num_bytes, 702 uint32_t* num_bytes,
681 MojoHandle* handles, 703 MojoHandle* handles,
682 uint32_t* num_handles, 704 uint32_t* num_handles,
683 MojoReadMessageFlags flags) { 705 MojoReadMessageFlags flags) {
684 CHECK((!num_handles || !*num_handles || handles) && 706 CHECK((!num_handles || !*num_handles || handles) &&
685 (!num_bytes || !*num_bytes || bytes)); 707 (!num_bytes || !*num_bytes || bytes));
686 RequestContext request_context; 708 RequestContext request_context;
687 auto dispatcher = GetDispatcher(message_pipe_handle); 709 auto dispatcher = GetDispatcher(message_pipe_handle);
688 if (!dispatcher) 710 if (!dispatcher)
689 return MOJO_RESULT_INVALID_ARGUMENT; 711 return MOJO_RESULT_INVALID_ARGUMENT;
712
690 std::unique_ptr<MessageForTransit> message; 713 std::unique_ptr<MessageForTransit> message;
691 MojoResult rv = 714 MojoResult rv =
692 dispatcher->ReadMessage(&message, num_bytes, handles, num_handles, flags, 715 dispatcher->ReadMessage(&message, num_bytes, handles, num_handles, flags,
693 false /* ignore_num_bytes */); 716 false /* ignore_num_bytes */);
694 if (rv != MOJO_RESULT_OK) 717 if (rv != MOJO_RESULT_OK)
695 return rv; 718 return rv;
696 719
697 if (message && message->num_bytes()) 720 if (message && message->num_bytes())
698 memcpy(bytes, message->bytes(), message->num_bytes()); 721 memcpy(bytes, message->bytes(), message->num_bytes());
699 722
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 std::unique_ptr<NodeController> node_controller) { 1192 std::unique_ptr<NodeController> node_controller) {
1170 // It's OK to leak this reference. At this point we know the IO loop is still 1193 // It's OK to leak this reference. At this point we know the IO loop is still
1171 // running, and we know the NodeController will observe its eventual 1194 // running, and we know the NodeController will observe its eventual
1172 // destruction. This tells the NodeController to delete itself when that 1195 // destruction. This tells the NodeController to delete itself when that
1173 // happens. 1196 // happens.
1174 node_controller.release()->DestroyOnIOThreadShutdown(); 1197 node_controller.release()->DestroyOnIOThreadShutdown();
1175 } 1198 }
1176 1199
1177 } // namespace edk 1200 } // namespace edk
1178 } // namespace mojo 1201 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core.h ('k') | mojo/edk/system/message_pipe_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698