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

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

Issue 1353683005: EDK: Convert remaining scoped_ptr -> std::unique_ptr in //mojo/edk/system. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 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_pipe.h ('k') | mojo/edk/system/message_pipe_endpoint.h » ('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/edk/system/message_pipe.h" 5 #include "mojo/edk/system/message_pipe.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "mojo/edk/system/channel.h" 11 #include "mojo/edk/system/channel.h"
11 #include "mojo/edk/system/channel_endpoint.h" 12 #include "mojo/edk/system/channel_endpoint.h"
12 #include "mojo/edk/system/channel_endpoint_id.h" 13 #include "mojo/edk/system/channel_endpoint_id.h"
13 #include "mojo/edk/system/incoming_endpoint.h" 14 #include "mojo/edk/system/incoming_endpoint.h"
14 #include "mojo/edk/system/local_message_pipe_endpoint.h" 15 #include "mojo/edk/system/local_message_pipe_endpoint.h"
15 #include "mojo/edk/system/message_in_transit.h" 16 #include "mojo/edk/system/message_in_transit.h"
16 #include "mojo/edk/system/message_pipe_dispatcher.h" 17 #include "mojo/edk/system/message_pipe_dispatcher.h"
17 #include "mojo/edk/system/message_pipe_endpoint.h" 18 #include "mojo/edk/system/message_pipe_endpoint.h"
18 #include "mojo/edk/system/proxy_message_pipe_endpoint.h" 19 #include "mojo/edk/system/proxy_message_pipe_endpoint.h"
20 #include "mojo/edk/util/make_unique.h"
19 21
20 namespace mojo { 22 namespace mojo {
21 namespace system { 23 namespace system {
22 24
23 // static 25 // static
24 MessagePipe* MessagePipe::CreateLocalLocal() MOJO_NO_THREAD_SAFETY_ANALYSIS { 26 MessagePipe* MessagePipe::CreateLocalLocal() MOJO_NO_THREAD_SAFETY_ANALYSIS {
25 MessagePipe* message_pipe = new MessagePipe(); 27 MessagePipe* message_pipe = new MessagePipe();
26 message_pipe->endpoints_[0].reset(new LocalMessagePipeEndpoint()); 28 message_pipe->endpoints_[0].reset(new LocalMessagePipeEndpoint());
27 message_pipe->endpoints_[1].reset(new LocalMessagePipeEndpoint()); 29 message_pipe->endpoints_[1].reset(new LocalMessagePipeEndpoint());
28 return message_pipe; 30 return message_pipe;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 unsigned port, 150 unsigned port,
149 UserPointer<const void> bytes, 151 UserPointer<const void> bytes,
150 uint32_t num_bytes, 152 uint32_t num_bytes,
151 std::vector<DispatcherTransport>* transports, 153 std::vector<DispatcherTransport>* transports,
152 MojoWriteMessageFlags flags) { 154 MojoWriteMessageFlags flags) {
153 DCHECK(port == 0 || port == 1); 155 DCHECK(port == 0 || port == 1);
154 156
155 MutexLocker locker(&mutex_); 157 MutexLocker locker(&mutex_);
156 return EnqueueMessageNoLock( 158 return EnqueueMessageNoLock(
157 GetPeerPort(port), 159 GetPeerPort(port),
158 make_scoped_ptr(new MessageInTransit( 160 util::MakeUnique<MessageInTransit>(
159 MessageInTransit::Type::ENDPOINT_CLIENT, 161 MessageInTransit::Type::ENDPOINT_CLIENT,
160 MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, num_bytes, bytes)), 162 MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, num_bytes, bytes),
161 transports); 163 transports);
162 } 164 }
163 165
164 MojoResult MessagePipe::ReadMessage(unsigned port, 166 MojoResult MessagePipe::ReadMessage(unsigned port,
165 UserPointer<void> bytes, 167 UserPointer<void> bytes,
166 UserPointer<uint32_t> num_bytes, 168 UserPointer<uint32_t> num_bytes,
167 DispatcherVector* dispatchers, 169 DispatcherVector* dispatchers,
168 uint32_t* num_dispatchers, 170 uint32_t* num_dispatchers,
169 MojoReadMessageFlags flags) { 171 MojoReadMessageFlags flags) {
170 DCHECK(port == 0 || port == 1); 172 DCHECK(port == 0 || port == 1);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // |ChannelEndpoint::ReplaceClient()|, in which case we reject the message, 288 // |ChannelEndpoint::ReplaceClient()|, in which case we reject the message,
287 // and the |ChannelEndpoint| can retry (calling the new client's 289 // and the |ChannelEndpoint| can retry (calling the new client's
288 // |OnReadMessage()|). 290 // |OnReadMessage()|).
289 return false; 291 return false;
290 } 292 }
291 293
292 // This is called when the |ChannelEndpoint| for the 294 // This is called when the |ChannelEndpoint| for the
293 // |ProxyMessagePipeEndpoint| |port| receives a message (from the |Channel|). 295 // |ProxyMessagePipeEndpoint| |port| receives a message (from the |Channel|).
294 // We need to pass this message on to its peer port (typically a 296 // We need to pass this message on to its peer port (typically a
295 // |LocalMessagePipeEndpoint|). 297 // |LocalMessagePipeEndpoint|).
296 MojoResult result = EnqueueMessageNoLock(GetPeerPort(port), 298 MojoResult result = EnqueueMessageNoLock(
297 make_scoped_ptr(message), nullptr); 299 GetPeerPort(port), std::unique_ptr<MessageInTransit>(message), nullptr);
298 DLOG_IF(WARNING, result != MOJO_RESULT_OK) 300 DLOG_IF(WARNING, result != MOJO_RESULT_OK)
299 << "EnqueueMessageNoLock() failed (result = " << result << ")"; 301 << "EnqueueMessageNoLock() failed (result = " << result << ")";
300 return true; 302 return true;
301 } 303 }
302 304
303 void MessagePipe::OnDetachFromChannel(unsigned port) { 305 void MessagePipe::OnDetachFromChannel(unsigned port) {
304 Close(port); 306 Close(port);
305 } 307 }
306 308
307 MessagePipe::MessagePipe() { 309 MessagePipe::MessagePipe() {
308 } 310 }
309 311
310 MessagePipe::~MessagePipe() { 312 MessagePipe::~MessagePipe() {
311 // Owned by the dispatchers. The owning dispatchers should only release us via 313 // Owned by the dispatchers. The owning dispatchers should only release us via
312 // their |Close()| method, which should inform us of being closed via our 314 // their |Close()| method, which should inform us of being closed via our
313 // |Close()|. Thus these should already be null. 315 // |Close()|. Thus these should already be null.
314 DCHECK(!endpoints_[0]); 316 DCHECK(!endpoints_[0]);
315 DCHECK(!endpoints_[1]); 317 DCHECK(!endpoints_[1]);
316 } 318 }
317 319
318 MojoResult MessagePipe::EnqueueMessageNoLock( 320 MojoResult MessagePipe::EnqueueMessageNoLock(
319 unsigned port, 321 unsigned port,
320 scoped_ptr<MessageInTransit> message, 322 std::unique_ptr<MessageInTransit> message,
321 std::vector<DispatcherTransport>* transports) { 323 std::vector<DispatcherTransport>* transports) {
322 DCHECK(port == 0 || port == 1); 324 DCHECK(port == 0 || port == 1);
323 DCHECK(message); 325 DCHECK(message);
324 326
325 DCHECK_EQ(message->type(), MessageInTransit::Type::ENDPOINT_CLIENT); 327 DCHECK_EQ(message->type(), MessageInTransit::Type::ENDPOINT_CLIENT);
326 DCHECK(endpoints_[GetPeerPort(port)]); 328 DCHECK(endpoints_[GetPeerPort(port)]);
327 329
328 // The destination port need not be open, unlike the source port. 330 // The destination port need not be open, unlike the source port.
329 if (!endpoints_[port]) 331 if (!endpoints_[port])
330 return MOJO_RESULT_FAILED_PRECONDITION; 332 return MOJO_RESULT_FAILED_PRECONDITION;
331 333
332 if (transports) { 334 if (transports) {
333 MojoResult result = AttachTransportsNoLock(port, message.get(), transports); 335 MojoResult result = AttachTransportsNoLock(port, message.get(), transports);
334 if (result != MOJO_RESULT_OK) 336 if (result != MOJO_RESULT_OK)
335 return result; 337 return result;
336 } 338 }
337 339
338 // The endpoint's |EnqueueMessage()| may not report failure. 340 // The endpoint's |EnqueueMessage()| may not report failure.
339 endpoints_[port]->EnqueueMessage(message.Pass()); 341 endpoints_[port]->EnqueueMessage(std::move(message));
340 return MOJO_RESULT_OK; 342 return MOJO_RESULT_OK;
341 } 343 }
342 344
343 MojoResult MessagePipe::AttachTransportsNoLock( 345 MojoResult MessagePipe::AttachTransportsNoLock(
344 unsigned port, 346 unsigned port,
345 MessageInTransit* message, 347 MessageInTransit* message,
346 std::vector<DispatcherTransport>* transports) { 348 std::vector<DispatcherTransport>* transports) {
347 DCHECK(!message->has_dispatchers()); 349 DCHECK(!message->has_dispatchers());
348 350
349 // You're not allowed to send either handle to a message pipe over the message 351 // You're not allowed to send either handle to a message pipe over the message
(...skipping 29 matching lines...) Expand all
379 LOG(WARNING) << "Enqueueing null dispatcher"; 381 LOG(WARNING) << "Enqueueing null dispatcher";
380 dispatchers->push_back(nullptr); 382 dispatchers->push_back(nullptr);
381 } 383 }
382 } 384 }
383 message->SetDispatchers(std::move(dispatchers)); 385 message->SetDispatchers(std::move(dispatchers));
384 return MOJO_RESULT_OK; 386 return MOJO_RESULT_OK;
385 } 387 }
386 388
387 } // namespace system 389 } // namespace system
388 } // namespace mojo 390 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe.h ('k') | mojo/edk/system/message_pipe_endpoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698