| 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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "mojo/edk/system/dispatcher.h" | 10 #include "mojo/edk/system/dispatcher.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // |MojoCreateMessagePipeOptions| and will be entirely overwritten on success | 36 // |MojoCreateMessagePipeOptions| and will be entirely overwritten on success |
| 37 // (it may be partly overwritten on failure). | 37 // (it may be partly overwritten on failure). |
| 38 static MojoResult ValidateCreateOptions( | 38 static MojoResult ValidateCreateOptions( |
| 39 UserPointer<const MojoCreateMessagePipeOptions> in_options, | 39 UserPointer<const MojoCreateMessagePipeOptions> in_options, |
| 40 MojoCreateMessagePipeOptions* out_options); | 40 MojoCreateMessagePipeOptions* out_options); |
| 41 | 41 |
| 42 // Must be called before any other methods. (This method is not thread-safe.) | 42 // Must be called before any other methods. (This method is not thread-safe.) |
| 43 void Init(scoped_refptr<MessagePipe> message_pipe, unsigned port); | 43 void Init(scoped_refptr<MessagePipe> message_pipe, unsigned port); |
| 44 | 44 |
| 45 // |Dispatcher| public methods: | 45 // |Dispatcher| public methods: |
| 46 virtual Type GetType() const override; | 46 Type GetType() const override; |
| 47 | 47 |
| 48 // Creates a |MessagePipe| with a local endpoint (at port 0) and a proxy | 48 // Creates a |MessagePipe| with a local endpoint (at port 0) and a proxy |
| 49 // endpoint, and creates/initializes a |MessagePipeDispatcher| (attached to | 49 // endpoint, and creates/initializes a |MessagePipeDispatcher| (attached to |
| 50 // the message pipe, port 0). | 50 // the message pipe, port 0). |
| 51 // TODO(vtl): This currently uses |kDefaultCreateOptions|, which is okay since | 51 // TODO(vtl): This currently uses |kDefaultCreateOptions|, which is okay since |
| 52 // there aren't any options, but eventually options should be plumbed through. | 52 // there aren't any options, but eventually options should be plumbed through. |
| 53 static scoped_refptr<MessagePipeDispatcher> CreateRemoteMessagePipe( | 53 static scoped_refptr<MessagePipeDispatcher> CreateRemoteMessagePipe( |
| 54 scoped_refptr<ChannelEndpoint>* channel_endpoint); | 54 scoped_refptr<ChannelEndpoint>* channel_endpoint); |
| 55 | 55 |
| 56 // The "opposite" of |SerializeAndClose()|. (Typically this is called by | 56 // The "opposite" of |SerializeAndClose()|. (Typically this is called by |
| 57 // |Dispatcher::Deserialize()|.) | 57 // |Dispatcher::Deserialize()|.) |
| 58 static scoped_refptr<MessagePipeDispatcher> Deserialize(Channel* channel, | 58 static scoped_refptr<MessagePipeDispatcher> Deserialize(Channel* channel, |
| 59 const void* source, | 59 const void* source, |
| 60 size_t size); | 60 size_t size); |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 friend class MessagePipeDispatcherTransport; | 63 friend class MessagePipeDispatcherTransport; |
| 64 | 64 |
| 65 virtual ~MessagePipeDispatcher(); | 65 ~MessagePipeDispatcher() override; |
| 66 | 66 |
| 67 // Gets a dumb pointer to |message_pipe_|. This must be called under the | 67 // Gets a dumb pointer to |message_pipe_|. This must be called under the |
| 68 // |Dispatcher| lock (that it's a dumb pointer is okay since it's under lock). | 68 // |Dispatcher| lock (that it's a dumb pointer is okay since it's under lock). |
| 69 // This is needed when sending handles across processes, where nontrivial, | 69 // This is needed when sending handles across processes, where nontrivial, |
| 70 // invasive work needs to be done. | 70 // invasive work needs to be done. |
| 71 MessagePipe* GetMessagePipeNoLock() const; | 71 MessagePipe* GetMessagePipeNoLock() const; |
| 72 // Similarly for the port. | 72 // Similarly for the port. |
| 73 unsigned GetPortNoLock() const; | 73 unsigned GetPortNoLock() const; |
| 74 | 74 |
| 75 // |Dispatcher| protected methods: | 75 // |Dispatcher| protected methods: |
| 76 virtual void CancelAllWaitersNoLock() override; | 76 void CancelAllWaitersNoLock() override; |
| 77 virtual void CloseImplNoLock() override; | 77 void CloseImplNoLock() override; |
| 78 virtual scoped_refptr<Dispatcher> | 78 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() |
| 79 CreateEquivalentDispatcherAndCloseImplNoLock() override; | 79 override; |
| 80 virtual MojoResult WriteMessageImplNoLock( | 80 MojoResult WriteMessageImplNoLock( |
| 81 UserPointer<const void> bytes, | 81 UserPointer<const void> bytes, |
| 82 uint32_t num_bytes, | 82 uint32_t num_bytes, |
| 83 std::vector<DispatcherTransport>* transports, | 83 std::vector<DispatcherTransport>* transports, |
| 84 MojoWriteMessageFlags flags) override; | 84 MojoWriteMessageFlags flags) override; |
| 85 virtual MojoResult ReadMessageImplNoLock(UserPointer<void> bytes, | 85 MojoResult ReadMessageImplNoLock(UserPointer<void> bytes, |
| 86 UserPointer<uint32_t> num_bytes, | 86 UserPointer<uint32_t> num_bytes, |
| 87 DispatcherVector* dispatchers, | 87 DispatcherVector* dispatchers, |
| 88 uint32_t* num_dispatchers, | 88 uint32_t* num_dispatchers, |
| 89 MojoReadMessageFlags flags) override; | 89 MojoReadMessageFlags flags) override; |
| 90 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const override; | 90 HandleSignalsState GetHandleSignalsStateImplNoLock() const override; |
| 91 virtual MojoResult AddWaiterImplNoLock( | 91 MojoResult AddWaiterImplNoLock(Waiter* waiter, |
| 92 Waiter* waiter, | 92 MojoHandleSignals signals, |
| 93 MojoHandleSignals signals, | 93 uint32_t context, |
| 94 uint32_t context, | 94 HandleSignalsState* signals_state) override; |
| 95 HandleSignalsState* signals_state) override; | 95 void RemoveWaiterImplNoLock(Waiter* waiter, |
| 96 virtual void RemoveWaiterImplNoLock( | 96 HandleSignalsState* signals_state) override; |
| 97 Waiter* waiter, | 97 void StartSerializeImplNoLock(Channel* channel, |
| 98 HandleSignalsState* signals_state) override; | 98 size_t* max_size, |
| 99 virtual void StartSerializeImplNoLock(Channel* channel, | 99 size_t* max_platform_handles) override; |
| 100 size_t* max_size, | 100 bool EndSerializeAndCloseImplNoLock( |
| 101 size_t* max_platform_handles) override; | |
| 102 virtual bool EndSerializeAndCloseImplNoLock( | |
| 103 Channel* channel, | 101 Channel* channel, |
| 104 void* destination, | 102 void* destination, |
| 105 size_t* actual_size, | 103 size_t* actual_size, |
| 106 embedder::PlatformHandleVector* platform_handles) override; | 104 embedder::PlatformHandleVector* platform_handles) override; |
| 107 | 105 |
| 108 // Protected by |lock()|: | 106 // Protected by |lock()|: |
| 109 scoped_refptr<MessagePipe> message_pipe_; // This will be null if closed. | 107 scoped_refptr<MessagePipe> message_pipe_; // This will be null if closed. |
| 110 unsigned port_; | 108 unsigned port_; |
| 111 | 109 |
| 112 DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); | 110 DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 126 return static_cast<MessagePipeDispatcher*>(dispatcher()); | 124 return static_cast<MessagePipeDispatcher*>(dispatcher()); |
| 127 } | 125 } |
| 128 | 126 |
| 129 // Copy and assign allowed. | 127 // Copy and assign allowed. |
| 130 }; | 128 }; |
| 131 | 129 |
| 132 } // namespace system | 130 } // namespace system |
| 133 } // namespace mojo | 131 } // namespace mojo |
| 134 | 132 |
| 135 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 133 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
| OLD | NEW |