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

Side by Side Diff: mojo/system/message_pipe_dispatcher.cc

Issue 324783002: Mojo: Add a MojoCreateMessagePipeOptions struct parameter to MojoCreateMessagePipe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/message_pipe_dispatcher.h ('k') | mojo/system/message_pipe_dispatcher_unittest.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 #include "mojo/system/message_pipe_dispatcher.h" 5 #include "mojo/system/message_pipe_dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/system/channel.h" 8 #include "mojo/system/channel.h"
9 #include "mojo/system/constants.h" 9 #include "mojo/system/constants.h"
10 #include "mojo/system/local_message_pipe_endpoint.h" 10 #include "mojo/system/local_message_pipe_endpoint.h"
11 #include "mojo/system/memory.h" 11 #include "mojo/system/memory.h"
12 #include "mojo/system/message_in_transit.h" 12 #include "mojo/system/message_in_transit.h"
13 #include "mojo/system/message_pipe.h" 13 #include "mojo/system/message_pipe.h"
14 #include "mojo/system/options_validation.h"
14 #include "mojo/system/proxy_message_pipe_endpoint.h" 15 #include "mojo/system/proxy_message_pipe_endpoint.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 namespace system { 18 namespace system {
18 19
19 namespace { 20 namespace {
20 21
21 const unsigned kInvalidPort = static_cast<unsigned>(-1); 22 const unsigned kInvalidPort = static_cast<unsigned>(-1);
22 23
23 struct SerializedMessagePipeDispatcher { 24 struct SerializedMessagePipeDispatcher {
24 MessageInTransit::EndpointId endpoint_id; 25 MessageInTransit::EndpointId endpoint_id;
25 }; 26 };
26 27
27 } // namespace 28 } // namespace
28 29
29 // MessagePipeDispatcher ------------------------------------------------------- 30 // MessagePipeDispatcher -------------------------------------------------------
30 31
31 MessagePipeDispatcher::MessagePipeDispatcher() 32 // static
33 const MojoCreateMessagePipeOptions
34 MessagePipeDispatcher::kDefaultCreateOptions = {
35 static_cast<uint32_t>(sizeof(MojoCreateMessagePipeOptions)),
36 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE
37 };
38
39 MessagePipeDispatcher::MessagePipeDispatcher(
40 const MojoCreateMessagePipeOptions& /*validated_options*/)
32 : port_(kInvalidPort) { 41 : port_(kInvalidPort) {
33 } 42 }
34 43
44 // static
45 MojoResult MessagePipeDispatcher::ValidateCreateOptions(
46 const MojoCreateMessagePipeOptions* in_options,
47 MojoCreateMessagePipeOptions* out_options) {
48 const MojoCreateMessagePipeOptionsFlags kKnownFlags =
49 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE;
50
51 *out_options = kDefaultCreateOptions;
52 if (!in_options)
53 return MOJO_RESULT_OK;
54
55 MojoResult result =
56 ValidateOptionsStructPointerSizeAndFlags<MojoCreateMessagePipeOptions>(
57 in_options, kKnownFlags, out_options);
58 if (result != MOJO_RESULT_OK)
59 return result;
60
61 // Checks for fields beyond |flags|:
62
63 // (Nothing here yet.)
64
65 return MOJO_RESULT_OK;
66 }
67
35 void MessagePipeDispatcher::Init(scoped_refptr<MessagePipe> message_pipe, 68 void MessagePipeDispatcher::Init(scoped_refptr<MessagePipe> message_pipe,
36 unsigned port) { 69 unsigned port) {
37 DCHECK(message_pipe); 70 DCHECK(message_pipe);
38 DCHECK(port == 0 || port == 1); 71 DCHECK(port == 0 || port == 1);
39 72
40 message_pipe_ = message_pipe; 73 message_pipe_ = message_pipe;
41 port_ = port; 74 port_ = port;
42 } 75 }
43 76
44 Dispatcher::Type MessagePipeDispatcher::GetType() const { 77 Dispatcher::Type MessagePipeDispatcher::GetType() const {
45 return kTypeMessagePipe; 78 return kTypeMessagePipe;
46 } 79 }
47 80
48 // static 81 // static
49 std::pair<scoped_refptr<MessagePipeDispatcher>, scoped_refptr<MessagePipe> > 82 std::pair<scoped_refptr<MessagePipeDispatcher>, scoped_refptr<MessagePipe> >
50 MessagePipeDispatcher::CreateRemoteMessagePipe() { 83 MessagePipeDispatcher::CreateRemoteMessagePipe() {
51 scoped_refptr<MessagePipe> message_pipe( 84 scoped_refptr<MessagePipe> message_pipe(
52 new MessagePipe( 85 new MessagePipe(
53 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()), 86 scoped_ptr<MessagePipeEndpoint>(new LocalMessagePipeEndpoint()),
54 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint()))); 87 scoped_ptr<MessagePipeEndpoint>(new ProxyMessagePipeEndpoint())));
55 scoped_refptr<MessagePipeDispatcher> dispatcher(new MessagePipeDispatcher()); 88 scoped_refptr<MessagePipeDispatcher> dispatcher(new MessagePipeDispatcher(
89 MessagePipeDispatcher::kDefaultCreateOptions));
56 dispatcher->Init(message_pipe, 0); 90 dispatcher->Init(message_pipe, 0);
57 91
58 return std::make_pair(dispatcher, message_pipe); 92 return std::make_pair(dispatcher, message_pipe);
59 } 93 }
60 94
61 // static 95 // static
62 scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize( 96 scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize(
63 Channel* channel, 97 Channel* channel,
64 const void* source, 98 const void* source,
65 size_t size) { 99 size_t size) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 lock().AssertAcquired(); 160 lock().AssertAcquired();
127 message_pipe_->Close(port_); 161 message_pipe_->Close(port_);
128 message_pipe_ = NULL; 162 message_pipe_ = NULL;
129 port_ = kInvalidPort; 163 port_ = kInvalidPort;
130 } 164 }
131 165
132 scoped_refptr<Dispatcher> 166 scoped_refptr<Dispatcher>
133 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { 167 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
134 lock().AssertAcquired(); 168 lock().AssertAcquired();
135 169
136 scoped_refptr<MessagePipeDispatcher> rv = new MessagePipeDispatcher(); 170 // TODO(vtl): Currently, there are no options, so we just use
171 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options
172 // too.
173 scoped_refptr<MessagePipeDispatcher> rv =
174 new MessagePipeDispatcher(kDefaultCreateOptions);
137 rv->Init(message_pipe_, port_); 175 rv->Init(message_pipe_, port_);
138 message_pipe_ = NULL; 176 message_pipe_ = NULL;
139 port_ = kInvalidPort; 177 port_ = kInvalidPort;
140 return scoped_refptr<Dispatcher>(rv.get()); 178 return scoped_refptr<Dispatcher>(rv.get());
141 } 179 }
142 180
143 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( 181 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock(
144 const void* bytes, 182 const void* bytes,
145 uint32_t num_bytes, 183 uint32_t num_bytes,
146 std::vector<DispatcherTransport>* transports, 184 std::vector<DispatcherTransport>* transports,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 272
235 // MessagePipeDispatcherTransport ---------------------------------------------- 273 // MessagePipeDispatcherTransport ----------------------------------------------
236 274
237 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( 275 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport(
238 DispatcherTransport transport) : DispatcherTransport(transport) { 276 DispatcherTransport transport) : DispatcherTransport(transport) {
239 DCHECK_EQ(message_pipe_dispatcher()->GetType(), Dispatcher::kTypeMessagePipe); 277 DCHECK_EQ(message_pipe_dispatcher()->GetType(), Dispatcher::kTypeMessagePipe);
240 } 278 }
241 279
242 } // namespace system 280 } // namespace system
243 } // namespace mojo 281 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/message_pipe_dispatcher.h ('k') | mojo/system/message_pipe_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698