| 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 passed in a message pipe (note this is only *during* the "write message" |
| 21 // call). (I.e., this is a wrapper around a |Dispatcher*| and a | 21 // 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 // | 27 class HandleTransport final { |
| 28 // TODO(vtl): Rename this class to HandleTransport. | |
| 29 class DispatcherTransport final { | |
| 30 public: | 28 public: |
| 31 DispatcherTransport() | 29 HandleTransport() : dispatcher_(nullptr), rights_(MOJO_HANDLE_RIGHT_NONE) {} |
| 32 : dispatcher_(nullptr), rights_(MOJO_HANDLE_RIGHT_NONE) {} | |
| 33 | 30 |
| 34 void End() MOJO_NOT_THREAD_SAFE; | 31 void End() MOJO_NOT_THREAD_SAFE; |
| 35 | 32 |
| 36 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } | 33 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } |
| 37 bool IsBusy() const MOJO_NOT_THREAD_SAFE { | 34 bool IsBusy() const MOJO_NOT_THREAD_SAFE { |
| 38 return dispatcher_->IsBusyNoLock(); | 35 return dispatcher_->IsBusyNoLock(); |
| 39 } | 36 } |
| 40 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } | 37 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } |
| 41 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndClose( | 38 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndClose( |
| 42 MessagePipe* message_pipe, | 39 MessagePipe* message_pipe, |
| 43 unsigned port) MOJO_NOT_THREAD_SAFE { | 40 unsigned port) MOJO_NOT_THREAD_SAFE { |
| 44 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(message_pipe, | 41 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(message_pipe, |
| 45 port); | 42 port); |
| 46 } | 43 } |
| 47 | 44 |
| 48 bool is_valid() const { return !!dispatcher_; } | 45 bool is_valid() const { return !!dispatcher_; } |
| 49 | 46 |
| 50 private: | 47 private: |
| 51 friend class Dispatcher::HandleTableAccess; | 48 friend class Dispatcher::HandleTableAccess; |
| 52 | 49 |
| 53 explicit DispatcherTransport(const Handle& handle) | 50 explicit HandleTransport(const Handle& handle) |
| 54 : dispatcher_(handle.dispatcher.get()), rights_(handle.rights) {} | 51 : dispatcher_(handle.dispatcher.get()), rights_(handle.rights) {} |
| 55 | 52 |
| 56 Dispatcher* dispatcher_; | 53 Dispatcher* dispatcher_; |
| 57 MojoHandleRights rights_; | 54 MojoHandleRights rights_; |
| 58 | 55 |
| 59 // Copy and assign allowed. | 56 // Copy and assign allowed. |
| 60 }; | 57 }; |
| 61 | 58 |
| 62 } // namespace system | 59 } // namespace system |
| 63 } // namespace mojo | 60 } // namespace mojo |
| 64 | 61 |
| 65 #endif // MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ | 62 #endif // MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ |
| OLD | NEW |