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/dispatcher.h" | 5 #include "mojo/edk/system/dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/edk/system/configuration.h" | 8 #include "mojo/edk/system/configuration.h" |
9 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" | 9 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" | 10 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
11 #include "mojo/edk/system/message_pipe_dispatcher.h" | 11 #include "mojo/edk/system/message_pipe_dispatcher.h" |
12 #include "mojo/edk/system/platform_handle_dispatcher.h" | 12 #include "mojo/edk/system/platform_handle_dispatcher.h" |
13 #include "mojo/edk/system/shared_buffer_dispatcher.h" | 13 #include "mojo/edk/system/shared_buffer_dispatcher.h" |
14 | 14 |
| 15 using mojo::embedder::ScopedPlatformHandle; |
15 using mojo::util::MutexLocker; | 16 using mojo::util::MutexLocker; |
16 using mojo::util::RefPtr; | 17 using mojo::util::RefPtr; |
17 | 18 |
18 namespace mojo { | 19 namespace mojo { |
19 namespace system { | 20 namespace system { |
20 | 21 |
21 namespace test { | 22 namespace test { |
22 | 23 |
23 // TODO(vtl): Maybe this should be defined in a test-only file instead. | 24 // TODO(vtl): Maybe this should be defined in a test-only file instead. |
24 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher) { | 25 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 DCHECK(dispatcher); | 57 DCHECK(dispatcher); |
57 dispatcher->StartSerialize(channel, max_size, max_platform_handles); | 58 dispatcher->StartSerialize(channel, max_size, max_platform_handles); |
58 } | 59 } |
59 | 60 |
60 // static | 61 // static |
61 bool Dispatcher::TransportDataAccess::EndSerializeAndClose( | 62 bool Dispatcher::TransportDataAccess::EndSerializeAndClose( |
62 Dispatcher* dispatcher, | 63 Dispatcher* dispatcher, |
63 Channel* channel, | 64 Channel* channel, |
64 void* destination, | 65 void* destination, |
65 size_t* actual_size, | 66 size_t* actual_size, |
66 embedder::PlatformHandleVector* platform_handles) { | 67 std::vector<ScopedPlatformHandle>* platform_handles) { |
67 DCHECK(dispatcher); | 68 DCHECK(dispatcher); |
68 return dispatcher->EndSerializeAndClose(channel, destination, actual_size, | 69 return dispatcher->EndSerializeAndClose(channel, destination, actual_size, |
69 platform_handles); | 70 platform_handles); |
70 } | 71 } |
71 | 72 |
72 // static | 73 // static |
73 RefPtr<Dispatcher> Dispatcher::TransportDataAccess::Deserialize( | 74 RefPtr<Dispatcher> Dispatcher::TransportDataAccess::Deserialize( |
74 Channel* channel, | 75 Channel* channel, |
75 int32_t type, | 76 int32_t type, |
76 const void* source, | 77 const void* source, |
77 size_t size, | 78 size_t size, |
78 embedder::PlatformHandleVector* platform_handles) { | 79 std::vector<ScopedPlatformHandle>* platform_handles) { |
79 switch (static_cast<Dispatcher::Type>(type)) { | 80 switch (static_cast<Dispatcher::Type>(type)) { |
80 case Type::UNKNOWN: | 81 case Type::UNKNOWN: |
81 DVLOG(2) << "Deserializing invalid handle"; | 82 DVLOG(2) << "Deserializing invalid handle"; |
82 return nullptr; | 83 return nullptr; |
83 case Type::MESSAGE_PIPE: | 84 case Type::MESSAGE_PIPE: |
84 return MessagePipeDispatcher::Deserialize(channel, source, size); | 85 return MessagePipeDispatcher::Deserialize(channel, source, size); |
85 case Type::DATA_PIPE_PRODUCER: | 86 case Type::DATA_PIPE_PRODUCER: |
86 return DataPipeProducerDispatcher::Deserialize(channel, source, size); | 87 return DataPipeProducerDispatcher::Deserialize(channel, source, size); |
87 case Type::DATA_PIPE_CONSUMER: | 88 case Type::DATA_PIPE_CONSUMER: |
88 return DataPipeConsumerDispatcher::Deserialize(channel, source, size); | 89 return DataPipeConsumerDispatcher::Deserialize(channel, source, size); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 AssertHasOneRef(); // Only one ref => no need to take the lock. | 406 AssertHasOneRef(); // Only one ref => no need to take the lock. |
406 DCHECK(!is_closed_); | 407 DCHECK(!is_closed_); |
407 *max_size = 0; | 408 *max_size = 0; |
408 *max_platform_handles = 0; | 409 *max_platform_handles = 0; |
409 } | 410 } |
410 | 411 |
411 bool Dispatcher::EndSerializeAndCloseImplNoLock( | 412 bool Dispatcher::EndSerializeAndCloseImplNoLock( |
412 Channel* /*channel*/, | 413 Channel* /*channel*/, |
413 void* /*destination*/, | 414 void* /*destination*/, |
414 size_t* /*actual_size*/, | 415 size_t* /*actual_size*/, |
415 embedder::PlatformHandleVector* /*platform_handles*/) { | 416 std::vector<ScopedPlatformHandle>* /*platform_handles*/) { |
416 AssertHasOneRef(); // Only one ref => no need to take the lock. | 417 AssertHasOneRef(); // Only one ref => no need to take the lock. |
417 DCHECK(is_closed_); | 418 DCHECK(is_closed_); |
418 // By default, serializing isn't supported, so just close. | 419 // By default, serializing isn't supported, so just close. |
419 CloseImplNoLock(); | 420 CloseImplNoLock(); |
420 return false; | 421 return false; |
421 } | 422 } |
422 | 423 |
423 bool Dispatcher::IsBusyNoLock() const { | 424 bool Dispatcher::IsBusyNoLock() const { |
424 mutex_.AssertHeld(); | 425 mutex_.AssertHeld(); |
425 DCHECK(!is_closed_); | 426 DCHECK(!is_closed_); |
(...skipping 28 matching lines...) Expand all Loading... |
454 DCHECK(max_platform_handles); | 455 DCHECK(max_platform_handles); |
455 AssertHasOneRef(); // Only one ref => no need to take the lock. | 456 AssertHasOneRef(); // Only one ref => no need to take the lock. |
456 DCHECK(!is_closed_); | 457 DCHECK(!is_closed_); |
457 StartSerializeImplNoLock(channel, max_size, max_platform_handles); | 458 StartSerializeImplNoLock(channel, max_size, max_platform_handles); |
458 } | 459 } |
459 | 460 |
460 bool Dispatcher::EndSerializeAndClose( | 461 bool Dispatcher::EndSerializeAndClose( |
461 Channel* channel, | 462 Channel* channel, |
462 void* destination, | 463 void* destination, |
463 size_t* actual_size, | 464 size_t* actual_size, |
464 embedder::PlatformHandleVector* platform_handles) { | 465 std::vector<ScopedPlatformHandle>* platform_handles) { |
465 DCHECK(channel); | 466 DCHECK(channel); |
466 DCHECK(actual_size); | 467 DCHECK(actual_size); |
467 AssertHasOneRef(); // Only one ref => no need to take the lock. | 468 AssertHasOneRef(); // Only one ref => no need to take the lock. |
468 DCHECK(!is_closed_); | 469 DCHECK(!is_closed_); |
469 | 470 |
470 // Like other |...Close()| methods, we mark ourselves as closed before calling | 471 // Like other |...Close()| methods, we mark ourselves as closed before calling |
471 // the impl. But there's no need to cancel waiters: we shouldn't have any (and | 472 // the impl. But there's no need to cancel waiters: we shouldn't have any (and |
472 // shouldn't be in |Core|'s handle table. | 473 // shouldn't be in |Core|'s handle table. |
473 is_closed_ = true; | 474 is_closed_ = true; |
474 | 475 |
(...skipping 11 matching lines...) Expand all Loading... |
486 // DispatcherTransport --------------------------------------------------------- | 487 // DispatcherTransport --------------------------------------------------------- |
487 | 488 |
488 void DispatcherTransport::End() { | 489 void DispatcherTransport::End() { |
489 DCHECK(dispatcher_); | 490 DCHECK(dispatcher_); |
490 dispatcher_->mutex_.Unlock(); | 491 dispatcher_->mutex_.Unlock(); |
491 dispatcher_ = nullptr; | 492 dispatcher_ = nullptr; |
492 } | 493 } |
493 | 494 |
494 } // namespace system | 495 } // namespace system |
495 } // namespace mojo | 496 } // namespace mojo |
OLD | NEW |