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

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

Issue 1396783004: Convert mojo::system::ChannelEndpointClient to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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
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/edk/system/message_pipe_dispatcher.h" 5 #include "mojo/edk/system/message_pipe_dispatcher.h"
6 6
7 #include <utility>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "mojo/edk/system/configuration.h" 10 #include "mojo/edk/system/configuration.h"
9 #include "mojo/edk/system/local_message_pipe_endpoint.h" 11 #include "mojo/edk/system/local_message_pipe_endpoint.h"
10 #include "mojo/edk/system/memory.h" 12 #include "mojo/edk/system/memory.h"
11 #include "mojo/edk/system/message_pipe.h" 13 #include "mojo/edk/system/message_pipe.h"
12 #include "mojo/edk/system/options_validation.h" 14 #include "mojo/edk/system/options_validation.h"
13 #include "mojo/edk/system/proxy_message_pipe_endpoint.h" 15 #include "mojo/edk/system/proxy_message_pipe_endpoint.h"
14 16
15 namespace mojo { 17 namespace mojo {
16 namespace system { 18 namespace system {
(...skipping 29 matching lines...) Expand all
46 return MOJO_RESULT_UNIMPLEMENTED; 48 return MOJO_RESULT_UNIMPLEMENTED;
47 out_options->flags = reader.options().flags; 49 out_options->flags = reader.options().flags;
48 50
49 // Checks for fields beyond |flags|: 51 // Checks for fields beyond |flags|:
50 52
51 // (Nothing here yet.) 53 // (Nothing here yet.)
52 54
53 return MOJO_RESULT_OK; 55 return MOJO_RESULT_OK;
54 } 56 }
55 57
56 void MessagePipeDispatcher::Init(scoped_refptr<MessagePipe> message_pipe, 58 void MessagePipeDispatcher::Init(RefPtr<MessagePipe>&& message_pipe,
57 unsigned port) { 59 unsigned port) {
58 DCHECK(message_pipe); 60 DCHECK(message_pipe);
59 DCHECK(port == 0 || port == 1); 61 DCHECK(port == 0 || port == 1);
60 62
61 message_pipe_ = message_pipe; 63 message_pipe_ = std::move(message_pipe);
62 port_ = port; 64 port_ = port;
63 } 65 }
64 66
65 Dispatcher::Type MessagePipeDispatcher::GetType() const { 67 Dispatcher::Type MessagePipeDispatcher::GetType() const {
66 return Type::MESSAGE_PIPE; 68 return Type::MESSAGE_PIPE;
67 } 69 }
68 70
69 // static 71 // static
70 scoped_refptr<MessagePipeDispatcher> 72 scoped_refptr<MessagePipeDispatcher>
71 MessagePipeDispatcher::CreateRemoteMessagePipe( 73 MessagePipeDispatcher::CreateRemoteMessagePipe(
72 RefPtr<ChannelEndpoint>* channel_endpoint) { 74 RefPtr<ChannelEndpoint>* channel_endpoint) {
73 scoped_refptr<MessagePipe> message_pipe( 75 auto message_pipe = MessagePipe::CreateLocalProxy(channel_endpoint);
74 MessagePipe::CreateLocalProxy(channel_endpoint));
75 scoped_refptr<MessagePipeDispatcher> dispatcher = 76 scoped_refptr<MessagePipeDispatcher> dispatcher =
76 Create(kDefaultCreateOptions); 77 Create(kDefaultCreateOptions);
77 dispatcher->Init(message_pipe, 0); 78 dispatcher->Init(std::move(message_pipe), 0);
78 return dispatcher; 79 return dispatcher;
79 } 80 }
80 81
81 // static 82 // static
82 scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize( 83 scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize(
83 Channel* channel, 84 Channel* channel,
84 const void* source, 85 const void* source,
85 size_t size) { 86 size_t size) {
86 unsigned port = kInvalidPort; 87 unsigned port = kInvalidPort;
87 scoped_refptr<MessagePipe> message_pipe; 88 RefPtr<MessagePipe> message_pipe;
88 if (!MessagePipe::Deserialize(channel, source, size, &message_pipe, &port)) 89 if (!MessagePipe::Deserialize(channel, source, size, &message_pipe, &port))
89 return nullptr; 90 return nullptr;
90 DCHECK(message_pipe); 91 DCHECK(message_pipe);
91 DCHECK(port == 0 || port == 1); 92 DCHECK(port == 0 || port == 1);
92 93
93 scoped_refptr<MessagePipeDispatcher> dispatcher = 94 scoped_refptr<MessagePipeDispatcher> dispatcher =
94 Create(kDefaultCreateOptions); 95 Create(kDefaultCreateOptions);
95 dispatcher->Init(message_pipe, port); 96 dispatcher->Init(std::move(message_pipe), port);
96 return dispatcher; 97 return dispatcher;
97 } 98 }
98 99
99 MessagePipeDispatcher::MessagePipeDispatcher() : port_(kInvalidPort) { 100 MessagePipeDispatcher::MessagePipeDispatcher() : port_(kInvalidPort) {
100 } 101 }
101 102
102 MessagePipeDispatcher::~MessagePipeDispatcher() { 103 MessagePipeDispatcher::~MessagePipeDispatcher() {
103 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. 104 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe.
104 DCHECK(!message_pipe_); 105 DCHECK(!message_pipe_);
105 } 106 }
(...skipping 21 matching lines...) Expand all
127 } 128 }
128 129
129 scoped_refptr<Dispatcher> 130 scoped_refptr<Dispatcher>
130 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { 131 MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
131 mutex().AssertHeld(); 132 mutex().AssertHeld();
132 133
133 // TODO(vtl): Currently, there are no options, so we just use 134 // TODO(vtl): Currently, there are no options, so we just use
134 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options 135 // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options
135 // too. 136 // too.
136 scoped_refptr<MessagePipeDispatcher> rv = Create(kDefaultCreateOptions); 137 scoped_refptr<MessagePipeDispatcher> rv = Create(kDefaultCreateOptions);
137 rv->Init(message_pipe_, port_); 138 rv->Init(std::move(message_pipe_), port_);
138 message_pipe_ = nullptr;
139 port_ = kInvalidPort; 139 port_ = kInvalidPort;
140 return scoped_refptr<Dispatcher>(rv.get()); 140 return scoped_refptr<Dispatcher>(rv.get());
141 } 141 }
142 142
143 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock( 143 MojoResult MessagePipeDispatcher::WriteMessageImplNoLock(
144 UserPointer<const void> bytes, 144 UserPointer<const void> bytes,
145 uint32_t num_bytes, 145 uint32_t num_bytes,
146 std::vector<DispatcherTransport>* transports, 146 std::vector<DispatcherTransport>* transports,
147 MojoWriteMessageFlags flags) { 147 MojoWriteMessageFlags flags) {
148 DCHECK(!transports || 148 DCHECK(!transports ||
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 219
220 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( 220 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport(
221 DispatcherTransport transport) 221 DispatcherTransport transport)
222 : DispatcherTransport(transport) { 222 : DispatcherTransport(transport) {
223 DCHECK_EQ(message_pipe_dispatcher()->GetType(), 223 DCHECK_EQ(message_pipe_dispatcher()->GetType(),
224 Dispatcher::Type::MESSAGE_PIPE); 224 Dispatcher::Type::MESSAGE_PIPE);
225 } 225 }
226 226
227 } // namespace system 227 } // namespace system
228 } // namespace mojo 228 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.h ('k') | mojo/edk/system/message_pipe_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698