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

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

Issue 1412283002: Convert mojo::system::Dispatcher to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: no change Created 5 years, 2 months 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/message_in_transit.cc ('k') | mojo/edk/system/message_pipe_dispatcher.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_DISPATCHER_H_ 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ 6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
7 7
8 #include "base/memory/ref_counted.h"
9 #include "mojo/edk/system/dispatcher.h" 8 #include "mojo/edk/system/dispatcher.h"
10 #include "mojo/edk/system/memory.h" 9 #include "mojo/edk/system/memory.h"
11 #include "mojo/edk/system/ref_ptr.h" 10 #include "mojo/edk/system/ref_ptr.h"
12 #include "mojo/public/cpp/system/macros.h" 11 #include "mojo/public/cpp/system/macros.h"
13 12
14 namespace mojo { 13 namespace mojo {
15 namespace system { 14 namespace system {
16 15
17 class ChannelEndpoint; 16 class ChannelEndpoint;
18 class MessagePipe; 17 class MessagePipe;
19 class MessagePipeDispatcherTransport; 18 class MessagePipeDispatcherTransport;
20 19
21 // This is the |Dispatcher| implementation for message pipes (created by the 20 // This is the |Dispatcher| implementation for message pipes (created by the
22 // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe. 21 // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe.
23 class MessagePipeDispatcher final : public Dispatcher { 22 class MessagePipeDispatcher final : public Dispatcher {
24 public: 23 public:
25 // The default options to use for |MojoCreateMessagePipe()|. (Real uses 24 // The default options to use for |MojoCreateMessagePipe()|. (Real uses
26 // should obtain this via |ValidateCreateOptions()| with a null |in_options|; 25 // should obtain this via |ValidateCreateOptions()| with a null |in_options|;
27 // this is exposed directly for testing convenience.) 26 // this is exposed directly for testing convenience.)
28 static const MojoCreateMessagePipeOptions kDefaultCreateOptions; 27 static const MojoCreateMessagePipeOptions kDefaultCreateOptions;
29 28
30 static scoped_refptr<MessagePipeDispatcher> Create( 29 static RefPtr<MessagePipeDispatcher> Create(
31 const MojoCreateMessagePipeOptions& /*validated_options*/) { 30 const MojoCreateMessagePipeOptions& /*validated_options*/) {
32 return make_scoped_refptr(new MessagePipeDispatcher()); 31 return AdoptRef(new MessagePipeDispatcher());
33 } 32 }
34 33
35 // Validates and/or sets default options for |MojoCreateMessagePipeOptions|. 34 // Validates and/or sets default options for |MojoCreateMessagePipeOptions|.
36 // If non-null, |in_options| must point to a struct of at least 35 // If non-null, |in_options| must point to a struct of at least
37 // |in_options->struct_size| bytes. |out_options| must point to a (current) 36 // |in_options->struct_size| bytes. |out_options| must point to a (current)
38 // |MojoCreateMessagePipeOptions| and will be entirely overwritten on success 37 // |MojoCreateMessagePipeOptions| and will be entirely overwritten on success
39 // (it may be partly overwritten on failure). 38 // (it may be partly overwritten on failure).
40 static MojoResult ValidateCreateOptions( 39 static MojoResult ValidateCreateOptions(
41 UserPointer<const MojoCreateMessagePipeOptions> in_options, 40 UserPointer<const MojoCreateMessagePipeOptions> in_options,
42 MojoCreateMessagePipeOptions* out_options); 41 MojoCreateMessagePipeOptions* out_options);
43 42
44 // Must be called before any other methods. (This method is not thread-safe.) 43 // Must be called before any other methods. (This method is not thread-safe.)
45 void Init(RefPtr<MessagePipe>&& message_pipe, 44 void Init(RefPtr<MessagePipe>&& message_pipe,
46 unsigned port) MOJO_NOT_THREAD_SAFE; 45 unsigned port) MOJO_NOT_THREAD_SAFE;
47 46
48 // |Dispatcher| public methods: 47 // |Dispatcher| public methods:
49 Type GetType() const override; 48 Type GetType() const override;
50 49
51 // Creates a |MessagePipe| with a local endpoint (at port 0) and a proxy 50 // Creates a |MessagePipe| with a local endpoint (at port 0) and a proxy
52 // endpoint, and creates/initializes a |MessagePipeDispatcher| (attached to 51 // endpoint, and creates/initializes a |MessagePipeDispatcher| (attached to
53 // the message pipe, port 0). 52 // the message pipe, port 0).
54 // TODO(vtl): This currently uses |kDefaultCreateOptions|, which is okay since 53 // TODO(vtl): This currently uses |kDefaultCreateOptions|, which is okay since
55 // there aren't any options, but eventually options should be plumbed through. 54 // there aren't any options, but eventually options should be plumbed through.
56 static scoped_refptr<MessagePipeDispatcher> CreateRemoteMessagePipe( 55 static RefPtr<MessagePipeDispatcher> CreateRemoteMessagePipe(
57 RefPtr<ChannelEndpoint>* channel_endpoint); 56 RefPtr<ChannelEndpoint>* channel_endpoint);
58 57
59 // The "opposite" of |SerializeAndClose()|. (Typically this is called by 58 // The "opposite" of |SerializeAndClose()|. (Typically this is called by
60 // |Dispatcher::Deserialize()|.) 59 // |Dispatcher::Deserialize()|.)
61 static scoped_refptr<MessagePipeDispatcher> Deserialize(Channel* channel, 60 static RefPtr<MessagePipeDispatcher> Deserialize(Channel* channel,
62 const void* source, 61 const void* source,
63 size_t size); 62 size_t size);
64 63
65 private: 64 private:
66 friend class MessagePipeDispatcherTransport; 65 friend class MessagePipeDispatcherTransport;
67 66
68 MessagePipeDispatcher(); 67 MessagePipeDispatcher();
69 ~MessagePipeDispatcher() override; 68 ~MessagePipeDispatcher() override;
70 69
71 // Gets a dumb pointer to |message_pipe_|. This must be called under the 70 // Gets a dumb pointer to |message_pipe_|. This must be called under the
72 // |Dispatcher| lock (that it's a dumb pointer is okay since it's under lock). 71 // |Dispatcher| lock (that it's a dumb pointer is okay since it's under lock).
73 // This is needed when sending handles across processes, where nontrivial, 72 // This is needed when sending handles across processes, where nontrivial,
74 // invasive work needs to be done. 73 // invasive work needs to be done.
75 MessagePipe* GetMessagePipeNoLock() const; 74 MessagePipe* GetMessagePipeNoLock() const;
76 // Similarly for the port. 75 // Similarly for the port.
77 unsigned GetPortNoLock() const; 76 unsigned GetPortNoLock() const;
78 77
79 // |Dispatcher| protected methods: 78 // |Dispatcher| protected methods:
80 void CancelAllAwakablesNoLock() override; 79 void CancelAllAwakablesNoLock() override;
81 void CloseImplNoLock() override; 80 void CloseImplNoLock() override;
82 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() 81 RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() override;
83 override;
84 MojoResult WriteMessageImplNoLock( 82 MojoResult WriteMessageImplNoLock(
85 UserPointer<const void> bytes, 83 UserPointer<const void> bytes,
86 uint32_t num_bytes, 84 uint32_t num_bytes,
87 std::vector<DispatcherTransport>* transports, 85 std::vector<DispatcherTransport>* transports,
88 MojoWriteMessageFlags flags) override; 86 MojoWriteMessageFlags flags) override;
89 MojoResult ReadMessageImplNoLock(UserPointer<void> bytes, 87 MojoResult ReadMessageImplNoLock(UserPointer<void> bytes,
90 UserPointer<uint32_t> num_bytes, 88 UserPointer<uint32_t> num_bytes,
91 DispatcherVector* dispatchers, 89 DispatcherVector* dispatchers,
92 uint32_t* num_dispatchers, 90 uint32_t* num_dispatchers,
93 MojoReadMessageFlags flags) override; 91 MojoReadMessageFlags flags) override;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return static_cast<MessagePipeDispatcher*>(dispatcher()); 128 return static_cast<MessagePipeDispatcher*>(dispatcher());
131 } 129 }
132 130
133 // Copy and assign allowed. 131 // Copy and assign allowed.
134 }; 132 };
135 133
136 } // namespace system 134 } // namespace system
137 } // namespace mojo 135 } // namespace mojo
138 136
139 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ 137 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/message_in_transit.cc ('k') | mojo/edk/system/message_pipe_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698