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

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

Issue 1423713009: EDK: Move ref counting classes to mojo/edk/util. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « mojo/edk/system/master_connection_manager.h ('k') | mojo/edk/system/message_pipe.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 11 #include <memory>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/memory/ref_counted.h"
15 #include "mojo/edk/embedder/platform_handle_vector.h" 14 #include "mojo/edk/embedder/platform_handle_vector.h"
16 #include "mojo/edk/system/channel_endpoint_client.h" 15 #include "mojo/edk/system/channel_endpoint_client.h"
17 #include "mojo/edk/system/dispatcher.h" 16 #include "mojo/edk/system/dispatcher.h"
18 #include "mojo/edk/system/handle_signals_state.h" 17 #include "mojo/edk/system/handle_signals_state.h"
19 #include "mojo/edk/system/memory.h" 18 #include "mojo/edk/system/memory.h"
20 #include "mojo/edk/system/message_in_transit.h" 19 #include "mojo/edk/system/message_in_transit.h"
21 #include "mojo/edk/system/message_pipe_endpoint.h" 20 #include "mojo/edk/system/message_pipe_endpoint.h"
22 #include "mojo/edk/system/mutex.h" 21 #include "mojo/edk/system/mutex.h"
23 #include "mojo/edk/system/ref_ptr.h" 22 #include "mojo/edk/util/ref_ptr.h"
24 #include "mojo/public/c/system/message_pipe.h" 23 #include "mojo/public/c/system/message_pipe.h"
25 #include "mojo/public/c/system/types.h" 24 #include "mojo/public/c/system/types.h"
26 #include "mojo/public/cpp/system/macros.h" 25 #include "mojo/public/cpp/system/macros.h"
27 26
28 namespace mojo { 27 namespace mojo {
29 namespace system { 28 namespace system {
30 29
31 class Awakable; 30 class Awakable;
32 class Channel; 31 class Channel;
33 class ChannelEndpoint; 32 class ChannelEndpoint;
34 class MessageInTransitQueue; 33 class MessageInTransitQueue;
35 34
36 // |MessagePipe| is the secondary object implementing a message pipe (see the 35 // |MessagePipe| is the secondary object implementing a message pipe (see the
37 // 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)
38 // corresponding to the local endpoints. This class is thread-safe. 37 // corresponding to the local endpoints. This class is thread-safe.
39 class MessagePipe final : public ChannelEndpointClient { 38 class MessagePipe final : public ChannelEndpointClient {
40 public: 39 public:
41 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. 40 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s.
42 static RefPtr<MessagePipe> CreateLocalLocal(); 41 static util::RefPtr<MessagePipe> CreateLocalLocal();
43 42
44 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a 43 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a
45 // |ProxyMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the 44 // |ProxyMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the
46 // (newly-created) |ChannelEndpoint| for the latter. 45 // (newly-created) |ChannelEndpoint| for the latter.
47 static RefPtr<MessagePipe> CreateLocalProxy( 46 static util::RefPtr<MessagePipe> CreateLocalProxy(
48 RefPtr<ChannelEndpoint>* channel_endpoint); 47 util::RefPtr<ChannelEndpoint>* channel_endpoint);
49 48
50 // Similar to |CreateLocalProxy()|, except that it'll do so from an existing 49 // Similar to |CreateLocalProxy()|, except that it'll do so from an existing
51 // |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and take 50 // |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and take
52 // |message_queue|'s contents as already-received incoming messages. If 51 // |message_queue|'s contents as already-received incoming messages. If
53 // |channel_endpoint| is null, this will create a "half-open" message pipe. 52 // |channel_endpoint| is null, this will create a "half-open" message pipe.
54 static RefPtr<MessagePipe> CreateLocalProxyFromExisting( 53 static util::RefPtr<MessagePipe> CreateLocalProxyFromExisting(
55 MessageInTransitQueue* message_queue, 54 MessageInTransitQueue* message_queue,
56 RefPtr<ChannelEndpoint>&& channel_endpoint); 55 util::RefPtr<ChannelEndpoint>&& channel_endpoint);
57 56
58 // Creates a |MessagePipe| with a |ProxyMessagePipeEndpoint| on port 0 and a 57 // Creates a |MessagePipe| with a |ProxyMessagePipeEndpoint| on port 0 and a
59 // |LocalMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the 58 // |LocalMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the
60 // (newly-created) |ChannelEndpoint| for the former. 59 // (newly-created) |ChannelEndpoint| for the former.
61 // Note: This is really only needed in tests (outside of tests, this 60 // Note: This is really only needed in tests (outside of tests, this
62 // configuration arises from a local message pipe having its port 0 61 // configuration arises from a local message pipe having its port 0
63 // "converted" using |ConvertLocalToProxy()|). 62 // "converted" using |ConvertLocalToProxy()|).
64 static RefPtr<MessagePipe> CreateProxyLocal( 63 static util::RefPtr<MessagePipe> CreateProxyLocal(
65 RefPtr<ChannelEndpoint>* channel_endpoint); 64 util::RefPtr<ChannelEndpoint>* channel_endpoint);
66 65
67 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). 66 // Gets the other port number (i.e., 0 -> 1, 1 -> 0).
68 static unsigned GetPeerPort(unsigned port); 67 static unsigned GetPeerPort(unsigned port);
69 68
70 // Used by |MessagePipeDispatcher::Deserialize()|. Returns true on success (in 69 // Used by |MessagePipeDispatcher::Deserialize()|. Returns true on success (in
71 // which case, |*message_pipe|/|*port| are set appropriately) and false on 70 // which case, |*message_pipe|/|*port| are set appropriately) and false on
72 // failure (in which case |*message_pipe| may or may not be set to null). 71 // failure (in which case |*message_pipe| may or may not be set to null).
73 static bool Deserialize(Channel* channel, 72 static bool Deserialize(Channel* channel,
74 const void* source, 73 const void* source,
75 size_t size, 74 size_t size,
76 RefPtr<MessagePipe>* message_pipe, 75 util::RefPtr<MessagePipe>* message_pipe,
77 unsigned* port); 76 unsigned* port);
78 77
79 // Gets the type of the endpoint (used for assertions, etc.). 78 // Gets the type of the endpoint (used for assertions, etc.).
80 MessagePipeEndpoint::Type GetType(unsigned port); 79 MessagePipeEndpoint::Type GetType(unsigned port);
81 80
82 // These are called by the dispatcher to implement its methods of 81 // These are called by the dispatcher to implement its methods of
83 // corresponding names. In all cases, the port |port| must be open. 82 // corresponding names. In all cases, the port |port| must be open.
84 void CancelAllAwakables(unsigned port); 83 void CancelAllAwakables(unsigned port);
85 void Close(unsigned port); 84 void Close(unsigned port);
86 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its 85 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 mutable Mutex mutex_; 140 mutable Mutex mutex_;
142 std::unique_ptr<MessagePipeEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_); 141 std::unique_ptr<MessagePipeEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_);
143 142
144 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipe); 143 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipe);
145 }; 144 };
146 145
147 } // namespace system 146 } // namespace system
148 } // namespace mojo 147 } // namespace mojo
149 148
150 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ 149 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/master_connection_manager.h ('k') | mojo/edk/system/message_pipe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698