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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/containers/stack_container.h" | 12 #include "base/containers/stack_container.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/trace_event/memory_dump_manager.h" |
21 #include "mojo/edk/embedder/embedder.h" | 22 #include "mojo/edk/embedder/embedder.h" |
22 #include "mojo/edk/embedder/embedder_internal.h" | 23 #include "mojo/edk/embedder/embedder_internal.h" |
23 #include "mojo/edk/embedder/platform_shared_buffer.h" | 24 #include "mojo/edk/embedder/platform_shared_buffer.h" |
24 #include "mojo/edk/system/channel.h" | 25 #include "mojo/edk/system/channel.h" |
25 #include "mojo/edk/system/configuration.h" | 26 #include "mojo/edk/system/configuration.h" |
26 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" | 27 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
27 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" | 28 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
28 #include "mojo/edk/system/handle_signals_state.h" | 29 #include "mojo/edk/system/handle_signals_state.h" |
29 #include "mojo/edk/system/message_pipe_dispatcher.h" | 30 #include "mojo/edk/system/message_pipe_dispatcher.h" |
30 #include "mojo/edk/system/platform_handle_dispatcher.h" | 31 #include "mojo/edk/system/platform_handle_dispatcher.h" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 #elif defined(OS_WIN) | 120 #elif defined(OS_WIN) |
120 platform_handle->type = MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE; | 121 platform_handle->type = MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE; |
121 platform_handle->value = reinterpret_cast<uint64_t>(handle.release().handle); | 122 platform_handle->value = reinterpret_cast<uint64_t>(handle.release().handle); |
122 #endif // defined(OS_WIN) | 123 #endif // defined(OS_WIN) |
123 | 124 |
124 return MOJO_RESULT_OK; | 125 return MOJO_RESULT_OK; |
125 } | 126 } |
126 | 127 |
127 } // namespace | 128 } // namespace |
128 | 129 |
129 Core::Core() {} | 130 Core::Core() { |
| 131 handles_.reset(new HandleTable); |
| 132 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 133 handles_.get(), "MojoHandleTable", nullptr); |
| 134 } |
130 | 135 |
131 Core::~Core() { | 136 Core::~Core() { |
132 if (node_controller_ && node_controller_->io_task_runner()) { | 137 if (node_controller_ && node_controller_->io_task_runner()) { |
133 // If this races with IO thread shutdown the callback will be dropped and | 138 // If this races with IO thread shutdown the callback will be dropped and |
134 // the NodeController will be shutdown on this thread anyway, which is also | 139 // the NodeController will be shutdown on this thread anyway, which is also |
135 // just fine. | 140 // just fine. |
136 scoped_refptr<base::TaskRunner> io_task_runner = | 141 scoped_refptr<base::TaskRunner> io_task_runner = |
137 node_controller_->io_task_runner(); | 142 node_controller_->io_task_runner(); |
138 io_task_runner->PostTask(FROM_HERE, | 143 io_task_runner->PostTask(FROM_HERE, |
139 base::Bind(&Core::PassNodeControllerToIOThread, | 144 base::Bind(&Core::PassNodeControllerToIOThread, |
140 base::Passed(&node_controller_))); | 145 base::Passed(&node_controller_))); |
141 } | 146 } |
| 147 base::trace_event::MemoryDumpManager::GetInstance() |
| 148 ->UnregisterAndDeleteDumpProviderSoon(std::move(handles_)); |
142 } | 149 } |
143 | 150 |
144 void Core::SetIOTaskRunner(scoped_refptr<base::TaskRunner> io_task_runner) { | 151 void Core::SetIOTaskRunner(scoped_refptr<base::TaskRunner> io_task_runner) { |
145 GetNodeController()->SetIOTaskRunner(io_task_runner); | 152 GetNodeController()->SetIOTaskRunner(io_task_runner); |
146 } | 153 } |
147 | 154 |
148 NodeController* Core::GetNodeController() { | 155 NodeController* Core::GetNodeController() { |
149 base::AutoLock lock(node_controller_lock_); | 156 base::AutoLock lock(node_controller_lock_); |
150 if (!node_controller_) | 157 if (!node_controller_) |
151 node_controller_.reset(new NodeController(this)); | 158 node_controller_.reset(new NodeController(this)); |
152 return node_controller_.get(); | 159 return node_controller_.get(); |
153 } | 160 } |
154 | 161 |
155 scoped_refptr<Dispatcher> Core::GetDispatcher(MojoHandle handle) { | 162 scoped_refptr<Dispatcher> Core::GetDispatcher(MojoHandle handle) { |
156 base::AutoLock lock(handles_.GetLock()); | 163 base::AutoLock lock(handles_->GetLock()); |
157 return handles_.GetDispatcher(handle); | 164 return handles_->GetDispatcher(handle); |
158 } | 165 } |
159 | 166 |
160 void Core::SetDefaultProcessErrorCallback( | 167 void Core::SetDefaultProcessErrorCallback( |
161 const ProcessErrorCallback& callback) { | 168 const ProcessErrorCallback& callback) { |
162 default_process_error_callback_ = callback; | 169 default_process_error_callback_ = callback; |
163 } | 170 } |
164 | 171 |
165 ScopedMessagePipeHandle Core::CreatePartialMessagePipe(ports::PortRef* peer) { | 172 ScopedMessagePipeHandle Core::CreatePartialMessagePipe(ports::PortRef* peer) { |
166 RequestContext request_context; | 173 RequestContext request_context; |
167 ports::PortRef local_port; | 174 ports::PortRef local_port; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 GetNodeController()->ClosePeerConnection(peer_connection_id); | 214 GetNodeController()->ClosePeerConnection(peer_connection_id); |
208 } | 215 } |
209 | 216 |
210 void Core::SetMachPortProvider(base::PortProvider* port_provider) { | 217 void Core::SetMachPortProvider(base::PortProvider* port_provider) { |
211 #if defined(OS_MACOSX) && !defined(OS_IOS) | 218 #if defined(OS_MACOSX) && !defined(OS_IOS) |
212 GetNodeController()->CreateMachPortRelay(port_provider); | 219 GetNodeController()->CreateMachPortRelay(port_provider); |
213 #endif | 220 #endif |
214 } | 221 } |
215 | 222 |
216 MojoHandle Core::AddDispatcher(scoped_refptr<Dispatcher> dispatcher) { | 223 MojoHandle Core::AddDispatcher(scoped_refptr<Dispatcher> dispatcher) { |
217 base::AutoLock lock(handles_.GetLock()); | 224 base::AutoLock lock(handles_->GetLock()); |
218 return handles_.AddDispatcher(dispatcher); | 225 return handles_->AddDispatcher(dispatcher); |
219 } | 226 } |
220 | 227 |
221 bool Core::AddDispatchersFromTransit( | 228 bool Core::AddDispatchersFromTransit( |
222 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers, | 229 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers, |
223 MojoHandle* handles) { | 230 MojoHandle* handles) { |
224 bool failed = false; | 231 bool failed = false; |
225 { | 232 { |
226 base::AutoLock lock(handles_.GetLock()); | 233 base::AutoLock lock(handles_->GetLock()); |
227 if (!handles_.AddDispatchersFromTransit(dispatchers, handles)) | 234 if (!handles_->AddDispatchersFromTransit(dispatchers, handles)) |
228 failed = true; | 235 failed = true; |
229 } | 236 } |
230 if (failed) { | 237 if (failed) { |
231 for (auto d : dispatchers) | 238 for (auto d : dispatchers) |
232 d.dispatcher->Close(); | 239 d.dispatcher->Close(); |
233 return false; | 240 return false; |
234 } | 241 } |
235 return true; | 242 return true; |
236 } | 243 } |
237 | 244 |
238 MojoResult Core::CreatePlatformHandleWrapper( | 245 MojoResult Core::CreatePlatformHandleWrapper( |
239 ScopedPlatformHandle platform_handle, | 246 ScopedPlatformHandle platform_handle, |
240 MojoHandle* wrapper_handle) { | 247 MojoHandle* wrapper_handle) { |
241 MojoHandle h = AddDispatcher( | 248 MojoHandle h = AddDispatcher( |
242 PlatformHandleDispatcher::Create(std::move(platform_handle))); | 249 PlatformHandleDispatcher::Create(std::move(platform_handle))); |
243 if (h == MOJO_HANDLE_INVALID) | 250 if (h == MOJO_HANDLE_INVALID) |
244 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 251 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
245 *wrapper_handle = h; | 252 *wrapper_handle = h; |
246 return MOJO_RESULT_OK; | 253 return MOJO_RESULT_OK; |
247 } | 254 } |
248 | 255 |
249 MojoResult Core::PassWrappedPlatformHandle( | 256 MojoResult Core::PassWrappedPlatformHandle( |
250 MojoHandle wrapper_handle, | 257 MojoHandle wrapper_handle, |
251 ScopedPlatformHandle* platform_handle) { | 258 ScopedPlatformHandle* platform_handle) { |
252 base::AutoLock lock(handles_.GetLock()); | 259 base::AutoLock lock(handles_->GetLock()); |
253 scoped_refptr<Dispatcher> d; | 260 scoped_refptr<Dispatcher> d; |
254 MojoResult result = handles_.GetAndRemoveDispatcher(wrapper_handle, &d); | 261 MojoResult result = handles_->GetAndRemoveDispatcher(wrapper_handle, &d); |
255 if (result != MOJO_RESULT_OK) | 262 if (result != MOJO_RESULT_OK) |
256 return result; | 263 return result; |
257 if (d->GetType() == Dispatcher::Type::PLATFORM_HANDLE) { | 264 if (d->GetType() == Dispatcher::Type::PLATFORM_HANDLE) { |
258 PlatformHandleDispatcher* phd = | 265 PlatformHandleDispatcher* phd = |
259 static_cast<PlatformHandleDispatcher*>(d.get()); | 266 static_cast<PlatformHandleDispatcher*>(d.get()); |
260 *platform_handle = phd->PassPlatformHandle(); | 267 *platform_handle = phd->PassPlatformHandle(); |
261 } else { | 268 } else { |
262 result = MOJO_RESULT_INVALID_ARGUMENT; | 269 result = MOJO_RESULT_INVALID_ARGUMENT; |
263 } | 270 } |
264 d->Close(); | 271 d->Close(); |
(...skipping 28 matching lines...) Expand all Loading... |
293 MojoHandle mojo_handle, | 300 MojoHandle mojo_handle, |
294 base::SharedMemoryHandle* shared_memory_handle, | 301 base::SharedMemoryHandle* shared_memory_handle, |
295 size_t* num_bytes, | 302 size_t* num_bytes, |
296 bool* read_only) { | 303 bool* read_only) { |
297 if (!shared_memory_handle) | 304 if (!shared_memory_handle) |
298 return MOJO_RESULT_INVALID_ARGUMENT; | 305 return MOJO_RESULT_INVALID_ARGUMENT; |
299 | 306 |
300 scoped_refptr<Dispatcher> dispatcher; | 307 scoped_refptr<Dispatcher> dispatcher; |
301 MojoResult result = MOJO_RESULT_OK; | 308 MojoResult result = MOJO_RESULT_OK; |
302 { | 309 { |
303 base::AutoLock lock(handles_.GetLock()); | 310 base::AutoLock lock(handles_->GetLock()); |
304 // Get the dispatcher and check it before removing it from the handle table | 311 // Get the dispatcher and check it before removing it from the handle table |
305 // to ensure that the dispatcher is of the correct type. This ensures we | 312 // to ensure that the dispatcher is of the correct type. This ensures we |
306 // don't close and remove the wrong type of dispatcher. | 313 // don't close and remove the wrong type of dispatcher. |
307 dispatcher = handles_.GetDispatcher(mojo_handle); | 314 dispatcher = handles_->GetDispatcher(mojo_handle); |
308 if (!dispatcher || dispatcher->GetType() != Dispatcher::Type::SHARED_BUFFER) | 315 if (!dispatcher || dispatcher->GetType() != Dispatcher::Type::SHARED_BUFFER) |
309 return MOJO_RESULT_INVALID_ARGUMENT; | 316 return MOJO_RESULT_INVALID_ARGUMENT; |
310 | 317 |
311 result = handles_.GetAndRemoveDispatcher(mojo_handle, &dispatcher); | 318 result = handles_->GetAndRemoveDispatcher(mojo_handle, &dispatcher); |
312 if (result != MOJO_RESULT_OK) | 319 if (result != MOJO_RESULT_OK) |
313 return result; | 320 return result; |
314 } | 321 } |
315 | 322 |
316 SharedBufferDispatcher* shm_dispatcher = | 323 SharedBufferDispatcher* shm_dispatcher = |
317 static_cast<SharedBufferDispatcher*>(dispatcher.get()); | 324 static_cast<SharedBufferDispatcher*>(dispatcher.get()); |
318 scoped_refptr<PlatformSharedBuffer> platform_shared_buffer = | 325 scoped_refptr<PlatformSharedBuffer> platform_shared_buffer = |
319 shm_dispatcher->PassPlatformSharedBuffer(); | 326 shm_dispatcher->PassPlatformSharedBuffer(); |
320 | 327 |
321 if (!platform_shared_buffer) | 328 if (!platform_shared_buffer) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 } | 366 } |
360 | 367 |
361 MojoTimeTicks Core::GetTimeTicksNow() { | 368 MojoTimeTicks Core::GetTimeTicksNow() { |
362 return base::TimeTicks::Now().ToInternalValue(); | 369 return base::TimeTicks::Now().ToInternalValue(); |
363 } | 370 } |
364 | 371 |
365 MojoResult Core::Close(MojoHandle handle) { | 372 MojoResult Core::Close(MojoHandle handle) { |
366 RequestContext request_context; | 373 RequestContext request_context; |
367 scoped_refptr<Dispatcher> dispatcher; | 374 scoped_refptr<Dispatcher> dispatcher; |
368 { | 375 { |
369 base::AutoLock lock(handles_.GetLock()); | 376 base::AutoLock lock(handles_->GetLock()); |
370 MojoResult rv = handles_.GetAndRemoveDispatcher(handle, &dispatcher); | 377 MojoResult rv = handles_->GetAndRemoveDispatcher(handle, &dispatcher); |
371 if (rv != MOJO_RESULT_OK) | 378 if (rv != MOJO_RESULT_OK) |
372 return rv; | 379 return rv; |
373 } | 380 } |
374 dispatcher->Close(); | 381 dispatcher->Close(); |
375 return MOJO_RESULT_OK; | 382 return MOJO_RESULT_OK; |
376 } | 383 } |
377 | 384 |
378 MojoResult Core::QueryHandleSignalsState( | 385 MojoResult Core::QueryHandleSignalsState( |
379 MojoHandle handle, | 386 MojoHandle handle, |
380 MojoHandleSignalsState* signals_state) { | 387 MojoHandleSignalsState* signals_state) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 463 |
457 if (num_handles > kMaxHandlesPerMessage) | 464 if (num_handles > kMaxHandlesPerMessage) |
458 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 465 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
459 | 466 |
460 // If serialization fails below this point, one or more handles may be closed. | 467 // If serialization fails below this point, one or more handles may be closed. |
461 // This requires an active RequestContext. | 468 // This requires an active RequestContext. |
462 RequestContext request_context; | 469 RequestContext request_context; |
463 | 470 |
464 std::vector<Dispatcher::DispatcherInTransit> dispatchers; | 471 std::vector<Dispatcher::DispatcherInTransit> dispatchers; |
465 { | 472 { |
466 base::AutoLock lock(handles_.GetLock()); | 473 base::AutoLock lock(handles_->GetLock()); |
467 MojoResult rv = handles_.BeginTransit(handles, num_handles, &dispatchers); | 474 MojoResult rv = handles_->BeginTransit(handles, num_handles, &dispatchers); |
468 if (rv != MOJO_RESULT_OK) { | 475 if (rv != MOJO_RESULT_OK) { |
469 handles_.CancelTransit(dispatchers); | 476 handles_->CancelTransit(dispatchers); |
470 return rv; | 477 return rv; |
471 } | 478 } |
472 } | 479 } |
473 DCHECK_EQ(num_handles, dispatchers.size()); | 480 DCHECK_EQ(num_handles, dispatchers.size()); |
474 | 481 |
475 std::unique_ptr<ports::UserMessageEvent> message; | 482 std::unique_ptr<ports::UserMessageEvent> message; |
476 MojoResult rv = UserMessageImpl::CreateEventForNewSerializedMessage( | 483 MojoResult rv = UserMessageImpl::CreateEventForNewSerializedMessage( |
477 num_bytes, dispatchers.data(), num_handles, &message); | 484 num_bytes, dispatchers.data(), num_handles, &message); |
478 | 485 |
479 { | 486 { |
480 base::AutoLock lock(handles_.GetLock()); | 487 base::AutoLock lock(handles_->GetLock()); |
481 if (rv == MOJO_RESULT_OK) { | 488 if (rv == MOJO_RESULT_OK) { |
482 handles_.CompleteTransitAndClose(dispatchers); | 489 handles_->CompleteTransitAndClose(dispatchers); |
483 *message_handle = reinterpret_cast<MojoMessageHandle>(message.release()); | 490 *message_handle = reinterpret_cast<MojoMessageHandle>(message.release()); |
484 } else { | 491 } else { |
485 handles_.CancelTransit(dispatchers); | 492 handles_->CancelTransit(dispatchers); |
486 } | 493 } |
487 } | 494 } |
488 | 495 |
489 return rv; | 496 return rv; |
490 } | 497 } |
491 | 498 |
492 MojoResult Core::FreeMessage(MojoMessageHandle message_handle) { | 499 MojoResult Core::FreeMessage(MojoMessageHandle message_handle) { |
493 if (!message_handle) | 500 if (!message_handle) |
494 return MOJO_RESULT_INVALID_ARGUMENT; | 501 return MOJO_RESULT_INVALID_ARGUMENT; |
495 | 502 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 new MessagePipeDispatcher(GetNodeController(), port0, pipe_id, 0)); | 547 new MessagePipeDispatcher(GetNodeController(), port0, pipe_id, 0)); |
541 if (*message_pipe_handle0 == MOJO_HANDLE_INVALID) | 548 if (*message_pipe_handle0 == MOJO_HANDLE_INVALID) |
542 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 549 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
543 | 550 |
544 *message_pipe_handle1 = AddDispatcher( | 551 *message_pipe_handle1 = AddDispatcher( |
545 new MessagePipeDispatcher(GetNodeController(), port1, pipe_id, 1)); | 552 new MessagePipeDispatcher(GetNodeController(), port1, pipe_id, 1)); |
546 if (*message_pipe_handle1 == MOJO_HANDLE_INVALID) { | 553 if (*message_pipe_handle1 == MOJO_HANDLE_INVALID) { |
547 scoped_refptr<Dispatcher> unused; | 554 scoped_refptr<Dispatcher> unused; |
548 unused->Close(); | 555 unused->Close(); |
549 | 556 |
550 base::AutoLock lock(handles_.GetLock()); | 557 base::AutoLock lock(handles_->GetLock()); |
551 handles_.GetAndRemoveDispatcher(*message_pipe_handle0, &unused); | 558 handles_->GetAndRemoveDispatcher(*message_pipe_handle0, &unused); |
552 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 559 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
553 } | 560 } |
554 | 561 |
555 return MOJO_RESULT_OK; | 562 return MOJO_RESULT_OK; |
556 } | 563 } |
557 | 564 |
558 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle, | 565 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle, |
559 const void* bytes, | 566 const void* bytes, |
560 uint32_t num_bytes, | 567 uint32_t num_bytes, |
561 const MojoHandle* handles, | 568 const MojoHandle* handles, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 return MOJO_RESULT_OK; | 657 return MOJO_RESULT_OK; |
651 } | 658 } |
652 | 659 |
653 MojoResult Core::FuseMessagePipes(MojoHandle handle0, MojoHandle handle1) { | 660 MojoResult Core::FuseMessagePipes(MojoHandle handle0, MojoHandle handle1) { |
654 RequestContext request_context; | 661 RequestContext request_context; |
655 scoped_refptr<Dispatcher> dispatcher0; | 662 scoped_refptr<Dispatcher> dispatcher0; |
656 scoped_refptr<Dispatcher> dispatcher1; | 663 scoped_refptr<Dispatcher> dispatcher1; |
657 | 664 |
658 bool valid_handles = true; | 665 bool valid_handles = true; |
659 { | 666 { |
660 base::AutoLock lock(handles_.GetLock()); | 667 base::AutoLock lock(handles_->GetLock()); |
661 MojoResult result0 = handles_.GetAndRemoveDispatcher(handle0, &dispatcher0); | 668 MojoResult result0 = |
662 MojoResult result1 = handles_.GetAndRemoveDispatcher(handle1, &dispatcher1); | 669 handles_->GetAndRemoveDispatcher(handle0, &dispatcher0); |
| 670 MojoResult result1 = |
| 671 handles_->GetAndRemoveDispatcher(handle1, &dispatcher1); |
663 if (result0 != MOJO_RESULT_OK || result1 != MOJO_RESULT_OK || | 672 if (result0 != MOJO_RESULT_OK || result1 != MOJO_RESULT_OK || |
664 dispatcher0->GetType() != Dispatcher::Type::MESSAGE_PIPE || | 673 dispatcher0->GetType() != Dispatcher::Type::MESSAGE_PIPE || |
665 dispatcher1->GetType() != Dispatcher::Type::MESSAGE_PIPE) | 674 dispatcher1->GetType() != Dispatcher::Type::MESSAGE_PIPE) |
666 valid_handles = false; | 675 valid_handles = false; |
667 } | 676 } |
668 | 677 |
669 if (!valid_handles) { | 678 if (!valid_handles) { |
670 if (dispatcher0) | 679 if (dispatcher0) |
671 dispatcher0->Close(); | 680 dispatcher0->Close(); |
672 if (dispatcher1) | 681 if (dispatcher1) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 producer->Close(); | 756 producer->Close(); |
748 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 757 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
749 } | 758 } |
750 | 759 |
751 *data_pipe_producer_handle = AddDispatcher(producer); | 760 *data_pipe_producer_handle = AddDispatcher(producer); |
752 *data_pipe_consumer_handle = AddDispatcher(consumer); | 761 *data_pipe_consumer_handle = AddDispatcher(consumer); |
753 if (*data_pipe_producer_handle == MOJO_HANDLE_INVALID || | 762 if (*data_pipe_producer_handle == MOJO_HANDLE_INVALID || |
754 *data_pipe_consumer_handle == MOJO_HANDLE_INVALID) { | 763 *data_pipe_consumer_handle == MOJO_HANDLE_INVALID) { |
755 if (*data_pipe_producer_handle != MOJO_HANDLE_INVALID) { | 764 if (*data_pipe_producer_handle != MOJO_HANDLE_INVALID) { |
756 scoped_refptr<Dispatcher> unused; | 765 scoped_refptr<Dispatcher> unused; |
757 base::AutoLock lock(handles_.GetLock()); | 766 base::AutoLock lock(handles_->GetLock()); |
758 handles_.GetAndRemoveDispatcher(*data_pipe_producer_handle, &unused); | 767 handles_->GetAndRemoveDispatcher(*data_pipe_producer_handle, &unused); |
759 } | 768 } |
760 producer->Close(); | 769 producer->Close(); |
761 consumer->Close(); | 770 consumer->Close(); |
762 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 771 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
763 } | 772 } |
764 | 773 |
765 return MOJO_RESULT_OK; | 774 return MOJO_RESULT_OK; |
766 } | 775 } |
767 | 776 |
768 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, | 777 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 } | 995 } |
987 | 996 |
988 MojoResult Core::UnwrapPlatformSharedBufferHandle( | 997 MojoResult Core::UnwrapPlatformSharedBufferHandle( |
989 MojoHandle mojo_handle, | 998 MojoHandle mojo_handle, |
990 MojoPlatformHandle* platform_handle, | 999 MojoPlatformHandle* platform_handle, |
991 size_t* size, | 1000 size_t* size, |
992 MojoPlatformSharedBufferHandleFlags* flags) { | 1001 MojoPlatformSharedBufferHandleFlags* flags) { |
993 scoped_refptr<Dispatcher> dispatcher; | 1002 scoped_refptr<Dispatcher> dispatcher; |
994 MojoResult result = MOJO_RESULT_OK; | 1003 MojoResult result = MOJO_RESULT_OK; |
995 { | 1004 { |
996 base::AutoLock lock(handles_.GetLock()); | 1005 base::AutoLock lock(handles_->GetLock()); |
997 result = handles_.GetAndRemoveDispatcher(mojo_handle, &dispatcher); | 1006 result = handles_->GetAndRemoveDispatcher(mojo_handle, &dispatcher); |
998 if (result != MOJO_RESULT_OK) | 1007 if (result != MOJO_RESULT_OK) |
999 return result; | 1008 return result; |
1000 } | 1009 } |
1001 | 1010 |
1002 if (dispatcher->GetType() != Dispatcher::Type::SHARED_BUFFER) { | 1011 if (dispatcher->GetType() != Dispatcher::Type::SHARED_BUFFER) { |
1003 dispatcher->Close(); | 1012 dispatcher->Close(); |
1004 return MOJO_RESULT_INVALID_ARGUMENT; | 1013 return MOJO_RESULT_INVALID_ARGUMENT; |
1005 } | 1014 } |
1006 | 1015 |
1007 SharedBufferDispatcher* shm_dispatcher = | 1016 SharedBufferDispatcher* shm_dispatcher = |
1008 static_cast<SharedBufferDispatcher*>(dispatcher.get()); | 1017 static_cast<SharedBufferDispatcher*>(dispatcher.get()); |
1009 scoped_refptr<PlatformSharedBuffer> platform_shared_buffer = | 1018 scoped_refptr<PlatformSharedBuffer> platform_shared_buffer = |
1010 shm_dispatcher->PassPlatformSharedBuffer(); | 1019 shm_dispatcher->PassPlatformSharedBuffer(); |
1011 DCHECK(platform_shared_buffer); | 1020 DCHECK(platform_shared_buffer); |
1012 | 1021 |
1013 DCHECK(size); | 1022 DCHECK(size); |
1014 *size = platform_shared_buffer->GetNumBytes(); | 1023 *size = platform_shared_buffer->GetNumBytes(); |
1015 | 1024 |
1016 DCHECK(flags); | 1025 DCHECK(flags); |
1017 *flags = MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE; | 1026 *flags = MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE; |
1018 if (platform_shared_buffer->IsReadOnly()) | 1027 if (platform_shared_buffer->IsReadOnly()) |
1019 *flags |= MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY; | 1028 *flags |= MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY; |
1020 | 1029 |
1021 ScopedPlatformHandle handle = platform_shared_buffer->PassPlatformHandle(); | 1030 ScopedPlatformHandle handle = platform_shared_buffer->PassPlatformHandle(); |
1022 return ScopedPlatformHandleToMojoPlatformHandle(std::move(handle), | 1031 return ScopedPlatformHandleToMojoPlatformHandle(std::move(handle), |
1023 platform_handle); | 1032 platform_handle); |
1024 } | 1033 } |
1025 | 1034 |
1026 void Core::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { | 1035 void Core::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { |
1027 base::AutoLock lock(handles_.GetLock()); | 1036 base::AutoLock lock(handles_->GetLock()); |
1028 handles_.GetActiveHandlesForTest(handles); | 1037 handles_->GetActiveHandlesForTest(handles); |
1029 } | 1038 } |
1030 | 1039 |
1031 // static | 1040 // static |
1032 void Core::PassNodeControllerToIOThread( | 1041 void Core::PassNodeControllerToIOThread( |
1033 std::unique_ptr<NodeController> node_controller) { | 1042 std::unique_ptr<NodeController> node_controller) { |
1034 // It's OK to leak this reference. At this point we know the IO loop is still | 1043 // It's OK to leak this reference. At this point we know the IO loop is still |
1035 // running, and we know the NodeController will observe its eventual | 1044 // running, and we know the NodeController will observe its eventual |
1036 // destruction. This tells the NodeController to delete itself when that | 1045 // destruction. This tells the NodeController to delete itself when that |
1037 // happens. | 1046 // happens. |
1038 node_controller.release()->DestroyOnIOThreadShutdown(); | 1047 node_controller.release()->DestroyOnIOThreadShutdown(); |
1039 } | 1048 } |
1040 | 1049 |
1041 } // namespace edk | 1050 } // namespace edk |
1042 } // namespace mojo | 1051 } // namespace mojo |
OLD | NEW |