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

Side by Side Diff: mojo/edk/system/message_pipe.h

Issue 738453003: Add a ChannelEndpointClient abstraction. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 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
OLDNEW
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_EDK_SYSTEM_MESSAGE_PIPE_H_ 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_
6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ 6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "mojo/edk/embedder/platform_handle_vector.h" 17 #include "mojo/edk/embedder/platform_handle_vector.h"
18 #include "mojo/edk/system/channel_endpoint_client.h"
18 #include "mojo/edk/system/dispatcher.h" 19 #include "mojo/edk/system/dispatcher.h"
19 #include "mojo/edk/system/handle_signals_state.h" 20 #include "mojo/edk/system/handle_signals_state.h"
20 #include "mojo/edk/system/memory.h" 21 #include "mojo/edk/system/memory.h"
21 #include "mojo/edk/system/message_in_transit.h" 22 #include "mojo/edk/system/message_in_transit.h"
22 #include "mojo/edk/system/message_pipe_endpoint.h" 23 #include "mojo/edk/system/message_pipe_endpoint.h"
23 #include "mojo/edk/system/system_impl_export.h" 24 #include "mojo/edk/system/system_impl_export.h"
24 #include "mojo/public/c/system/message_pipe.h" 25 #include "mojo/public/c/system/message_pipe.h"
25 #include "mojo/public/c/system/types.h" 26 #include "mojo/public/c/system/types.h"
26 27
27 namespace mojo { 28 namespace mojo {
28 namespace system { 29 namespace system {
29 30
30 class Channel; 31 class Channel;
31 class ChannelEndpoint; 32 class ChannelEndpoint;
32 class Waiter; 33 class Waiter;
33 34
34 // |MessagePipe| is the secondary object implementing a message pipe (see the 35 // |MessagePipe| is the secondary object implementing a message pipe (see the
35 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) 36 // explanatory comment in core.cc). It is typically owned by the dispatcher(s)
36 // corresponding to the local endpoints. This class is thread-safe. 37 // corresponding to the local endpoints. This class is thread-safe.
37 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe 38 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe : public ChannelEndpointClient {
38 : public base::RefCountedThreadSafe<MessagePipe> {
39 public: 39 public:
40 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. 40 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s.
41 static MessagePipe* CreateLocalLocal(); 41 static MessagePipe* CreateLocalLocal();
42 42
43 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a 43 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a
44 // |ProxyMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the 44 // |ProxyMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the
45 // (newly-created) |ChannelEndpoint| for the latter. 45 // (newly-created) |ChannelEndpoint| for the latter.
46 static MessagePipe* CreateLocalProxy( 46 static MessagePipe* CreateLocalProxy(
47 scoped_refptr<ChannelEndpoint>* channel_endpoint); 47 scoped_refptr<ChannelEndpoint>* channel_endpoint);
48 48
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 bool EndSerialize(unsigned port, 103 bool EndSerialize(unsigned port,
104 Channel* channel, 104 Channel* channel,
105 void* destination, 105 void* destination,
106 size_t* actual_size, 106 size_t* actual_size,
107 embedder::PlatformHandleVector* platform_handles); 107 embedder::PlatformHandleVector* platform_handles);
108 108
109 // Used by |EndSerialize()|. TODO(vtl): Remove this (merge it into 109 // Used by |EndSerialize()|. TODO(vtl): Remove this (merge it into
110 // |EndSerialize()|). 110 // |EndSerialize()|).
111 scoped_refptr<ChannelEndpoint> ConvertLocalToProxy(unsigned port); 111 scoped_refptr<ChannelEndpoint> ConvertLocalToProxy(unsigned port);
112 112
113 // This is used by |Channel| to enqueue messages (typically to a 113 // |ChannelEndpointClient| methods:
114 // |LocalMessagePipeEndpoint|). Unlike |WriteMessage()|, |port| is the 114 virtual bool OnReadMessage(unsigned port,
yzshen1 2014/11/18 00:28:17 nit: I think the current style guide prefers using
viettrungluu 2014/11/18 00:47:30 Done.
115 // *destination* port. 115 scoped_ptr<MessageInTransit> message) override;
116 MojoResult EnqueueMessage(unsigned port, 116 virtual void OnDetachFromChannel(unsigned port) override;
117 scoped_ptr<MessageInTransit> message);
118 117
119 private: 118 private:
120 MessagePipe(); 119 MessagePipe();
120 virtual ~MessagePipe();
121 121
122 friend class base::RefCountedThreadSafe<MessagePipe>; 122 // This is used internally by |WriteMessage()| and by |OnReadMessage()|.
123 ~MessagePipe();
124
125 // This is used internally by |WriteMessage()| and by |EnqueueMessage()|.
126 // |transports| may be non-null only if it's nonempty and |message| has no 123 // |transports| may be non-null only if it's nonempty and |message| has no
127 // dispatchers attached. 124 // dispatchers attached.
128 MojoResult EnqueueMessageInternal( 125 MojoResult EnqueueMessage(unsigned port,
129 unsigned port, 126 scoped_ptr<MessageInTransit> message,
130 scoped_ptr<MessageInTransit> message, 127 std::vector<DispatcherTransport>* transports);
131 std::vector<DispatcherTransport>* transports);
132 128
133 // Helper for |EnqueueMessageInternal()|. Must be called with |lock_| held. 129 // Helper for |EnqueueMessage()|. Must be called with |lock_| held.
134 MojoResult AttachTransportsNoLock( 130 MojoResult AttachTransportsNoLock(
135 unsigned port, 131 unsigned port,
136 MessageInTransit* message, 132 MessageInTransit* message,
137 std::vector<DispatcherTransport>* transports); 133 std::vector<DispatcherTransport>* transports);
138 134
139 // Used by |EnqueueMessageInternal()| to handle control messages that are 135 // Used by |EnqueueMessage()| to handle control messages that are actually
140 // actually meant for us. 136 // meant for us.
141 MojoResult HandleControlMessage(unsigned port, 137 MojoResult HandleControlMessage(unsigned port,
142 scoped_ptr<MessageInTransit> message); 138 scoped_ptr<MessageInTransit> message);
143 139
144 base::Lock lock_; // Protects the following members. 140 base::Lock lock_; // Protects the following members.
145 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; 141 scoped_ptr<MessagePipeEndpoint> endpoints_[2];
146 142
147 DISALLOW_COPY_AND_ASSIGN(MessagePipe); 143 DISALLOW_COPY_AND_ASSIGN(MessagePipe);
148 }; 144 };
149 145
150 } // namespace system 146 } // namespace system
151 } // namespace mojo 147 } // namespace mojo
152 148
153 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ 149 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698