OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SYSTEM_CHANNEL_ENDPOINT_H_ | 5 #ifndef MOJO_SYSTEM_CHANNEL_ENDPOINT_H_ |
6 #define MOJO_SYSTEM_CHANNEL_ENDPOINT_H_ | 6 #define MOJO_SYSTEM_CHANNEL_ENDPOINT_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "mojo/system/message_in_transit.h" | 12 #include "mojo/system/message_in_transit.h" |
| 13 #include "mojo/system/message_in_transit_queue.h" |
13 #include "mojo/system/system_impl_export.h" | 14 #include "mojo/system/system_impl_export.h" |
14 | 15 |
15 namespace mojo { | 16 namespace mojo { |
16 namespace system { | 17 namespace system { |
17 | 18 |
18 class Channel; | 19 class Channel; |
19 class MessagePipe; | 20 class MessagePipe; |
20 | 21 |
21 // TODO(vtl): The plan: | 22 // TODO(vtl): The plan: |
22 // - (Done.) Move |Channel::Endpoint| to |ChannelEndpoint|. Make it | 23 // - (Done.) Move |Channel::Endpoint| to |ChannelEndpoint|. Make it |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // "remove" message from the other side (if the other side is closed | 106 // "remove" message from the other side (if the other side is closed |
106 // simultaneously, and both sides send "remove" messages). In that | 107 // simultaneously, and both sides send "remove" messages). In that |
107 // case, it must still remain alive until it receives the "remove | 108 // case, it must still remain alive until it receives the "remove |
108 // ack" (and it must ack the "remove" message that it received). | 109 // ack" (and it must ack the "remove" message that it received). |
109 class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpoint | 110 class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpoint |
110 : public base::RefCountedThreadSafe<ChannelEndpoint> { | 111 : public base::RefCountedThreadSafe<ChannelEndpoint> { |
111 public: | 112 public: |
112 // TODO(vtl): More comments.... | 113 // TODO(vtl): More comments.... |
113 ChannelEndpoint(MessagePipe* message_pipe, unsigned port); | 114 ChannelEndpoint(MessagePipe* message_pipe, unsigned port); |
114 | 115 |
| 116 // Takes messages from the given |MessageInTransitQueue|. This must be called |
| 117 // before this object is attached to a channel, and before anyone has a chance |
| 118 // to enqueue any messages. |
| 119 void TakeMessages(MessageInTransitQueue* message_queue); |
| 120 |
115 // Methods called by |MessagePipe| (via |ProxyMessagePipeEndpoint|): | 121 // Methods called by |MessagePipe| (via |ProxyMessagePipeEndpoint|): |
116 | 122 |
117 // TODO(vtl): This currently only works if we're "running". We'll move the | 123 // TODO(vtl): This currently only works if we're "running". We'll move the |
118 // "paused message queue" here (will this be needed when we have | 124 // "paused message queue" here (will this be needed when we have |
119 // locally-allocated remote IDs?). | 125 // locally-allocated remote IDs?). |
120 bool EnqueueMessage(scoped_ptr<MessageInTransit> message); | 126 bool EnqueueMessage(scoped_ptr<MessageInTransit> message); |
121 | 127 |
122 void DetachFromMessagePipe(); | 128 void DetachFromMessagePipe(); |
123 | 129 |
124 // Methods called by |Channel|: | 130 // Methods called by |Channel|: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // TODO(vtl): Move the things above under lock. | 169 // TODO(vtl): Move the things above under lock. |
164 // Protects the members below. | 170 // Protects the members below. |
165 base::Lock lock_; | 171 base::Lock lock_; |
166 | 172 |
167 // |channel_| must be alive whenever this is non-null. Before the |channel_| | 173 // |channel_| must be alive whenever this is non-null. Before the |channel_| |
168 // gives up its reference to this object, it will call |DetachFromChannel()|. | 174 // gives up its reference to this object, it will call |DetachFromChannel()|. |
169 Channel* channel_; | 175 Channel* channel_; |
170 MessageInTransit::EndpointId local_id_; | 176 MessageInTransit::EndpointId local_id_; |
171 MessageInTransit::EndpointId remote_id_; | 177 MessageInTransit::EndpointId remote_id_; |
172 | 178 |
| 179 // This queue is used before we're running on a channel and ready to send |
| 180 // messages. |
| 181 MessageInTransitQueue paused_message_queue_; |
| 182 |
173 DISALLOW_COPY_AND_ASSIGN(ChannelEndpoint); | 183 DISALLOW_COPY_AND_ASSIGN(ChannelEndpoint); |
174 }; | 184 }; |
175 | 185 |
176 } // namespace system | 186 } // namespace system |
177 } // namespace mojo | 187 } // namespace mojo |
178 | 188 |
179 #endif // MOJO_SYSTEM_CHANNEL_ENDPOINT_H_ | 189 #endif // MOJO_SYSTEM_CHANNEL_ENDPOINT_H_ |
OLD | NEW |