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/system/message_pipe_dispatcher.h" | 5 #include "mojo/system/message_pipe_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/system/constants.h" | 8 #include "mojo/system/constants.h" |
9 #include "mojo/system/memory.h" | 9 #include "mojo/system/memory.h" |
10 #include "mojo/system/message_pipe.h" | 10 #include "mojo/system/message_pipe.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 namespace system { | 13 namespace system { |
14 | 14 |
15 const unsigned kInvalidPort = static_cast<unsigned>(-1); | 15 const unsigned kInvalidPort = static_cast<unsigned>(-1); |
16 | 16 |
17 MessagePipeDispatcher::MessagePipeDispatcher() | 17 MessagePipeDispatcher::MessagePipeDispatcher() |
18 : port_(kInvalidPort) { | 18 : port_(kInvalidPort) { |
19 } | 19 } |
20 | 20 |
21 void MessagePipeDispatcher::Init(scoped_refptr<MessagePipe> message_pipe, | 21 void MessagePipeDispatcher::Init(scoped_refptr<MessagePipe> message_pipe, |
22 unsigned port) { | 22 unsigned port) { |
23 DCHECK(message_pipe.get()); | 23 DCHECK(message_pipe.get()); |
24 DCHECK(port == 0 || port == 1); | 24 DCHECK(port == 0 || port == 1); |
25 | 25 |
26 message_pipe_ = message_pipe; | 26 message_pipe_ = message_pipe; |
27 port_ = port; | 27 port_ = port; |
28 } | 28 } |
29 | 29 |
| 30 MessagePipe* MessagePipeDispatcher::GetMessagePipeNoLock() const { |
| 31 lock().AssertAcquired(); |
| 32 return message_pipe_.get(); |
| 33 } |
| 34 |
| 35 unsigned MessagePipeDispatcher::GetPortNoLock() const { |
| 36 lock().AssertAcquired(); |
| 37 return port_; |
| 38 } |
| 39 |
30 Dispatcher::Type MessagePipeDispatcher::GetType() { | 40 Dispatcher::Type MessagePipeDispatcher::GetType() { |
31 return kTypeMessagePipe; | 41 return kTypeMessagePipe; |
32 } | 42 } |
33 | 43 |
34 MessagePipeDispatcher::~MessagePipeDispatcher() { | 44 MessagePipeDispatcher::~MessagePipeDispatcher() { |
35 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. | 45 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. |
36 DCHECK(!message_pipe_.get()); | 46 DCHECK(!message_pipe_.get()); |
37 } | 47 } |
38 | 48 |
39 void MessagePipeDispatcher::CancelAllWaitersNoLock() { | 49 void MessagePipeDispatcher::CancelAllWaitersNoLock() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 117 |
108 scoped_refptr<MessagePipeDispatcher> rv = new MessagePipeDispatcher(); | 118 scoped_refptr<MessagePipeDispatcher> rv = new MessagePipeDispatcher(); |
109 rv->Init(message_pipe_, port_); | 119 rv->Init(message_pipe_, port_); |
110 message_pipe_ = NULL; | 120 message_pipe_ = NULL; |
111 port_ = kInvalidPort; | 121 port_ = kInvalidPort; |
112 return scoped_refptr<Dispatcher>(rv.get()); | 122 return scoped_refptr<Dispatcher>(rv.get()); |
113 } | 123 } |
114 | 124 |
115 } // namespace system | 125 } // namespace system |
116 } // namespace mojo | 126 } // namespace mojo |
OLD | NEW |