| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 void MessagePipeDispatcher::CloseImplNoLock() { | 128 void MessagePipeDispatcher::CloseImplNoLock() { |
| 129 mutex().AssertHeld(); | 129 mutex().AssertHeld(); |
| 130 message_pipe_->Close(port_); | 130 message_pipe_->Close(port_); |
| 131 message_pipe_ = nullptr; | 131 message_pipe_ = nullptr; |
| 132 port_ = kInvalidPort; | 132 port_ = kInvalidPort; |
| 133 } | 133 } |
| 134 | 134 |
| 135 RefPtr<Dispatcher> | 135 RefPtr<Dispatcher> |
| 136 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 136 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock( |
| 137 MessagePipe* message_pipe, |
| 138 unsigned port) { |
| 137 mutex().AssertHeld(); | 139 mutex().AssertHeld(); |
| 138 | 140 |
| 141 // "We" are being sent over our peer. |
| 142 if (message_pipe == message_pipe_.get()) { |
| 143 // A message pipe dispatcher can't be sent over itself (this should be |
| 144 // disallowed by |Core|). Note that |port| is the destination port. |
| 145 DCHECK_EQ(port, port_); |
| 146 // In this case, |message_pipe_|'s mutex should already be held! |
| 147 message_pipe_->CancelAllAwakablesNoLock(port_); |
| 148 } else { |
| 149 CancelAllAwakablesNoLock(); |
| 150 } |
| 151 |
| 139 // TODO(vtl): Currently, there are no options, so we just use | 152 // TODO(vtl): Currently, there are no options, so we just use |
| 140 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options | 153 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options |
| 141 // too. | 154 // too. |
| 142 auto dispatcher = MessagePipeDispatcher::Create(kDefaultCreateOptions); | 155 auto dispatcher = MessagePipeDispatcher::Create(kDefaultCreateOptions); |
| 143 dispatcher->Init(std::move(message_pipe_), port_); | 156 dispatcher->Init(std::move(message_pipe_), port_); |
| 144 port_ = kInvalidPort; | 157 port_ = kInvalidPort; |
| 145 return dispatcher; | 158 return dispatcher; |
| 146 } | 159 } |
| 147 | 160 |
| 148 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( | 161 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 std::vector<ScopedPlatformHandle>* platform_handles) { | 226 std::vector<ScopedPlatformHandle>* platform_handles) { |
| 214 AssertHasOneRef(); // Only one ref => no need to take the lock. | 227 AssertHasOneRef(); // Only one ref => no need to take the lock. |
| 215 | 228 |
| 216 bool rv = message_pipe_->EndSerialize(port_, channel, destination, | 229 bool rv = message_pipe_->EndSerialize(port_, channel, destination, |
| 217 actual_size, platform_handles); | 230 actual_size, platform_handles); |
| 218 message_pipe_ = nullptr; | 231 message_pipe_ = nullptr; |
| 219 port_ = kInvalidPort; | 232 port_ = kInvalidPort; |
| 220 return rv; | 233 return rv; |
| 221 } | 234 } |
| 222 | 235 |
| 223 // MessagePipeDispatcherTransport ---------------------------------------------- | |
| 224 | |
| 225 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( | |
| 226 DispatcherTransport transport) | |
| 227 : DispatcherTransport(transport) { | |
| 228 DCHECK_EQ(message_pipe_dispatcher()->GetType(), | |
| 229 Dispatcher::Type::MESSAGE_PIPE); | |
| 230 } | |
| 231 | |
| 232 } // namespace system | 236 } // namespace system |
| 233 } // namespace mojo | 237 } // namespace mojo |
| OLD | NEW |