| 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 <deque> | 10 #include <deque> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "mojo/public/system/core.h" | 15 #include "mojo/public/system/core.h" |
| 16 #include "mojo/system/message_in_transit.h" | 16 #include "mojo/system/message_in_transit.h" |
| 17 #include "mojo/system/message_pipe_endpoint.h" | 17 #include "mojo/system/message_pipe_endpoint.h" |
| 18 #include "mojo/system/system_impl_export.h" | 18 #include "mojo/system/system_impl_export.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace system { | 21 namespace system { |
| 22 | 22 |
| 23 class Channel; | 23 class Channel; |
| 24 class MessagePipe; |
| 24 | 25 |
| 25 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a | 26 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a |
| 26 // |Channel|, over which it transmits and receives data (to/from another | 27 // |Channel|, over which it transmits and receives data (to/from another |
| 27 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and | 28 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and |
| 28 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a | 29 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a |
| 29 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via | 30 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via |
| 30 // a |MessagePipeDispatcher|. | 31 // a |MessagePipeDispatcher|. |
| 31 // | 32 // |
| 32 // Like any |MessagePipeEndpoint|, a |ProxyMessagePipeEndpoint| is owned by a | 33 // Like any |MessagePipeEndpoint|, a |ProxyMessagePipeEndpoint| is owned by a |
| 33 // |MessagePipe|. | 34 // |MessagePipe|. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 virtual void Close() OVERRIDE; | 48 virtual void Close() OVERRIDE; |
| 48 virtual void OnPeerClose() OVERRIDE; | 49 virtual void OnPeerClose() OVERRIDE; |
| 49 virtual MojoResult EnqueueMessage( | 50 virtual MojoResult EnqueueMessage( |
| 50 MessageInTransit* message, | 51 MessageInTransit* message, |
| 51 const std::vector<Dispatcher*>* dispatchers) OVERRIDE; | 52 const std::vector<Dispatcher*>* dispatchers) OVERRIDE; |
| 52 virtual void Attach(scoped_refptr<Channel> channel, | 53 virtual void Attach(scoped_refptr<Channel> channel, |
| 53 MessageInTransit::EndpointId local_id) OVERRIDE; | 54 MessageInTransit::EndpointId local_id) OVERRIDE; |
| 54 virtual void Run(MessageInTransit::EndpointId remote_id) OVERRIDE; | 55 virtual void Run(MessageInTransit::EndpointId remote_id) OVERRIDE; |
| 55 | 56 |
| 56 private: | 57 private: |
| 58 struct PreflightDispatcherInfo { |
| 59 PreflightDispatcherInfo() : message_pipe(), port() {} |
| 60 |
| 61 // For now, we only support sending message pipes, so this is simple. |
| 62 MessagePipe* message_pipe; |
| 63 unsigned port; |
| 64 }; |
| 65 |
| 57 bool is_attached() const { | 66 bool is_attached() const { |
| 58 return !!channel_.get(); | 67 return !!channel_.get(); |
| 59 } | 68 } |
| 60 | 69 |
| 61 bool is_running() const { | 70 bool is_running() const { |
| 62 return remote_id_ != MessageInTransit::kInvalidEndpointId; | 71 return remote_id_ != MessageInTransit::kInvalidEndpointId; |
| 63 } | 72 } |
| 64 | 73 |
| 65 MojoResult CanEnqueueDispatchers(const std::vector<Dispatcher*>* dispatchers); | 74 // Checks that |dispatchers| will be able to be enqueued by |
| 75 // |EnqueueMessageInternal()| (which then MUST be called if this succeeds). |
| 76 // |dispatchers| must be non-null and nonempty; |preflight_dispatcher_infos| |
| 77 // must be non-null and empty. |
| 78 MojoResult PreflightDispatchers( |
| 79 const std::vector<Dispatcher*>* dispatchers, |
| 80 std::vector<PreflightDispatcherInfo>* preflight_dispatcher_infos); |
| 66 // |dispatchers| should be non-null only if it's nonempty, in which case the | 81 // |dispatchers| should be non-null only if it's nonempty, in which case the |
| 67 // dispatchers should have been preflighted by |CanEnqueueDispatchers()|. | 82 // dispatchers should have been preflighted by |PreflightDispatchers()|. |
| 68 void EnqueueMessageInternal(MessageInTransit* message, | 83 void EnqueueMessageInternal(MessageInTransit* message, |
| 69 const std::vector<Dispatcher*>* dispatchers); | 84 const std::vector<Dispatcher*>* dispatchers); |
| 70 | 85 |
| 71 #ifdef NDEBUG | 86 #ifdef NDEBUG |
| 72 void AssertConsistentState() const {} | 87 void AssertConsistentState() const {} |
| 73 #else | 88 #else |
| 74 void AssertConsistentState() const; | 89 void AssertConsistentState() const; |
| 75 #endif | 90 #endif |
| 76 | 91 |
| 77 // This should only be set if we're attached. | 92 // This should only be set if we're attached. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 94 // not ready to send them yet. | 109 // not ready to send them yet. |
| 95 std::deque<MessageInTransit*> paused_message_queue_; | 110 std::deque<MessageInTransit*> paused_message_queue_; |
| 96 | 111 |
| 97 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); | 112 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); |
| 98 }; | 113 }; |
| 99 | 114 |
| 100 } // namespace system | 115 } // namespace system |
| 101 } // namespace mojo | 116 } // namespace mojo |
| 102 | 117 |
| 103 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ | 118 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
| OLD | NEW |