| 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 #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
| 6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include "mojo/edk/system/dispatcher.h" | 8 #include "mojo/edk/system/dispatcher.h" |
| 9 #include "mojo/edk/system/memory.h" | 9 #include "mojo/edk/system/memory.h" |
| 10 #include "mojo/edk/util/ref_ptr.h" | 10 #include "mojo/edk/util/ref_ptr.h" |
| 11 #include "mojo/edk/util/thread_annotations.h" | 11 #include "mojo/edk/util/thread_annotations.h" |
| 12 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace system { | 15 namespace system { |
| 16 | 16 |
| 17 class ChannelEndpoint; | 17 class ChannelEndpoint; |
| 18 class MessagePipe; | 18 class MessagePipe; |
| 19 class MessagePipeDispatcherTransport; | |
| 20 | 19 |
| 21 // This is the |Dispatcher| implementation for message pipes (created by the | 20 // This is the |Dispatcher| implementation for message pipes (created by the |
| 22 // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe. | 21 // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe. |
| 23 class MessagePipeDispatcher final : public Dispatcher { | 22 class MessagePipeDispatcher final : public Dispatcher { |
| 24 public: | 23 public: |
| 25 // The default options to use for |MojoCreateMessagePipe()|. (Real uses | 24 // The default options to use for |MojoCreateMessagePipe()|. (Real uses |
| 26 // should obtain this via |ValidateCreateOptions()| with a null |in_options|; | 25 // should obtain this via |ValidateCreateOptions()| with a null |in_options|; |
| 27 // this is exposed directly for testing convenience.) | 26 // this is exposed directly for testing convenience.) |
| 28 static const MojoCreateMessagePipeOptions kDefaultCreateOptions; | 27 static const MojoCreateMessagePipeOptions kDefaultCreateOptions; |
| 29 | 28 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 57 static util::RefPtr<MessagePipeDispatcher> CreateRemoteMessagePipe( | 56 static util::RefPtr<MessagePipeDispatcher> CreateRemoteMessagePipe( |
| 58 util::RefPtr<ChannelEndpoint>* channel_endpoint); | 57 util::RefPtr<ChannelEndpoint>* channel_endpoint); |
| 59 | 58 |
| 60 // The "opposite" of |SerializeAndClose()|. (Typically this is called by | 59 // The "opposite" of |SerializeAndClose()|. (Typically this is called by |
| 61 // |Dispatcher::Deserialize()|.) | 60 // |Dispatcher::Deserialize()|.) |
| 62 static util::RefPtr<MessagePipeDispatcher> Deserialize(Channel* channel, | 61 static util::RefPtr<MessagePipeDispatcher> Deserialize(Channel* channel, |
| 63 const void* source, | 62 const void* source, |
| 64 size_t size); | 63 size_t size); |
| 65 | 64 |
| 66 private: | 65 private: |
| 67 friend class MessagePipeDispatcherTransport; | |
| 68 | |
| 69 MessagePipeDispatcher(); | 66 MessagePipeDispatcher(); |
| 70 ~MessagePipeDispatcher() override; | 67 ~MessagePipeDispatcher() override; |
| 71 | 68 |
| 72 // Gets a dumb pointer to |message_pipe_|. This must be called under the | 69 // Gets a dumb pointer to |message_pipe_|. This must be called under the |
| 73 // |Dispatcher| lock (that it's a dumb pointer is okay since it's under lock). | 70 // |Dispatcher| lock (that it's a dumb pointer is okay since it's under lock). |
| 74 // This is needed when sending handles across processes, where nontrivial, | 71 // This is needed when sending handles across processes, where nontrivial, |
| 75 // invasive work needs to be done. | 72 // invasive work needs to be done. |
| 76 MessagePipe* GetMessagePipeNoLock() const; | 73 MessagePipe* GetMessagePipeNoLock() const; |
| 77 // Similarly for the port. | 74 // Similarly for the port. |
| 78 unsigned GetPortNoLock() const; | 75 unsigned GetPortNoLock() const; |
| 79 | 76 |
| 80 // |Dispatcher| protected methods: | 77 // |Dispatcher| protected methods: |
| 81 void CancelAllAwakablesNoLock() override; | 78 void CancelAllAwakablesNoLock() override; |
| 82 void CloseImplNoLock() override; | 79 void CloseImplNoLock() override; |
| 83 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | 80 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock( |
| 84 override; | 81 MessagePipe* message_pipe, |
| 82 unsigned port) override; |
| 85 MojoResult WriteMessageImplNoLock( | 83 MojoResult WriteMessageImplNoLock( |
| 86 UserPointer<const void> bytes, | 84 UserPointer<const void> bytes, |
| 87 uint32_t num_bytes, | 85 uint32_t num_bytes, |
| 88 std::vector<DispatcherTransport>* transports, | 86 std::vector<DispatcherTransport>* transports, |
| 89 MojoWriteMessageFlags flags) override; | 87 MojoWriteMessageFlags flags) override; |
| 90 MojoResult ReadMessageImplNoLock(UserPointer<void> bytes, | 88 MojoResult ReadMessageImplNoLock(UserPointer<void> bytes, |
| 91 UserPointer<uint32_t> num_bytes, | 89 UserPointer<uint32_t> num_bytes, |
| 92 DispatcherVector* dispatchers, | 90 DispatcherVector* dispatchers, |
| 93 uint32_t* num_dispatchers, | 91 uint32_t* num_dispatchers, |
| 94 MojoReadMessageFlags flags) override; | 92 MojoReadMessageFlags flags) override; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 110 std::vector<platform::ScopedPlatformHandle>* platform_handles) override | 108 std::vector<platform::ScopedPlatformHandle>* platform_handles) override |
| 111 MOJO_NOT_THREAD_SAFE; | 109 MOJO_NOT_THREAD_SAFE; |
| 112 | 110 |
| 113 // This will be null if closed. | 111 // This will be null if closed. |
| 114 util::RefPtr<MessagePipe> message_pipe_ MOJO_GUARDED_BY(mutex()); | 112 util::RefPtr<MessagePipe> message_pipe_ MOJO_GUARDED_BY(mutex()); |
| 115 unsigned port_ MOJO_GUARDED_BY(mutex()); | 113 unsigned port_ MOJO_GUARDED_BY(mutex()); |
| 116 | 114 |
| 117 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); | 115 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); |
| 118 }; | 116 }; |
| 119 | 117 |
| 120 class MessagePipeDispatcherTransport : public DispatcherTransport { | |
| 121 public: | |
| 122 explicit MessagePipeDispatcherTransport(DispatcherTransport transport); | |
| 123 | |
| 124 MessagePipe* GetMessagePipe() { | |
| 125 return message_pipe_dispatcher()->GetMessagePipeNoLock(); | |
| 126 } | |
| 127 unsigned GetPort() { return message_pipe_dispatcher()->GetPortNoLock(); } | |
| 128 | |
| 129 private: | |
| 130 MessagePipeDispatcher* message_pipe_dispatcher() { | |
| 131 return static_cast<MessagePipeDispatcher*>(dispatcher()); | |
| 132 } | |
| 133 | |
| 134 // Copy and assign allowed. | |
| 135 }; | |
| 136 | |
| 137 } // namespace system | 118 } // namespace system |
| 138 } // namespace mojo | 119 } // namespace mojo |
| 139 | 120 |
| 140 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 121 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
| OLD | NEW |