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 #include "mojo/edk/system/message_pipe_dispatcher.h" | 5 #include "mojo/edk/system/message_pipe_dispatcher.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/edk/system/configuration.h" | 10 #include "mojo/edk/system/configuration.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 message_pipe_ = std::move(message_pipe); | 63 message_pipe_ = std::move(message_pipe); |
64 port_ = port; | 64 port_ = port; |
65 } | 65 } |
66 | 66 |
67 Dispatcher::Type MessagePipeDispatcher::GetType() const { | 67 Dispatcher::Type MessagePipeDispatcher::GetType() const { |
68 return Type::MESSAGE_PIPE; | 68 return Type::MESSAGE_PIPE; |
69 } | 69 } |
70 | 70 |
71 // static | 71 // static |
72 scoped_refptr<MessagePipeDispatcher> | 72 RefPtr<MessagePipeDispatcher> MessagePipeDispatcher::CreateRemoteMessagePipe( |
73 MessagePipeDispatcher::CreateRemoteMessagePipe( | |
74 RefPtr<ChannelEndpoint>* channel_endpoint) { | 73 RefPtr<ChannelEndpoint>* channel_endpoint) { |
75 auto message_pipe = MessagePipe::CreateLocalProxy(channel_endpoint); | 74 auto message_pipe = MessagePipe::CreateLocalProxy(channel_endpoint); |
76 scoped_refptr<MessagePipeDispatcher> dispatcher = | 75 auto dispatcher = MessagePipeDispatcher::Create(kDefaultCreateOptions); |
77 Create(kDefaultCreateOptions); | |
78 dispatcher->Init(std::move(message_pipe), 0); | 76 dispatcher->Init(std::move(message_pipe), 0); |
79 return dispatcher; | 77 return dispatcher; |
80 } | 78 } |
81 | 79 |
82 // static | 80 // static |
83 scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize( | 81 RefPtr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize( |
84 Channel* channel, | 82 Channel* channel, |
85 const void* source, | 83 const void* source, |
86 size_t size) { | 84 size_t size) { |
87 unsigned port = kInvalidPort; | 85 unsigned port = kInvalidPort; |
88 RefPtr<MessagePipe> message_pipe; | 86 RefPtr<MessagePipe> message_pipe; |
89 if (!MessagePipe::Deserialize(channel, source, size, &message_pipe, &port)) | 87 if (!MessagePipe::Deserialize(channel, source, size, &message_pipe, &port)) |
90 return nullptr; | 88 return nullptr; |
91 DCHECK(message_pipe); | 89 DCHECK(message_pipe); |
92 DCHECK(port == 0 || port == 1); | 90 DCHECK(port == 0 || port == 1); |
93 | 91 |
94 scoped_refptr<MessagePipeDispatcher> dispatcher = | 92 auto dispatcher = MessagePipeDispatcher::Create(kDefaultCreateOptions); |
95 Create(kDefaultCreateOptions); | |
96 dispatcher->Init(std::move(message_pipe), port); | 93 dispatcher->Init(std::move(message_pipe), port); |
97 return dispatcher; | 94 return dispatcher; |
98 } | 95 } |
99 | 96 |
100 MessagePipeDispatcher::MessagePipeDispatcher() : port_(kInvalidPort) { | 97 MessagePipeDispatcher::MessagePipeDispatcher() : port_(kInvalidPort) { |
101 } | 98 } |
102 | 99 |
103 MessagePipeDispatcher::~MessagePipeDispatcher() { | 100 MessagePipeDispatcher::~MessagePipeDispatcher() { |
104 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. | 101 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. |
105 DCHECK(!message_pipe_); | 102 DCHECK(!message_pipe_); |
(...skipping 14 matching lines...) Expand all Loading... |
120 message_pipe_->CancelAllAwakables(port_); | 117 message_pipe_->CancelAllAwakables(port_); |
121 } | 118 } |
122 | 119 |
123 void MessagePipeDispatcher::CloseImplNoLock() { | 120 void MessagePipeDispatcher::CloseImplNoLock() { |
124 mutex().AssertHeld(); | 121 mutex().AssertHeld(); |
125 message_pipe_->Close(port_); | 122 message_pipe_->Close(port_); |
126 message_pipe_ = nullptr; | 123 message_pipe_ = nullptr; |
127 port_ = kInvalidPort; | 124 port_ = kInvalidPort; |
128 } | 125 } |
129 | 126 |
130 scoped_refptr<Dispatcher> | 127 RefPtr<Dispatcher> |
131 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 128 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
132 mutex().AssertHeld(); | 129 mutex().AssertHeld(); |
133 | 130 |
134 // TODO(vtl): Currently, there are no options, so we just use | 131 // TODO(vtl): Currently, there are no options, so we just use |
135 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options | 132 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options |
136 // too. | 133 // too. |
137 scoped_refptr<MessagePipeDispatcher> rv = Create(kDefaultCreateOptions); | 134 auto dispatcher = MessagePipeDispatcher::Create(kDefaultCreateOptions); |
138 rv->Init(std::move(message_pipe_), port_); | 135 dispatcher->Init(std::move(message_pipe_), port_); |
139 port_ = kInvalidPort; | 136 port_ = kInvalidPort; |
140 return scoped_refptr<Dispatcher>(rv.get()); | 137 return dispatcher; |
141 } | 138 } |
142 | 139 |
143 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( | 140 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( |
144 UserPointer<const void> bytes, | 141 UserPointer<const void> bytes, |
145 uint32_t num_bytes, | 142 uint32_t num_bytes, |
146 std::vector<DispatcherTransport>* transports, | 143 std::vector<DispatcherTransport>* transports, |
147 MojoWriteMessageFlags flags) { | 144 MojoWriteMessageFlags flags) { |
148 DCHECK(!transports || | 145 DCHECK(!transports || |
149 (transports->size() > 0 && | 146 (transports->size() > 0 && |
150 transports->size() <= GetConfiguration().max_message_num_handles)); | 147 transports->size() <= GetConfiguration().max_message_num_handles)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 Awakable* awakable, | 186 Awakable* awakable, |
190 HandleSignalsState* signals_state) { | 187 HandleSignalsState* signals_state) { |
191 mutex().AssertHeld(); | 188 mutex().AssertHeld(); |
192 message_pipe_->RemoveAwakable(port_, awakable, signals_state); | 189 message_pipe_->RemoveAwakable(port_, awakable, signals_state); |
193 } | 190 } |
194 | 191 |
195 void MessagePipeDispatcher::StartSerializeImplNoLock( | 192 void MessagePipeDispatcher::StartSerializeImplNoLock( |
196 Channel* channel, | 193 Channel* channel, |
197 size_t* max_size, | 194 size_t* max_size, |
198 size_t* max_platform_handles) { | 195 size_t* max_platform_handles) { |
199 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 196 AssertHasOneRef(); // Only one ref => no need to take the lock. |
200 return message_pipe_->StartSerialize(port_, channel, max_size, | 197 return message_pipe_->StartSerialize(port_, channel, max_size, |
201 max_platform_handles); | 198 max_platform_handles); |
202 } | 199 } |
203 | 200 |
204 bool MessagePipeDispatcher::EndSerializeAndCloseImplNoLock( | 201 bool MessagePipeDispatcher::EndSerializeAndCloseImplNoLock( |
205 Channel* channel, | 202 Channel* channel, |
206 void* destination, | 203 void* destination, |
207 size_t* actual_size, | 204 size_t* actual_size, |
208 embedder::PlatformHandleVector* platform_handles) { | 205 embedder::PlatformHandleVector* platform_handles) { |
209 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 206 AssertHasOneRef(); // Only one ref => no need to take the lock. |
210 | 207 |
211 bool rv = message_pipe_->EndSerialize(port_, channel, destination, | 208 bool rv = message_pipe_->EndSerialize(port_, channel, destination, |
212 actual_size, platform_handles); | 209 actual_size, platform_handles); |
213 message_pipe_ = nullptr; | 210 message_pipe_ = nullptr; |
214 port_ = kInvalidPort; | 211 port_ = kInvalidPort; |
215 return rv; | 212 return rv; |
216 } | 213 } |
217 | 214 |
218 // MessagePipeDispatcherTransport ---------------------------------------------- | 215 // MessagePipeDispatcherTransport ---------------------------------------------- |
219 | 216 |
220 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( | 217 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( |
221 DispatcherTransport transport) | 218 DispatcherTransport transport) |
222 : DispatcherTransport(transport) { | 219 : DispatcherTransport(transport) { |
223 DCHECK_EQ(message_pipe_dispatcher()->GetType(), | 220 DCHECK_EQ(message_pipe_dispatcher()->GetType(), |
224 Dispatcher::Type::MESSAGE_PIPE); | 221 Dispatcher::Type::MESSAGE_PIPE); |
225 } | 222 } |
226 | 223 |
227 } // namespace system | 224 } // namespace system |
228 } // namespace mojo | 225 } // namespace mojo |
OLD | NEW |