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/util/ref_ptr.h" | 10 #include "mojo/edk/util/ref_ptr.h" |
10 #include "mojo/edk/util/thread_annotations.h" | 11 #include "mojo/edk/util/thread_annotations.h" |
| 12 #include "mojo/public/c/system/handle.h" |
11 | 13 |
12 namespace mojo { | 14 namespace mojo { |
13 namespace system { | 15 namespace system { |
14 | 16 |
15 class MessagePipe; | 17 class MessagePipe; |
16 | 18 |
17 // Wrapper around a |Dispatcher| pointer, while it's being processed to be | 19 // Like |Handle|, but non-owning, for use while a handle is being processed to |
18 // passed in a message pipe. See the comment about | 20 // be passed in a message pipe (note this is only *during* the "write message" |
19 // |Dispatcher::HandleTableAccess| for more details. | 21 // call). (I.e., this is a wrapper around a |Dispatcher*| and a |
| 22 // |MojoHandleRights|.) See the comment about |Dispatcher::HandleTableAccess| |
| 23 // for more details. |
20 // | 24 // |
21 // Note: This class is deliberately "thin" -- no more expensive than a | 25 // Note: This class is deliberately "thin" -- no more expensive than a struct |
22 // |Dispatcher*|. | 26 // containing a |Dispatcher*| and a |MojoHandleRights|. |
23 // | 27 // |
24 // TODO(vtl): Add handle rights to this, and rename it to HandleTransport. | 28 // TODO(vtl): Rename this class to HandleTransport. |
25 class DispatcherTransport final { | 29 class DispatcherTransport final { |
26 public: | 30 public: |
27 DispatcherTransport() : dispatcher_(nullptr) {} | 31 DispatcherTransport() |
| 32 : dispatcher_(nullptr), rights_(MOJO_HANDLE_RIGHT_NONE) {} |
28 | 33 |
29 void End() MOJO_NOT_THREAD_SAFE; | 34 void End() MOJO_NOT_THREAD_SAFE; |
30 | 35 |
31 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } | 36 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } |
32 bool IsBusy() const MOJO_NOT_THREAD_SAFE { | 37 bool IsBusy() const MOJO_NOT_THREAD_SAFE { |
33 return dispatcher_->IsBusyNoLock(); | 38 return dispatcher_->IsBusyNoLock(); |
34 } | 39 } |
35 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } | 40 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } |
36 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndClose( | 41 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndClose( |
37 MessagePipe* message_pipe, | 42 MessagePipe* message_pipe, |
38 unsigned port) MOJO_NOT_THREAD_SAFE { | 43 unsigned port) MOJO_NOT_THREAD_SAFE { |
39 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(message_pipe, | 44 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(message_pipe, |
40 port); | 45 port); |
41 } | 46 } |
42 | 47 |
43 bool is_valid() const { return !!dispatcher_; } | 48 bool is_valid() const { return !!dispatcher_; } |
44 | 49 |
45 private: | 50 private: |
46 friend class Dispatcher::HandleTableAccess; | 51 friend class Dispatcher::HandleTableAccess; |
47 | 52 |
48 explicit DispatcherTransport(Dispatcher* dispatcher) | 53 explicit DispatcherTransport(const Handle& handle) |
49 : dispatcher_(dispatcher) {} | 54 : dispatcher_(handle.dispatcher.get()), rights_(handle.rights) {} |
50 | 55 |
51 Dispatcher* dispatcher_; | 56 Dispatcher* dispatcher_; |
| 57 MojoHandleRights rights_; |
52 | 58 |
53 // Copy and assign allowed. | 59 // Copy and assign allowed. |
54 }; | 60 }; |
55 | 61 |
56 } // namespace system | 62 } // namespace system |
57 } // namespace mojo | 63 } // namespace mojo |
58 | 64 |
59 #endif // MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ | 65 #endif // MOJO_EDK_SYSTEM_HANDLE_TRANSPORT_H_ |
OLD | NEW |