| 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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "mojo/system/message_in_transit.h" | 10 #include "mojo/system/message_in_transit.h" |
| 11 #include "mojo/system/message_in_transit_queue.h" | |
| 12 #include "mojo/system/message_pipe_endpoint.h" | 11 #include "mojo/system/message_pipe_endpoint.h" |
| 13 #include "mojo/system/system_impl_export.h" | 12 #include "mojo/system/system_impl_export.h" |
| 14 | 13 |
| 15 namespace mojo { | 14 namespace mojo { |
| 16 namespace system { | 15 namespace system { |
| 17 | 16 |
| 18 class ChannelEndpoint; | 17 class ChannelEndpoint; |
| 19 class LocalMessagePipeEndpoint; | 18 class LocalMessagePipeEndpoint; |
| 20 class MessagePipe; | 19 class MessagePipe; |
| 21 | 20 |
| 22 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a | 21 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a |
| 23 // |Channel|, over which it transmits and receives data (to/from another | 22 // |Channel|, over which it transmits and receives data (to/from another |
| 24 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and | 23 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and |
| 25 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a | 24 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a |
| 26 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via | 25 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via |
| 27 // a |MessagePipeDispatcher|. | 26 // a |MessagePipeDispatcher|. |
| 28 // | 27 // |
| 29 // Like any |MessagePipeEndpoint|, a |ProxyMessagePipeEndpoint| is owned by a | 28 // Like any |MessagePipeEndpoint|, a |ProxyMessagePipeEndpoint| is owned by a |
| 30 // |MessagePipe|. | 29 // |MessagePipe|. |
| 31 // - A |ProxyMessagePipeEndpoint| starts out *detached*, i.e., not associated | 30 // - A |ProxyMessagePipeEndpoint| starts out *detached*, i.e., not associated |
| 32 // to any |Channel|. When *attached*, it gets a reference to a |Channel| and | 31 // to any |Channel|. When *attached*, it gets a reference to a |Channel| and |
| 33 // is assigned a local ID. A |ProxyMessagePipeEndpoint| must be detached | 32 // is assigned a local ID. A |ProxyMessagePipeEndpoint| must be detached |
| 34 // before destruction; this is done inside |Close()|. | 33 // before destruction; this is done inside |Close()|. |
| 35 // - When attached, a |ProxyMessagePipeEndpoint| starts out not running. When | 34 // - When attached, a |ProxyMessagePipeEndpoint| starts out not running. When |
| 36 // run, it gets a remote ID. | 35 // run, it gets a remote ID. |
| 37 class MOJO_SYSTEM_IMPL_EXPORT ProxyMessagePipeEndpoint | 36 class MOJO_SYSTEM_IMPL_EXPORT ProxyMessagePipeEndpoint |
| 38 : public MessagePipeEndpoint { | 37 : public MessagePipeEndpoint { |
| 39 public: | 38 public: |
| 40 explicit ProxyMessagePipeEndpoint(ChannelEndpoint* channel_endpoint); | 39 explicit ProxyMessagePipeEndpoint(ChannelEndpoint* channel_endpoint); |
| 41 // Constructs a |ProxyMessagePipeEndpoint| that replaces the given | 40 // Constructs a |ProxyMessagePipeEndpoint|, whose peer may already be closed. |
| 42 // |LocalMessagePipeEndpoint| (which this constructor will close), taking its | 41 // This is used to construct one to replace a |LocalMessagePipeEndpoint|, when |
| 43 // message queue's contents. This is done when transferring a message pipe | 42 // transferring a message pipe handle over a remote message pipe. |
| 44 // handle over a remote message pipe. | |
| 45 ProxyMessagePipeEndpoint( | 43 ProxyMessagePipeEndpoint( |
| 46 ChannelEndpoint* channel_endpoint, | 44 ChannelEndpoint* channel_endpoint, |
| 47 LocalMessagePipeEndpoint* local_message_pipe_endpoint, | |
| 48 bool is_peer_open); | 45 bool is_peer_open); |
| 49 virtual ~ProxyMessagePipeEndpoint(); | 46 virtual ~ProxyMessagePipeEndpoint(); |
| 50 | 47 |
| 51 // |MessagePipeEndpoint| implementation: | 48 // |MessagePipeEndpoint| implementation: |
| 52 virtual Type GetType() const OVERRIDE; | 49 virtual Type GetType() const OVERRIDE; |
| 53 virtual bool OnPeerClose() OVERRIDE; | 50 virtual bool OnPeerClose() OVERRIDE; |
| 54 virtual void EnqueueMessage(scoped_ptr<MessageInTransit> message) OVERRIDE; | 51 virtual void EnqueueMessage(scoped_ptr<MessageInTransit> message) OVERRIDE; |
| 55 virtual bool Run() OVERRIDE; | 52 virtual bool Run() OVERRIDE; |
| 56 virtual void OnRemove() OVERRIDE; | 53 virtual void OnRemove() OVERRIDE; |
| 57 | 54 |
| 58 private: | 55 private: |
| 59 void Detach(); | 56 void Detach(); |
| 60 | 57 |
| 61 // TODO(vtl): Get rid of these. | 58 // TODO(vtl): Get rid of these. |
| 62 bool is_attached() const { return !!channel_endpoint_.get(); } | 59 bool is_attached() const { return !!channel_endpoint_.get(); } |
| 63 bool is_running() const { return is_running_; } | 60 bool is_running() const { return is_running_; } |
| 64 | 61 |
| 65 // This should only be set if we're attached. | 62 // This should only be set if we're attached. |
| 66 scoped_refptr<ChannelEndpoint> channel_endpoint_; | 63 scoped_refptr<ChannelEndpoint> channel_endpoint_; |
| 67 | 64 |
| 68 // TODO(vtl): Get rid of this. | 65 // TODO(vtl): Get rid of this. |
| 69 bool is_running_; | 66 bool is_running_; |
| 70 | 67 |
| 71 bool is_peer_open_; | 68 bool is_peer_open_; |
| 72 | 69 |
| 73 // This queue is only used while we're detached, to store messages while we're | |
| 74 // not ready to send them yet. | |
| 75 MessageInTransitQueue paused_message_queue_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); | 70 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); |
| 78 }; | 71 }; |
| 79 | 72 |
| 80 } // namespace system | 73 } // namespace system |
| 81 } // namespace mojo | 74 } // namespace mojo |
| 82 | 75 |
| 83 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ | 76 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
| OLD | NEW |