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

Side by Side Diff: mojo/edk/system/channel.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/channel.h ('k') | mojo/edk/system/channel_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/channel.h" 5 #include "mojo/edk/system/channel.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // There must not be an endpoint with that ID already. 118 // There must not be an endpoint with that ID already.
119 DCHECK(local_id_to_endpoint_map_.find(local_id) == 119 DCHECK(local_id_to_endpoint_map_.find(local_id) ==
120 local_id_to_endpoint_map_.end()); 120 local_id_to_endpoint_map_.end());
121 121
122 local_id_to_endpoint_map_[local_id] = endpoint; 122 local_id_to_endpoint_map_[local_id] = endpoint;
123 } 123 }
124 124
125 endpoint->AttachAndRun(this, local_id, remote_id); 125 endpoint->AttachAndRun(this, local_id, remote_id);
126 } 126 }
127 127
128 bool Channel::WriteMessage(scoped_ptr<MessageInTransit> message) { 128 bool Channel::WriteMessage(std::unique_ptr<MessageInTransit> message) {
129 MutexLocker locker(&mutex_); 129 MutexLocker locker(&mutex_);
130 if (!is_running_) { 130 if (!is_running_) {
131 // TODO(vtl): I think this is probably not an error condition, but I should 131 // TODO(vtl): I think this is probably not an error condition, but I should
132 // think about it (and the shutdown sequence) more carefully. 132 // think about it (and the shutdown sequence) more carefully.
133 LOG(WARNING) << "WriteMessage() after shutdown"; 133 LOG(WARNING) << "WriteMessage() after shutdown";
134 return false; 134 return false;
135 } 135 }
136 136
137 DLOG_IF(WARNING, is_shutting_down_) << "WriteMessage() while shutting down"; 137 DLOG_IF(WARNING, is_shutting_down_) << "WriteMessage() while shutting down";
138 return raw_channel_->WriteMessage(message.Pass()); 138 return raw_channel_->WriteMessage(std::move(message));
139 } 139 }
140 140
141 bool Channel::IsWriteBufferEmpty() { 141 bool Channel::IsWriteBufferEmpty() {
142 MutexLocker locker(&mutex_); 142 MutexLocker locker(&mutex_);
143 if (!is_running_) 143 if (!is_running_)
144 return true; 144 return true;
145 return raw_channel_->IsWriteBufferEmpty(); 145 return raw_channel_->IsWriteBufferEmpty();
146 } 146 }
147 147
148 void Channel::DetachEndpoint(ChannelEndpoint* endpoint, 148 void Channel::DetachEndpoint(ChannelEndpoint* endpoint,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 "Received a message for nonexistent local destination ID %u", 384 "Received a message for nonexistent local destination ID %u",
385 static_cast<unsigned>(local_id.value())).c_str()); 385 static_cast<unsigned>(local_id.value())).c_str());
386 // This is strongly indicative of some problem. However, it's not a fatal 386 // This is strongly indicative of some problem. However, it's not a fatal
387 // error, since it may indicate a buggy (or hostile) remote process. Don't 387 // error, since it may indicate a buggy (or hostile) remote process. Don't
388 // die even for Debug builds, since handling this properly needs to be 388 // die even for Debug builds, since handling this properly needs to be
389 // tested (TODO(vtl)). 389 // tested (TODO(vtl)).
390 DLOG(ERROR) << "This should not happen under normal operation."; 390 DLOG(ERROR) << "This should not happen under normal operation.";
391 return; 391 return;
392 } 392 }
393 393
394 scoped_ptr<MessageInTransit> message(new MessageInTransit(message_view)); 394 std::unique_ptr<MessageInTransit> message(new MessageInTransit(message_view));
395 if (message_view.transport_data_buffer_size() > 0) { 395 if (message_view.transport_data_buffer_size() > 0) {
396 DCHECK(message_view.transport_data_buffer()); 396 DCHECK(message_view.transport_data_buffer());
397 message->SetDispatchers(TransportData::DeserializeDispatchers( 397 message->SetDispatchers(TransportData::DeserializeDispatchers(
398 message_view.transport_data_buffer(), 398 message_view.transport_data_buffer(),
399 message_view.transport_data_buffer_size(), platform_handles.Pass(), 399 message_view.transport_data_buffer_size(), platform_handles.Pass(),
400 this)); 400 this));
401 } 401 }
402 402
403 endpoint->OnReadMessage(message.Pass()); 403 endpoint->OnReadMessage(std::move(message));
404 } 404 }
405 405
406 void Channel::OnReadMessageForChannel( 406 void Channel::OnReadMessageForChannel(
407 const MessageInTransit::View& message_view, 407 const MessageInTransit::View& message_view,
408 embedder::ScopedPlatformHandleVectorPtr platform_handles) { 408 embedder::ScopedPlatformHandleVectorPtr platform_handles) {
409 DCHECK(creation_thread_checker_.CalledOnValidThread()); 409 DCHECK(creation_thread_checker_.CalledOnValidThread());
410 DCHECK_EQ(message_view.type(), MessageInTransit::Type::CHANNEL); 410 DCHECK_EQ(message_view.type(), MessageInTransit::Type::CHANNEL);
411 411
412 // Currently, no channel messages take platform handles. 412 // Currently, no channel messages take platform handles.
413 if (platform_handles) { 413 if (platform_handles) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 return remote_id; 617 return remote_id;
618 } 618 }
619 619
620 bool Channel::SendControlMessage(MessageInTransit::Subtype subtype, 620 bool Channel::SendControlMessage(MessageInTransit::Subtype subtype,
621 ChannelEndpointId local_id, 621 ChannelEndpointId local_id,
622 ChannelEndpointId remote_id, 622 ChannelEndpointId remote_id,
623 uint32_t num_bytes, 623 uint32_t num_bytes,
624 const void* bytes) { 624 const void* bytes) {
625 DVLOG(2) << "Sending channel control message: subtype " << subtype 625 DVLOG(2) << "Sending channel control message: subtype " << subtype
626 << ", local ID " << local_id << ", remote ID " << remote_id; 626 << ", local ID " << local_id << ", remote ID " << remote_id;
627 scoped_ptr<MessageInTransit> message(new MessageInTransit( 627 std::unique_ptr<MessageInTransit> message(new MessageInTransit(
628 MessageInTransit::Type::CHANNEL, subtype, num_bytes, bytes)); 628 MessageInTransit::Type::CHANNEL, subtype, num_bytes, bytes));
629 message->set_source_id(local_id); 629 message->set_source_id(local_id);
630 message->set_destination_id(remote_id); 630 message->set_destination_id(remote_id);
631 return WriteMessage(message.Pass()); 631 return WriteMessage(std::move(message));
632 } 632 }
633 633
634 } // namespace system 634 } // namespace system
635 } // namespace mojo 635 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.h ('k') | mojo/edk/system/channel_endpoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698