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 #ifndef MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ | 5 #ifndef MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
6 #define MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ | 6 #define MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
13 #include "mojo/system/message_in_transit.h" | 12 #include "mojo/system/message_in_transit.h" |
14 #include "mojo/system/message_in_transit_queue.h" | 13 #include "mojo/system/message_in_transit_queue.h" |
15 #include "mojo/system/message_pipe_endpoint.h" | 14 #include "mojo/system/message_pipe_endpoint.h" |
16 #include "mojo/system/system_impl_export.h" | 15 #include "mojo/system/system_impl_export.h" |
17 | 16 |
18 namespace mojo { | 17 namespace mojo { |
19 namespace system { | 18 namespace system { |
20 | 19 |
21 class Channel; | |
22 class ChannelEndpoint; | 20 class ChannelEndpoint; |
23 class LocalMessagePipeEndpoint; | 21 class LocalMessagePipeEndpoint; |
24 class MessagePipe; | 22 class MessagePipe; |
25 | 23 |
26 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a | 24 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a |
27 // |Channel|, over which it transmits and receives data (to/from another | 25 // |Channel|, over which it transmits and receives data (to/from another |
28 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and | 26 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and |
29 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a | 27 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a |
30 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via | 28 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via |
31 // a |MessagePipeDispatcher|. | 29 // a |MessagePipeDispatcher|. |
(...skipping 16 matching lines...) Expand all Loading... |
48 // handle over a remote message pipe. | 46 // handle over a remote message pipe. |
49 ProxyMessagePipeEndpoint( | 47 ProxyMessagePipeEndpoint( |
50 LocalMessagePipeEndpoint* local_message_pipe_endpoint, | 48 LocalMessagePipeEndpoint* local_message_pipe_endpoint, |
51 bool is_peer_open); | 49 bool is_peer_open); |
52 virtual ~ProxyMessagePipeEndpoint(); | 50 virtual ~ProxyMessagePipeEndpoint(); |
53 | 51 |
54 // |MessagePipeEndpoint| implementation: | 52 // |MessagePipeEndpoint| implementation: |
55 virtual Type GetType() const OVERRIDE; | 53 virtual Type GetType() const OVERRIDE; |
56 virtual bool OnPeerClose() OVERRIDE; | 54 virtual bool OnPeerClose() OVERRIDE; |
57 virtual void EnqueueMessage(scoped_ptr<MessageInTransit> message) OVERRIDE; | 55 virtual void EnqueueMessage(scoped_ptr<MessageInTransit> message) OVERRIDE; |
58 virtual void Attach(ChannelEndpoint* channel_endpoint, | 56 virtual void Attach(ChannelEndpoint* channel_endpoint) OVERRIDE; |
59 Channel* channel, | 57 virtual bool Run() OVERRIDE; |
60 MessageInTransit::EndpointId local_id) OVERRIDE; | |
61 virtual bool Run(MessageInTransit::EndpointId remote_id) OVERRIDE; | |
62 virtual void OnRemove() OVERRIDE; | 58 virtual void OnRemove() OVERRIDE; |
63 | 59 |
64 private: | 60 private: |
65 void Detach(); | 61 void Detach(); |
66 | 62 |
67 #ifdef NDEBUG | 63 // TODO(vtl): Get rid of these. |
68 void AssertConsistentState() const {} | 64 bool is_attached() const { return !!channel_endpoint_.get(); } |
69 #else | 65 bool is_running() const { return is_running_; } |
70 void AssertConsistentState() const; | |
71 #endif | |
72 | |
73 bool is_attached() const { return !!channel_.get(); } | |
74 | |
75 bool is_running() const { | |
76 return remote_id_ != MessageInTransit::kInvalidEndpointId; | |
77 } | |
78 | 66 |
79 // This should only be set if we're attached. | 67 // This should only be set if we're attached. |
80 scoped_refptr<ChannelEndpoint> channel_endpoint_; | 68 scoped_refptr<ChannelEndpoint> channel_endpoint_; |
81 | 69 |
82 // TODO(vtl): Remove this, local_id_, and remote_id_. | 70 // TODO(vtl): Get rid of this. |
83 // This should only be set if we're attached. | 71 bool is_running_; |
84 scoped_refptr<Channel> channel_; | |
85 | |
86 // |local_id_| should be set to something other than | |
87 // |MessageInTransit::kInvalidEndpointId| when we're attached. | |
88 MessageInTransit::EndpointId local_id_; | |
89 | |
90 // |remote_id_| being set to anything other than | |
91 // |MessageInTransit::kInvalidEndpointId| indicates that we're "running", | |
92 // i.e., actively able to send messages. We should only ever be running if | |
93 // we're attached. | |
94 MessageInTransit::EndpointId remote_id_; | |
95 | 72 |
96 bool is_peer_open_; | 73 bool is_peer_open_; |
97 | 74 |
98 // This queue is only used while we're detached, to store messages while we're | 75 // This queue is only used while we're detached, to store messages while we're |
99 // not ready to send them yet. | 76 // not ready to send them yet. |
100 MessageInTransitQueue paused_message_queue_; | 77 MessageInTransitQueue paused_message_queue_; |
101 | 78 |
102 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); | 79 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); |
103 }; | 80 }; |
104 | 81 |
105 } // namespace system | 82 } // namespace system |
106 } // namespace mojo | 83 } // namespace mojo |
107 | 84 |
108 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ | 85 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
OLD | NEW |