| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_HANDLE_TRANSPORT_H_ | 5 #ifndef MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ |
| 6 #define MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ | 6 #define MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ |
| 7 | 7 |
| 8 #include "mojo/edk/system/dispatcher.h" | 8 #include "mojo/edk/system/dispatcher.h" |
| 9 #include "mojo/edk/system/handle.h" | 9 #include "mojo/edk/system/handle.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/c/system/handle.h" | 12 #include "mojo/public/c/system/handle.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace system { | 15 namespace system { |
| 16 | 16 |
| 17 class MessagePipe; | 17 class MessagePipe; |
| 18 | 18 |
| 19 // Like |Handle|, but non-owning, for use while a handle is being processed to | 19 // Like |Handle|, but non-owning, for use while a handle is being processed to |
| 20 // be passed in a message pipe (note this is only *during* the "write message" | 20 // be replaced or to be passed in a message pipe (note this is only *during* the |
| 21 // call). (I.e., this is a wrapper around a |Dispatcher*| and a | 21 // "write message" call). (I.e., this is a wrapper around a |Dispatcher*| and a |
| 22 // |MojoHandleRights|.) See the comment about |Dispatcher::HandleTableAccess| | 22 // |MojoHandleRights|.) See the comment about |Dispatcher::HandleTableAccess| |
| 23 // for more details. | 23 // for more details. |
| 24 // | 24 // |
| 25 // Note: This class is deliberately "thin" -- no more expensive than a struct | 25 // Note: This class is deliberately "thin" -- no more expensive than a struct |
| 26 // containing a |Dispatcher*| and a |MojoHandleRights|. | 26 // containing a |Dispatcher*| and a |MojoHandleRights|. |
| 27 class HandleTransport final { | 27 class HandleTransport final { |
| 28 public: | 28 public: |
| 29 // Constructs a "null"/invalid |HandleTransport|. No methods other than |
| 30 // |is_valid()| may be called on the resulting instance. |
| 29 HandleTransport() : dispatcher_(nullptr), rights_(MOJO_HANDLE_RIGHT_NONE) {} | 31 HandleTransport() : dispatcher_(nullptr), rights_(MOJO_HANDLE_RIGHT_NONE) {} |
| 30 | 32 |
| 33 // Ends transport. This must be called exactly once (on the result, or one of |
| 34 // the copies thereof) if |Dispatcher::HandleTableAccess::TryStartTransport()| |
| 35 // succeeds. |
| 31 void End() MOJO_NOT_THREAD_SAFE; | 36 void End() MOJO_NOT_THREAD_SAFE; |
| 32 | 37 |
| 33 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } | 38 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } |
| 34 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } | 39 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } |
| 40 // Creates an equivalent handle and closes the original one. If this is done |
| 41 // while being sent on a message pipe (i.e., under a |MessagePipe| mutex), |
| 42 // then |message_pipe|/|port| should be set appropriately. Otherwise, |
| 43 // |message_pipe| should be null (and |port| will be ignored). |
| 35 Handle CreateEquivalentHandleAndClose(MessagePipe* message_pipe, | 44 Handle CreateEquivalentHandleAndClose(MessagePipe* message_pipe, |
| 36 unsigned port) MOJO_NOT_THREAD_SAFE { | 45 unsigned port) MOJO_NOT_THREAD_SAFE { |
| 37 return Handle(dispatcher_->CreateEquivalentDispatcherAndCloseNoLock( | 46 return Handle(dispatcher_->CreateEquivalentDispatcherAndCloseNoLock( |
| 38 message_pipe, port), | 47 message_pipe, port), |
| 39 rights_); | 48 rights_); |
| 40 } | 49 } |
| 41 | 50 |
| 42 bool is_valid() const { return !!dispatcher_; } | 51 bool is_valid() const { return !!dispatcher_; } |
| 43 | 52 |
| 44 private: | 53 private: |
| 45 friend class Dispatcher::HandleTableAccess; | 54 friend class Dispatcher::HandleTableAccess; |
| 46 | 55 |
| 47 explicit HandleTransport(const Handle& handle) | 56 explicit HandleTransport(const Handle& handle) |
| 48 : dispatcher_(handle.dispatcher.get()), rights_(handle.rights) {} | 57 : dispatcher_(handle.dispatcher.get()), rights_(handle.rights) {} |
| 49 | 58 |
| 50 Dispatcher* dispatcher_; | 59 Dispatcher* dispatcher_; |
| 51 MojoHandleRights rights_; | 60 MojoHandleRights rights_; |
| 52 | 61 |
| 53 // Copy and assign allowed. | 62 // Copy and assign allowed. |
| 54 }; | 63 }; |
| 55 | 64 |
| 56 } // namespace system | 65 } // namespace system |
| 57 } // namespace mojo | 66 } // namespace mojo |
| 58 | 67 |
| 59 #endif // MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ | 68 #endif // MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ |
| OLD | NEW |