Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: mojo/system/proxy_message_pipe_endpoint.h

Issue 60103005: Mojo: First stab at making MessagePipes work across OS pipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_
6 #define MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_
7
8 #include <stdint.h>
9
10 #include <deque>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "mojo/public/system/core.h"
16 #include "mojo/system/message_in_transit.h"
17 #include "mojo/system/message_pipe_endpoint.h"
18
19 namespace mojo {
20 namespace system {
21
22 class Channel;
23
24 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a
25 // |Channel|, over which it transmits and receives data (to/from another
26 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and
27 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a
28 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via
29 // a |MessagePipeDispatcher|.
30 //
31 // Like any |MessagePipeEndpoint|, a |ProxyMessagePipeEndpoint| is owned by a
32 // |MessagePipe|.
33 // - A |ProxyMessagePipeEndpoint| starts out *detached*, i.e., not associated
34 // to any |Channel|. When *attached*, it gets a reference to a |Channel| and
35 // is assigned a local ID. A |ProxyMessagePipeEndpoint| must be detached
36 // before destruction; this is done inside |Close()|.
37 // - When attached, a |ProxyMessagePipeEndpoint| starts out not running. When
38 // run, it gets a remote ID.
39 class ProxyMessagePipeEndpoint : public MessagePipeEndpoint {
40 public:
41 ProxyMessagePipeEndpoint();
42 virtual ~ProxyMessagePipeEndpoint();
43
44 // |MessagePipeEndpoint| implementation:
45 virtual void Close() OVERRIDE;
46 virtual bool OnPeerClose() OVERRIDE;
47 virtual MojoResult EnqueueMessage(MessageInTransit* message) OVERRIDE;
48 virtual void Attach(scoped_refptr<Channel> channel,
49 MessageInTransit::EndpointId local_id) OVERRIDE;
50 virtual bool Run(MessageInTransit::EndpointId remote_id) OVERRIDE;
51
52 private:
53 bool is_attached() const {
54 return !!channel_.get();
55 }
56
57 bool is_running() const {
58 return remote_id_ != MessageInTransit::kInvalidEndpointId;
59 }
60
61 #ifdef NDEBUG
62 void AssertConsistentState() const {}
63 #else
64 void AssertConsistentState() const;
65 #endif
66
67 // This should only be set if we're attached.
68 scoped_refptr<Channel> channel_;
69
70 // |local_id_| should be set to something other than
71 // |MessageInTransit::kInvalidEndpointId| when we're attached.
72 MessageInTransit::EndpointId local_id_;
73
74 // |remote_id_| being set to anything other than
75 // |MessageInTransit::kInvalidEndpointId| indicates that we're "running",
76 // i.e., actively able to send messages. We should only ever be running if
77 // we're attached.
78 MessageInTransit::EndpointId remote_id_;
79
80 bool is_open_;
81 bool is_peer_open_;
82
83 // This queue is only used while we're detached, to store messages while we're
84 // not ready to send them yet.
85 std::deque<MessageInTransit*> paused_message_queue_;
86
87 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint);
88 };
89
90 } // namespace system
91 } // namespace mojo
92
93 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698