0

Convert Pass()→std::move() in //mojo/edk

BUG=557422
R=avi@chromium.org
TBR=ben@chromium.org

Review URL: https://codereview.chromium.org/1529303004

Cr-Commit-Position: refs/heads/master@{#366167}
This commit is contained in:
dcheng
2015-12-18 13:07:16 -08:00
committed by Commit bot
parent 60b2cdd0d6
commit 2a370ee932
29 changed files with 225 additions and 197 deletions

@ -4,6 +4,8 @@
#include "mojo/edk/embedder/embedder.h"
#include <utility>
#include "base/atomicops.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
@ -64,11 +66,11 @@ ScopedPlatformHandle ChildProcessLaunched(base::ProcessHandle child_process) {
void ChildProcessLaunched(base::ProcessHandle child_process,
ScopedPlatformHandle server_pipe) {
new ChildBrokerHost(child_process, server_pipe.Pass());
new ChildBrokerHost(child_process, std::move(server_pipe));
}
void SetParentPipeHandle(ScopedPlatformHandle pipe) {
ChildBroker::GetInstance()->SetChildBrokerHostHandle(pipe.Pass());
ChildBroker::GetInstance()->SetChildBrokerHostHandle(std::move(pipe));
}
void Init() {
@ -96,7 +98,7 @@ MojoResult CreatePlatformHandleWrapper(
DCHECK(platform_handle_wrapper_handle);
scoped_refptr<Dispatcher> dispatcher =
PlatformHandleDispatcher::Create(platform_handle.Pass());
PlatformHandleDispatcher::Create(std::move(platform_handle));
DCHECK(internal::g_core);
MojoHandle h = internal::g_core->AddDispatcher(dispatcher);
@ -123,10 +125,8 @@ MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
if (dispatcher->GetType() != Dispatcher::Type::PLATFORM_HANDLE)
return MOJO_RESULT_INVALID_ARGUMENT;
*platform_handle =
static_cast<PlatformHandleDispatcher*>(dispatcher.get())
->PassPlatformHandle()
.Pass();
*platform_handle = static_cast<PlatformHandleDispatcher*>(dispatcher.get())
->PassPlatformHandle();
return MOJO_RESULT_OK;
}
@ -157,11 +157,11 @@ ScopedMessagePipeHandle CreateMessagePipe(
ScopedMessagePipeHandle rv(
MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));
CHECK(rv.is_valid());
dispatcher->Init(platform_handle.Pass(), nullptr, 0, nullptr, 0, nullptr,
dispatcher->Init(std::move(platform_handle), nullptr, 0, nullptr, 0, nullptr,
nullptr);
// TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it
// once that's fixed.
return rv.Pass();
return rv;
}
} // namespace edk

@ -4,6 +4,8 @@
#include "mojo/edk/embedder/embedder.h"
#include <utility>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
@ -357,9 +359,11 @@ TEST_F(EmbedderTest, MAYBE_MultiprocessChannels) {
multiprocess_test_helper.StartChild("MultiprocessChannelsClient");
{
MojoHandle server_mp = CreateMessagePipe(
multiprocess_test_helper.server_platform_handle.Pass()).release().
value();
MojoHandle server_mp =
CreateMessagePipe(
std::move(multiprocess_test_helper.server_platform_handle))
.release()
.value();
// 1. Write a message to |server_mp| (attaching nothing).
const char kHello[] = "hello";
@ -465,11 +469,11 @@ TEST_F(EmbedderTest, MAYBE_MultiprocessChannels) {
MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
ScopedPlatformHandle client_platform_handle =
test::MultiprocessTestHelper::client_platform_handle.Pass();
std::move(test::MultiprocessTestHelper::client_platform_handle);
EXPECT_TRUE(client_platform_handle.is_valid());
MojoHandle client_mp = CreateMessagePipe(
client_platform_handle.Pass()).release().value();
MojoHandle client_mp =
CreateMessagePipe(std::move(client_platform_handle)).release().value();
// 1. Read the first message from |client_mp|.
MojoHandleSignalsState state;

@ -4,6 +4,8 @@
#include "mojo/edk/embedder/platform_channel_pair.h"
#include <utility>
#include "base/logging.h"
namespace mojo {
@ -16,11 +18,11 @@ PlatformChannelPair::~PlatformChannelPair() {
}
ScopedPlatformHandle PlatformChannelPair::PassServerHandle() {
return server_handle_.Pass();
return std::move(server_handle_);
}
ScopedPlatformHandle PlatformChannelPair::PassClientHandle() {
return client_handle_.Pass();
return std::move(client_handle_);
}
void PlatformChannelPair::ChildProcessLaunched() {

@ -12,8 +12,8 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <deque>
#include <utility>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@ -64,8 +64,8 @@ class PlatformChannelPairPosixTest : public testing::Test {
TEST_F(PlatformChannelPairPosixTest, NoSigPipe) {
PlatformChannelPair channel_pair;
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass();
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle();
// Write to the client.
static const char kHello[] = "hello";
@ -105,8 +105,8 @@ TEST_F(PlatformChannelPairPosixTest, NoSigPipe) {
TEST_F(PlatformChannelPairPosixTest, SendReceiveData) {
PlatformChannelPair channel_pair;
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass();
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle();
for (size_t i = 0; i < 10; i++) {
std::string send_string(1 << i, 'A' + i);
@ -134,8 +134,8 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) {
static const char kHello[] = "hello";
PlatformChannelPair channel_pair;
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass();
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle();
// Reduce the number of FDs opened on OS X to avoid test flake.
#if defined(OS_MACOSX)
@ -156,7 +156,7 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) {
ASSERT_TRUE(fp);
ASSERT_EQ(j, fwrite(std::string(j, c).data(), 1, j, fp.get()));
platform_handles->push_back(
test::PlatformHandleFromFILE(fp.Pass()).release());
test::PlatformHandleFromFILE(std::move(fp)).release());
ASSERT_TRUE(platform_handles->back().is_valid());
}
@ -200,8 +200,8 @@ TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) {
static const char kHello[] = "hello";
PlatformChannelPair channel_pair;
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass();
ScopedPlatformHandle server_handle = channel_pair.PassServerHandle();
ScopedPlatformHandle client_handle = channel_pair.PassClientHandle();
const std::string file_contents("hello world");
@ -214,7 +214,7 @@ TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) {
fwrite(file_contents.data(), 1, file_contents.size(), fp.get()));
ScopedPlatformHandleVectorPtr platform_handles(new PlatformHandleVector);
platform_handles->push_back(
test::PlatformHandleFromFILE(fp.Pass()).release());
test::PlatformHandleFromFILE(std::move(fp)).release());
ASSERT_TRUE(platform_handles->back().is_valid());
// Send the FD (+ "hello").

@ -4,6 +4,8 @@
#include "mojo/edk/embedder/simple_platform_shared_buffer.h"
#include <utility>
#include "base/logging.h"
#include "mojo/edk/embedder/platform_handle_utils.h"
@ -34,7 +36,7 @@ SimplePlatformSharedBuffer::CreateFromPlatformHandle(
DCHECK_GT(num_bytes, 0u);
SimplePlatformSharedBuffer* rv = new SimplePlatformSharedBuffer(num_bytes);
if (!rv->InitFromPlatformHandle(platform_handle.Pass())) {
if (!rv->InitFromPlatformHandle(std::move(platform_handle))) {
// We can't just delete it directly, due to the "in destructor" (debug)
// check.
scoped_refptr<SimplePlatformSharedBuffer> deleter(rv);
@ -82,7 +84,7 @@ ScopedPlatformHandle SimplePlatformSharedBuffer::DuplicatePlatformHandle() {
ScopedPlatformHandle SimplePlatformSharedBuffer::PassPlatformHandle() {
DCHECK(HasOneRef());
return handle_.Pass();
return std::move(handle_);
}
SimplePlatformSharedBuffer::SimplePlatformSharedBuffer(size_t num_bytes)

@ -10,8 +10,8 @@
#include <sys/stat.h>
#include <sys/types.h> // For |off_t|.
#include <unistd.h>
#include <limits>
#include <utility>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@ -114,7 +114,7 @@ bool SimplePlatformSharedBuffer::InitFromPlatformHandle(
// TODO(vtl): More checks?
handle_ = platform_handle.Pass();
handle_ = std::move(platform_handle);
return true;
}

@ -179,8 +179,8 @@ TEST(SimplePlatformSharedBufferTest, MappingsOutliveBuffer) {
{
scoped_refptr<SimplePlatformSharedBuffer> buffer(
SimplePlatformSharedBuffer::Create(100));
mapping1 = buffer->Map(0, 100).Pass();
mapping2 = buffer->Map(50, 50).Pass();
mapping1 = buffer->Map(0, 100);
mapping2 = buffer->Map(50, 50);
static_cast<char*>(mapping1->GetBase())[50] = 'x';
}

@ -4,6 +4,8 @@
#include "mojo/edk/embedder/simple_platform_support.h"
#include <utility>
#include "base/rand_util.h"
#include "mojo/edk/embedder/simple_platform_shared_buffer.h"
@ -24,7 +26,7 @@ PlatformSharedBuffer* SimplePlatformSupport::CreateSharedBufferFromHandle(
size_t num_bytes,
ScopedPlatformHandle platform_handle) {
return SimplePlatformSharedBuffer::CreateFromPlatformHandle(
num_bytes, platform_handle.Pass());
num_bytes, std::move(platform_handle));
}
} // namespace edk

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "base/at_exit.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@ -98,8 +100,8 @@ js_to_cpp::EchoArgsPtr BuildSampleEchoArgs() {
string_array[0] = "one";
string_array[1] = "two";
string_array[2] = "three";
args->string_array = string_array.Pass();
return args.Pass();
args->string_array = std::move(string_array);
return args;
}
void CheckSampleEchoArgs(const js_to_cpp::EchoArgs& arg) {
@ -208,7 +210,7 @@ class CppSideConnection : public js_to_cpp::CppSide {
js_to_cpp::JsSide* js_side() { return js_side_; }
void Bind(InterfaceRequest<js_to_cpp::CppSide> request) {
binding_.Bind(request.Pass());
binding_.Bind(std::move(request));
// Keep the pipe open even after validation errors.
binding_.EnableTestingMode();
}
@ -378,7 +380,7 @@ class JsToCppTest : public testing::Test {
js_to_cpp::CppSidePtr cpp_side_ptr;
cpp_side->Bind(GetProxy(&cpp_side_ptr));
js_side->SetCppSide(cpp_side_ptr.Pass());
js_side->SetCppSide(std::move(cpp_side_ptr));
gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
gin::IsolateHolder::kStableV8Extras,

@ -4,6 +4,8 @@
#include "mojo/edk/system/child_broker.h"
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "mojo/edk/embedder/embedder_internal.h"
@ -22,7 +24,7 @@ ChildBroker* ChildBroker::GetInstance() {
void ChildBroker::SetChildBrokerHostHandle(ScopedPlatformHandle handle) {
ScopedPlatformHandle parent_async_channel_handle;
#if defined(OS_POSIX)
parent_async_channel_handle = handle.Pass();
parent_async_channel_handle = std::move(handle);
#else
// On Windows we have two pipes to the parent. The first is for the token
// exchange for creating and passing handles, since the child needs the
@ -119,7 +121,7 @@ void ChildBroker::ConnectMessagePipe(uint64_t pipe_id,
data.type = CANCEL_CONNECT_MESSAGE_PIPE;
scoped_ptr<MessageInTransit> message(new MessageInTransit(
MessageInTransit::Type::MESSAGE, sizeof(data), &data));
WriteAsyncMessage(message.Pass());
WriteAsyncMessage(std::move(message));
if (!in_process_pipes_channel1_) {
ScopedPlatformHandle server_handle, client_handle;
@ -131,10 +133,10 @@ void ChildBroker::ConnectMessagePipe(uint64_t pipe_id,
client_handle = channel_pair.PassClientHandle();
#endif
in_process_pipes_channel1_ = new RoutedRawChannel(
server_handle.Pass(),
std::move(server_handle),
base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
in_process_pipes_channel2_ = new RoutedRawChannel(
client_handle.Pass(),
std::move(client_handle),
base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
}
@ -149,7 +151,7 @@ void ChildBroker::ConnectMessagePipe(uint64_t pipe_id,
scoped_ptr<MessageInTransit> message(new MessageInTransit(
MessageInTransit::Type::MESSAGE, sizeof(data), &data));
pending_connects_[pipe_id] = message_pipe;
WriteAsyncMessage(message.Pass());
WriteAsyncMessage(std::move(message));
}
void ChildBroker::CloseMessagePipe(
@ -191,7 +193,7 @@ void ChildBroker::OnReadMessage(
CHECK(channels_.find(message->process_id) == channels_.end());
channels_[message->process_id] = new RoutedRawChannel(
handle.Pass(),
std::move(handle),
base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
} else if (type == PEER_PIPE_CONNECTED) {
DCHECK(!platform_handles);
@ -237,9 +239,9 @@ void ChildBroker::WriteAsyncMessage(scoped_ptr<MessageInTransit> message) {
DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread());
message->set_route_id(kBrokerRouteId);
if (parent_async_channel_) {
parent_async_channel_->channel()->WriteMessage(message.Pass());
parent_async_channel_->channel()->WriteMessage(std::move(message));
} else {
async_channel_queue_.AddMessage(message.Pass());
async_channel_queue_.AddMessage(std::move(message));
}
}
@ -248,7 +250,7 @@ void ChildBroker::InitAsyncChannel(
DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread());
parent_async_channel_ = new RoutedRawChannel(
parent_async_channel_handle.Pass() ,
std::move(parent_async_channel_handle),
base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
parent_async_channel_->AddRoute(kBrokerRouteId, this);
while (!async_channel_queue_.IsEmpty()) {

@ -4,6 +4,8 @@
#include "mojo/edk/system/child_broker_host.h"
#include <utility>
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "mojo/edk/embedder/embedder_internal.h"
@ -28,7 +30,7 @@ ChildBrokerHost::ChildBrokerHost(base::ProcessHandle child_process,
: process_id_(base::GetProcId(child_process)), child_channel_(nullptr) {
ScopedPlatformHandle parent_async_channel_handle;
#if defined(OS_POSIX)
parent_async_channel_handle = pipe.Pass();
parent_async_channel_handle = std::move(pipe);
#else
DuplicateHandle(GetCurrentProcess(), child_process,
GetCurrentProcess(), &child_process,
@ -75,14 +77,14 @@ void ChildBrokerHost::ConnectToProcess(base::ProcessId process_id,
scoped_ptr<MessageInTransit> message(new MessageInTransit(
MessageInTransit::Type::MESSAGE, sizeof(data), &data));
scoped_refptr<Dispatcher> dispatcher =
PlatformHandleDispatcher::Create(pipe.Pass());
PlatformHandleDispatcher::Create(std::move(pipe));
internal::g_core->AddDispatcher(dispatcher);
scoped_ptr<DispatcherVector> dispatchers(new DispatcherVector);
dispatchers->push_back(dispatcher);
message->SetDispatchers(dispatchers.Pass());
message->SetDispatchers(std::move(dispatchers));
message->SerializeAndCloseDispatchers();
message->set_route_id(kBrokerRouteId);
child_channel_->channel()->WriteMessage(message.Pass());
child_channel_->channel()->WriteMessage(std::move(message));
}
void ChildBrokerHost::ConnectMessagePipe(uint64_t pipe_id,
@ -96,7 +98,7 @@ void ChildBrokerHost::ConnectMessagePipe(uint64_t pipe_id,
scoped_ptr<MessageInTransit> message(new MessageInTransit(
MessageInTransit::Type::MESSAGE, sizeof(data), &data));
message->set_route_id(kBrokerRouteId);
child_channel_->channel()->WriteMessage(message.Pass());
child_channel_->channel()->WriteMessage(std::move(message));
}
ChildBrokerHost::~ChildBrokerHost() {
@ -109,7 +111,7 @@ ChildBrokerHost::~ChildBrokerHost() {
void ChildBrokerHost::InitOnIO(
ScopedPlatformHandle parent_async_channel_handle) {
child_channel_ = new RoutedRawChannel(
parent_async_channel_handle.Pass(),
std::move(parent_async_channel_handle),
base::Bind(&ChildBrokerHost::ChannelDestructed, base::Unretained(this)));
child_channel_->AddRoute(kBrokerRouteId, this);

@ -4,6 +4,7 @@
#include "mojo/edk/system/core.h"
#include <utility>
#include <vector>
#include "base/containers/stack_container.h"
@ -293,10 +294,10 @@ MojoResult Core::CreateMessagePipe(
server_handle = channel_pair.PassServerHandle();
client_handle = channel_pair.PassClientHandle();
#endif
dispatcher0->Init(server_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr,
nullptr);
dispatcher1->Init(client_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr,
nullptr);
dispatcher0->Init(std::move(server_handle), nullptr, 0u, nullptr, 0u,
nullptr, nullptr);
dispatcher1->Init(std::move(client_handle), nullptr, 0u, nullptr, 0u,
nullptr, nullptr);
} else {
uint64_t pipe_id = 0;
// route_id 0 is used internally in RoutedRawChannel. See kInternalRouteId
@ -471,8 +472,8 @@ MojoResult Core::CreateDataPipe(
server_handle = channel_pair.PassServerHandle();
client_handle = channel_pair.PassClientHandle();
#endif
producer_dispatcher->Init(server_handle.Pass(), nullptr, 0u);
consumer_dispatcher->Init(client_handle.Pass(), nullptr, 0u);
producer_dispatcher->Init(std::move(server_handle), nullptr, 0u);
consumer_dispatcher->Init(std::move(client_handle), nullptr, 0u);
*data_pipe_producer_handle = handle_pair.first;
*data_pipe_consumer_handle = handle_pair.second;
@ -618,7 +619,7 @@ MojoResult Core::MapBuffer(MojoHandle buffer_handle,
void* address = mapping->GetBase();
{
base::AutoLock locker(mapping_table_lock_);
result = mapping_table_.AddMapping(mapping.Pass());
result = mapping_table_.AddMapping(std::move(mapping));
}
if (result != MOJO_RESULT_OK)
return result;

@ -5,6 +5,7 @@
#include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
#include <algorithm>
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
@ -26,7 +27,7 @@ void DataPipeConsumerDispatcher::Init(
ScopedPlatformHandle message_pipe,
char* serialized_read_buffer, size_t serialized_read_buffer_size) {
if (message_pipe.is_valid()) {
channel_ = RawChannel::Create(message_pipe.Pass());
channel_ = RawChannel::Create(std::move(message_pipe));
channel_->SetSerializedData(
serialized_read_buffer, serialized_read_buffer_size, nullptr, 0u,
nullptr, nullptr);
@ -82,7 +83,7 @@ DataPipeConsumerDispatcher::Deserialize(
scoped_ptr<PlatformSharedBufferMapping> mapping;
if (shared_memory_size) {
shared_buffer = internal::g_platform_support->CreateSharedBufferFromHandle(
shared_memory_size, shared_memory_handle.Pass());
shared_memory_size, std::move(shared_memory_handle));
mapping = shared_buffer->Map(0, shared_memory_size);
char* buffer = static_cast<char*>(mapping->GetBase());
SharedMemoryHeader* header = reinterpret_cast<SharedMemoryHeader*>(buffer);
@ -99,7 +100,7 @@ DataPipeConsumerDispatcher::Deserialize(
}
}
rv->Init(platform_handle.Pass(), serialized_read_buffer,
rv->Init(std::move(platform_handle), serialized_read_buffer,
serialized_read_buffer_size);
return rv;
}
@ -143,7 +144,7 @@ DataPipeConsumerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
scoped_refptr<DataPipeConsumerDispatcher> rv = Create(options_);
data_.swap(rv->data_);
serialized_read_buffer_.swap(rv->serialized_read_buffer_);
rv->serialized_platform_handle_ = serialized_platform_handle_.Pass();
rv->serialized_platform_handle_ = std::move(serialized_platform_handle_);
rv->serialized_ = true;
return scoped_refptr<Dispatcher>(rv.get());
@ -373,11 +374,9 @@ bool DataPipeConsumerDispatcher::EndSerializeAndCloseImplNoLock(
shared_memory_handle.reset(shared_buffer->PassPlatformHandle().release());
}
DataPipe::EndSerialize(
options_,
serialized_platform_handle_.Pass(),
shared_memory_handle.Pass(), shared_memory_size,
destination, actual_size, platform_handles);
DataPipe::EndSerialize(options_, std::move(serialized_platform_handle_),
std::move(shared_memory_handle), shared_memory_size,
destination, actual_size, platform_handles);
CloseImplNoLock();
return true;
}

@ -4,6 +4,8 @@
#include "mojo/edk/system/data_pipe_producer_dispatcher.h"
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
@ -20,7 +22,7 @@ void DataPipeProducerDispatcher::Init(
ScopedPlatformHandle message_pipe,
char* serialized_write_buffer, size_t serialized_write_buffer_size) {
if (message_pipe.is_valid()) {
channel_ = RawChannel::Create(message_pipe.Pass());
channel_ = RawChannel::Create(std::move(message_pipe));
channel_->SetSerializedData(
nullptr, 0u, serialized_write_buffer, serialized_write_buffer_size,
nullptr, nullptr);
@ -69,13 +71,13 @@ DataPipeProducerDispatcher::Deserialize(
scoped_ptr<PlatformSharedBufferMapping> mapping;
if (shared_memory_size) {
shared_buffer = internal::g_platform_support->CreateSharedBufferFromHandle(
shared_memory_size, shared_memory_handle.Pass());
shared_memory_size, std::move(shared_memory_handle));
mapping = shared_buffer->Map(0, shared_memory_size);
serialized_write_buffer = static_cast<char*>(mapping->GetBase());
serialized_write_buffer_size = shared_memory_size;
}
rv->Init(platform_handle.Pass(), serialized_write_buffer,
rv->Init(std::move(platform_handle), serialized_write_buffer,
serialized_write_buffer_size);
return rv;
}
@ -112,7 +114,7 @@ DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
scoped_refptr<DataPipeProducerDispatcher> rv = Create(options_);
serialized_write_buffer_.swap(rv->serialized_write_buffer_);
rv->serialized_platform_handle_ = serialized_platform_handle_.Pass();
rv->serialized_platform_handle_ = std::move(serialized_platform_handle_);
rv->serialized_ = true;
return scoped_refptr<Dispatcher>(rv.get());
}
@ -288,11 +290,9 @@ bool DataPipeProducerDispatcher::EndSerializeAndCloseImplNoLock(
shared_memory_handle.reset(shared_buffer->PassPlatformHandle().release());
}
DataPipe::EndSerialize(
options_,
serialized_platform_handle_.Pass(),
shared_memory_handle.Pass(), shared_memory_size,
destination, actual_size, platform_handles);
DataPipe::EndSerialize(options_, std::move(serialized_platform_handle_),
std::move(shared_memory_handle), shared_memory_size,
destination, actual_size, platform_handles);
CloseImplNoLock();
return true;
}
@ -373,7 +373,7 @@ bool DataPipeProducerDispatcher::WriteDataIntoMessages(
scoped_ptr<MessageInTransit> message(new MessageInTransit(
MessageInTransit::Type::MESSAGE, message_num_bytes,
static_cast<const char*>(elements) + offset));
if (!channel_->WriteMessage(message.Pass())) {
if (!channel_->WriteMessage(std::move(message))) {
error_ = true;
return false;
}

@ -5,8 +5,8 @@
#include "mojo/edk/system/message_in_transit.h"
#include <string.h>
#include <ostream>
#include <utility>
#include "base/logging.h"
#include "mojo/edk/system/configuration.h"
@ -133,7 +133,7 @@ void MessageInTransit::SetDispatchers(
DCHECK(!dispatchers_);
DCHECK(!transport_data_);
dispatchers_ = dispatchers.Pass();
dispatchers_ = std::move(dispatchers);
}
void MessageInTransit::SetTransportData(
@ -142,7 +142,7 @@ void MessageInTransit::SetTransportData(
DCHECK(!transport_data_);
DCHECK(!dispatchers_);
transport_data_ = transport_data.Pass();
transport_data_ = std::move(transport_data);
UpdateTotalSize();
}
@ -152,7 +152,7 @@ void MessageInTransit::SerializeAndCloseDispatchers() {
if (!dispatchers_ || !dispatchers_->size())
return;
transport_data_.reset(new TransportData(dispatchers_.Pass()));
transport_data_.reset(new TransportData(std::move(dispatchers_)));
// Update the sizes in the message header.
UpdateTotalSize();

@ -4,6 +4,8 @@
#include "mojo/edk/system/message_pipe_dispatcher.h"
#include <utility>
#include "base/bind.h"
#include "base/debug/stack_trace.h"
#include "base/logging.h"
@ -126,7 +128,7 @@ void MessagePipeDispatcher::Init(
std::vector<int>* serialized_write_fds) {
CHECK(transferable_);
if (message_pipe.get().is_valid()) {
channel_ = RawChannel::Create(message_pipe.Pass());
channel_ = RawChannel::Create(std::move(message_pipe));
// TODO(jam): It's probably cleaner to pass this in Init call.
channel_->SetSerializedData(
@ -270,7 +272,7 @@ scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize(
scoped_ptr<PlatformSharedBufferMapping> mapping;
if (shared_memory_handle.is_valid()) {
shared_buffer = internal::g_platform_support->CreateSharedBufferFromHandle(
serialization->shared_memory_size, shared_memory_handle.Pass());
serialization->shared_memory_size, std::move(shared_memory_handle));
mapping = shared_buffer->Map(0, serialization->shared_memory_size);
char* buffer = static_cast<char*>(mapping->GetBase());
if (serialization->serialized_read_buffer_size) {
@ -374,18 +376,15 @@ scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize(
message->SetDispatchers(TransportData::DeserializeDispatchers(
message_view.transport_data_buffer(),
message_view.transport_data_buffer_size(),
temp_platform_handles.Pass()));
std::move(temp_platform_handles)));
}
rv->message_queue_.AddMessage(message.Pass());
rv->message_queue_.AddMessage(std::move(message));
}
rv->Init(platform_handle.Pass(),
serialized_read_buffer,
serialized_read_buffer_size,
serialized_write_buffer,
serialized_write_buffer_size,
&serialized_read_fds,
rv->Init(std::move(platform_handle), serialized_read_buffer,
serialized_read_buffer_size, serialized_write_buffer,
serialized_write_buffer_size, &serialized_read_fds,
&serialized_write_fds);
if (message_queue_size) { // Should be empty by now.
@ -559,7 +558,7 @@ MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
new MessagePipeDispatcher(transferable_));
rv->serialized_ = true;
if (transferable_) {
rv->serialized_platform_handle_ = serialized_platform_handle_.Pass();
rv->serialized_platform_handle_ = std::move(serialized_platform_handle_);
serialized_message_queue_.swap(rv->serialized_message_queue_);
serialized_read_buffer_.swap(rv->serialized_read_buffer_);
serialized_write_buffer_.swap(rv->serialized_write_buffer_);
@ -610,9 +609,9 @@ MojoResult MessagePipeDispatcher::WriteMessageImplNoLock(
non_transferable_state_ == CONNECT_CALLED)) {
if (non_transferable_state_ == WAITING_FOR_READ_OR_WRITE)
RequestNontransferableChannel();
non_transferable_outgoing_message_queue_.AddMessage(message.Pass());
non_transferable_outgoing_message_queue_.AddMessage(std::move(message));
} else {
channel_->WriteMessage(message.Pass());
channel_->WriteMessage(std::move(message));
}
return MOJO_RESULT_OK;
@ -861,7 +860,8 @@ void MessagePipeDispatcher::OnReadMessage(
DCHECK(message_view.transport_data_buffer());
message->SetDispatchers(TransportData::DeserializeDispatchers(
message_view.transport_data_buffer(),
message_view.transport_data_buffer_size(), platform_handles.Pass()));
message_view.transport_data_buffer_size(),
std::move(platform_handles)));
}
if (started_transport_.Try()) {
@ -874,7 +874,7 @@ void MessagePipeDispatcher::OnReadMessage(
}
bool was_empty = message_queue_.IsEmpty();
message_queue_.AddMessage(message.Pass());
message_queue_.AddMessage(std::move(message));
if (was_empty)
awakable_list_.AwakeForStateChange(GetHandleSignalsStateImplNoLock());
@ -883,7 +883,7 @@ void MessagePipeDispatcher::OnReadMessage(
// If RawChannel is calling OnRead, that means it has its read_lock_
// acquired. That means StartSerialize can't be accessing message queue as
// it waits on ReleaseHandle first which acquires readlock_.
message_queue_.AddMessage(message.Pass());
message_queue_.AddMessage(std::move(message));
}
}
@ -986,7 +986,7 @@ MojoResult MessagePipeDispatcher::AttachTransportsNoLock(
dispatchers->push_back(nullptr);
}
}
message->SetDispatchers(dispatchers.Pass());
message->SetDispatchers(std::move(dispatchers));
return MOJO_RESULT_OK;
}

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
@ -86,10 +88,10 @@ class MultiprocessMessagePipePerfTest
// not including any "quitquitquit" message, modulo 100.
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) {
ScopedPlatformHandle client_platform_handle =
test::MultiprocessTestHelper::client_platform_handle.Pass();
std::move(test::MultiprocessTestHelper::client_platform_handle);
CHECK(client_platform_handle.is_valid());
ScopedMessagePipeHandle mp =
CreateMessagePipe(client_platform_handle.Pass());
CreateMessagePipe(std::move(client_platform_handle));
std::string buffer(1000000, '\0');
int rv = 0;
@ -135,8 +137,8 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) {
TEST_F(MultiprocessMessagePipePerfTest, MAYBE_PingPong) {
helper()->StartChild("PingPongClient");
ScopedMessagePipeHandle mp = CreateMessagePipe(
helper()->server_platform_handle.Pass());
ScopedMessagePipeHandle mp =
CreateMessagePipe(std::move(helper()->server_platform_handle));
// This values are set to align with one at ipc_pertests.cc for comparison.
const size_t kMsgSize[5] = {12, 144, 1728, 20736, 248832};

@ -5,8 +5,8 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#include "base/bind.h"
@ -44,10 +44,10 @@ class MultiprocessMessagePipeTest
// not including any "quitquitquit" message, modulo 100.
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
ScopedPlatformHandle client_platform_handle =
test::MultiprocessTestHelper::client_platform_handle.Pass();
std::move(test::MultiprocessTestHelper::client_platform_handle);
CHECK(client_platform_handle.is_valid());
ScopedMessagePipeHandle mp =
CreateMessagePipe(client_platform_handle.Pass());
CreateMessagePipe(std::move(client_platform_handle));
const std::string quitquitquit("quitquitquit");
int rv = 0;
@ -102,8 +102,8 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
TEST_F(MultiprocessMessagePipeTest, MAYBE_Basic) {
helper()->StartChild("EchoEcho");
ScopedMessagePipeHandle mp = CreateMessagePipe(
helper()->server_platform_handle.Pass());
ScopedMessagePipeHandle mp =
CreateMessagePipe(std::move(helper()->server_platform_handle));
std::string hello("hello");
ASSERT_EQ(MOJO_RESULT_OK,
@ -148,8 +148,8 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_Basic) {
TEST_F(MultiprocessMessagePipeTest, MAYBE_QueueMessages) {
helper()->StartChild("EchoEcho");
ScopedMessagePipeHandle mp = CreateMessagePipe(
helper()->server_platform_handle.Pass());
ScopedMessagePipeHandle mp =
CreateMessagePipe(std::move(helper()->server_platform_handle));
static const size_t kNumMessages = 1001;
for (size_t i = 0; i < kNumMessages; i++) {
@ -203,10 +203,10 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_QueueMessages) {
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
ScopedPlatformHandle client_platform_handle =
test::MultiprocessTestHelper::client_platform_handle.Pass();
std::move(test::MultiprocessTestHelper::client_platform_handle);
CHECK(client_platform_handle.is_valid());
ScopedMessagePipeHandle mp =
CreateMessagePipe(client_platform_handle.Pass());
CreateMessagePipe(std::move(client_platform_handle));
// Wait for the first message from our parent.
HandleSignalsState hss;
@ -291,8 +291,8 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
helper()->StartChild("CheckSharedBuffer");
ScopedMessagePipeHandle mp = CreateMessagePipe(
helper()->server_platform_handle.Pass());
ScopedMessagePipeHandle mp =
CreateMessagePipe(std::move(helper()->server_platform_handle));
// Make a shared buffer.
MojoCreateSharedBufferOptions options;
@ -372,10 +372,10 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
ScopedPlatformHandle client_platform_handle =
test::MultiprocessTestHelper::client_platform_handle.Pass();
std::move(test::MultiprocessTestHelper::client_platform_handle);
CHECK(client_platform_handle.is_valid());
ScopedMessagePipeHandle mp =
CreateMessagePipe(client_platform_handle.Pass());
CreateMessagePipe(std::move(client_platform_handle));
HandleSignalsState hss;
CHECK_EQ(MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE,
@ -413,7 +413,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
CHECK(h.is_valid());
MojoClose(handles[i]);
base::ScopedFILE fp(test::FILEFromPlatformHandle(h.Pass(), "r"));
base::ScopedFILE fp(test::FILEFromPlatformHandle(std::move(h), "r"));
CHECK(fp);
std::string fread_buffer(100, '\0');
size_t bytes_read =
@ -434,8 +434,8 @@ TEST_P(MultiprocessMessagePipeTestWithPipeCount, PlatformHandlePassing) {
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
helper()->StartChild("CheckPlatformHandleFile");
ScopedMessagePipeHandle mp = CreateMessagePipe(
helper()->server_platform_handle.Pass());
ScopedMessagePipeHandle mp =
CreateMessagePipe(std::move(helper()->server_platform_handle));
std::vector<MojoHandle> handles;
@ -449,10 +449,11 @@ TEST_P(MultiprocessMessagePipeTestWithPipeCount, PlatformHandlePassing) {
fflush(fp.get());
rewind(fp.get());
MojoHandle handle;
ASSERT_EQ(CreatePlatformHandleWrapper(
ScopedPlatformHandle(test::PlatformHandleFromFILE(fp.Pass())),
&handle),
MOJO_RESULT_OK);
ASSERT_EQ(
CreatePlatformHandleWrapper(
ScopedPlatformHandle(test::PlatformHandleFromFILE(std::move(fp))),
&handle),
MOJO_RESULT_OK);
handles.push_back(handle);
}
@ -486,11 +487,11 @@ INSTANTIATE_TEST_CASE_P(PipeCount,
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckMessagePipe) {
ScopedPlatformHandle client_platform_handle =
test::MultiprocessTestHelper::client_platform_handle.Pass();
std::move(test::MultiprocessTestHelper::client_platform_handle);
CHECK(client_platform_handle.is_valid());
ScopedMessagePipeHandle mp =
CreateMessagePipe(client_platform_handle.Pass());
CreateMessagePipe(std::move(client_platform_handle));
// Wait for the first message from our parent.
HandleSignalsState hss;
@ -553,7 +554,7 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_MessagePipePassing) {
helper()->StartChild("CheckMessagePipe");
ScopedMessagePipeHandle mp =
CreateMessagePipe(helper()->server_platform_handle.Pass());
CreateMessagePipe(std::move(helper()->server_platform_handle));
MojoCreateSharedBufferOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE;
@ -606,7 +607,7 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_MessagePipeTwoPassing) {
helper()->StartChild("CheckMessagePipe");
ScopedMessagePipeHandle mp =
CreateMessagePipe(helper()->server_platform_handle.Pass());
CreateMessagePipe(std::move(helper()->server_platform_handle));
MojoHandle mp1, mp2;
ASSERT_EQ(MOJO_RESULT_OK,
@ -646,11 +647,11 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_MessagePipeTwoPassing) {
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(DataPipeConsumer) {
ScopedPlatformHandle client_platform_handle =
test::MultiprocessTestHelper::client_platform_handle.Pass();
std::move(test::MultiprocessTestHelper::client_platform_handle);
CHECK(client_platform_handle.is_valid());
ScopedMessagePipeHandle mp =
CreateMessagePipe(client_platform_handle.Pass());
CreateMessagePipe(std::move(client_platform_handle));
// Wait for the first message from our parent.
HandleSignalsState hss;
@ -713,7 +714,7 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_DataPipeConsumer) {
helper()->StartChild("DataPipeConsumer");
ScopedMessagePipeHandle mp =
CreateMessagePipe(helper()->server_platform_handle.Pass());
CreateMessagePipe(std::move(helper()->server_platform_handle));
MojoCreateSharedBufferOptions options;
options.struct_size = sizeof(options);
options.flags = MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE;

@ -5,6 +5,7 @@
#include "mojo/edk/system/platform_handle_dispatcher.h"
#include <algorithm>
#include <utility>
#include "base/logging.h"
@ -23,7 +24,7 @@ struct MOJO_ALIGNAS(8) SerializedPlatformHandleDispatcher {
ScopedPlatformHandle PlatformHandleDispatcher::PassPlatformHandle() {
base::AutoLock locker(lock());
return platform_handle_.Pass();
return std::move(platform_handle_);
}
Dispatcher::Type PlatformHandleDispatcher::GetType() const {
@ -65,8 +66,7 @@ scoped_refptr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize(
PlatformHandleDispatcher::PlatformHandleDispatcher(
ScopedPlatformHandle platform_handle)
: platform_handle_(platform_handle.Pass()) {
}
: platform_handle_(std::move(platform_handle)) {}
PlatformHandleDispatcher::~PlatformHandleDispatcher() {
}
@ -79,7 +79,7 @@ void PlatformHandleDispatcher::CloseImplNoLock() {
scoped_refptr<Dispatcher>
PlatformHandleDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() {
lock().AssertAcquired();
return Create(platform_handle_.Pass());
return Create(std::move(platform_handle_));
}
void PlatformHandleDispatcher::StartSerializeImplNoLock(

@ -5,6 +5,8 @@
#ifndef MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_
#define MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_
#include <utility>
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "mojo/edk/system/simple_dispatcher.h"
#include "mojo/edk/system/system_impl_export.h"
@ -21,7 +23,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher final
static scoped_refptr<PlatformHandleDispatcher> Create(
ScopedPlatformHandle platform_handle) {
return make_scoped_refptr(
new PlatformHandleDispatcher(platform_handle.Pass()));
new PlatformHandleDispatcher(std::move(platform_handle)));
}
ScopedPlatformHandle PassPlatformHandle();

@ -5,6 +5,7 @@
#include "mojo/edk/system/platform_handle_dispatcher.h"
#include <stdio.h>
#include <utility>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@ -31,19 +32,19 @@ TEST(PlatformHandleDispatcherTest, Basic) {
EXPECT_EQ(sizeof(kHelloWorld),
fwrite(kHelloWorld, 1, sizeof(kHelloWorld), fp.get()));
ScopedPlatformHandle h(test::PlatformHandleFromFILE(fp.Pass()));
ScopedPlatformHandle h(test::PlatformHandleFromFILE(std::move(fp)));
EXPECT_FALSE(fp);
ASSERT_TRUE(h.is_valid());
scoped_refptr<PlatformHandleDispatcher> dispatcher =
PlatformHandleDispatcher::Create(h.Pass());
PlatformHandleDispatcher::Create(std::move(h));
EXPECT_FALSE(h.is_valid());
EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, dispatcher->GetType());
h = dispatcher->PassPlatformHandle().Pass();
h = dispatcher->PassPlatformHandle();
EXPECT_TRUE(h.is_valid());
fp = test::FILEFromPlatformHandle(h.Pass(), "rb").Pass();
fp = test::FILEFromPlatformHandle(std::move(h), "rb");
EXPECT_FALSE(h.is_valid());
EXPECT_TRUE(fp);
@ -54,7 +55,7 @@ TEST(PlatformHandleDispatcherTest, Basic) {
EXPECT_STREQ(kHelloWorld, read_buffer);
// Try getting the handle again. (It should fail cleanly.)
h = dispatcher->PassPlatformHandle().Pass();
h = dispatcher->PassPlatformHandle();
EXPECT_FALSE(h.is_valid());
EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
@ -73,7 +74,7 @@ TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) {
scoped_refptr<PlatformHandleDispatcher> dispatcher =
PlatformHandleDispatcher::Create(
test::PlatformHandleFromFILE(fp.Pass()));
test::PlatformHandleFromFILE(std::move(fp)));
DispatcherTransport transport(
test::DispatcherTryStartTransport(dispatcher.get()));
@ -92,8 +93,7 @@ TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) {
ASSERT_EQ(Dispatcher::Type::PLATFORM_HANDLE, generic_dispatcher->GetType());
dispatcher = static_cast<PlatformHandleDispatcher*>(generic_dispatcher.get());
fp = test::FILEFromPlatformHandle(dispatcher->PassPlatformHandle(),
"rb").Pass();
fp = test::FILEFromPlatformHandle(dispatcher->PassPlatformHandle(), "rb");
EXPECT_TRUE(fp);
rewind(fp.get());

@ -5,8 +5,8 @@
#include "mojo/edk/system/raw_channel.h"
#include <string.h>
#include <algorithm>
#include <utility>
#include "base/bind.h"
#include "base/location.h"
@ -283,7 +283,7 @@ void RawChannel::Shutdown() {
{
base::AutoLock read_locker(read_lock_);
base::AutoLock locker(write_lock_);
OnShutdownNoLock(read_buffer_.Pass(), write_buffer_.Pass());
OnShutdownNoLock(std::move(read_buffer_), std::move(write_buffer_));
}
if (initialized_) {
@ -335,7 +335,7 @@ bool RawChannel::WriteMessage(scoped_ptr<MessageInTransit> message) {
return false;
bool queue_was_empty = write_buffer_->message_queue_.IsEmpty();
EnqueueMessageNoLock(message.Pass());
EnqueueMessageNoLock(std::move(message));
if (queue_was_empty && write_ready_)
return SendQueuedMessagesNoLock();
@ -398,7 +398,7 @@ void RawChannel::SetSerializedData(
scoped_ptr<MessageInTransit> message(new MessageInTransit(
MessageInTransit::Type::RAW_MESSAGE, message_num_bytes,
static_cast<const char*>(serialized_write_buffer) + offset));
write_buffer_->message_queue_.AddMessage(message.Pass());
write_buffer_->message_queue_.AddMessage(std::move(message));
offset += message_num_bytes;
}
}
@ -526,7 +526,7 @@ void RawChannel::SerializeWriteBuffer(
void RawChannel::EnqueueMessageNoLock(scoped_ptr<MessageInTransit> message) {
write_lock_.AssertAcquired();
write_buffer_->message_queue_.AddMessage(message.Pass());
write_buffer_->message_queue_.AddMessage(std::move(message));
}
bool RawChannel::OnReadMessageForRawChannel(
@ -660,9 +660,8 @@ void RawChannel::DispatchMessages(bool* did_dispatch_message,
&platform_handle_table);
if (num_platform_handles > 0) {
platform_handles =
GetReadPlatformHandles(num_platform_handles,
platform_handle_table).Pass();
platform_handles = GetReadPlatformHandles(num_platform_handles,
platform_handle_table);
if (!platform_handles) {
LOG(ERROR) << "Invalid number of platform handles received";
CallOnError(Delegate::ERROR_READ_BAD_MESSAGE);
@ -677,7 +676,7 @@ void RawChannel::DispatchMessages(bool* did_dispatch_message,
if (delegate_) {
DCHECK(!calling_delegate_);
calling_delegate_ = true;
delegate_->OnReadMessage(message_view, platform_handles.Pass());
delegate_->OnReadMessage(message_view, std::move(platform_handles));
calling_delegate_ = false;
}
}

@ -10,9 +10,9 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <algorithm>
#include <deque>
#include <utility>
#include "base/bind.h"
#include "base/location.h"
@ -109,7 +109,7 @@ class RawChannelPosix final : public RawChannel,
};
RawChannelPosix::RawChannelPosix(ScopedPlatformHandle handle)
: fd_(handle.Pass()),
: fd_(std::move(handle)),
pending_read_(false),
pending_write_(false),
weak_ptr_factory_(this) {
@ -152,9 +152,9 @@ void RawChannelPosix::EnqueueMessageNoLock(
new PlatformHandleVector(
platform_handles->begin() + i,
platform_handles->begin() + i + kPlatformChannelMaxNumHandles));
fd_message->SetTransportData(make_scoped_ptr(
new TransportData(fds.Pass(), GetSerializedPlatformHandleSize())));
RawChannel::EnqueueMessageNoLock(fd_message.Pass());
fd_message->SetTransportData(make_scoped_ptr(new TransportData(
std::move(fds), GetSerializedPlatformHandleSize())));
RawChannel::EnqueueMessageNoLock(std::move(fd_message));
}
// Remove the handles that we "moved" into the other messages.
@ -163,7 +163,7 @@ void RawChannelPosix::EnqueueMessageNoLock(
}
}
RawChannel::EnqueueMessageNoLock(message.Pass());
RawChannel::EnqueueMessageNoLock(std::move(message));
}
bool RawChannelPosix::OnReadMessageForRawChannel(
@ -196,7 +196,7 @@ ScopedPlatformHandle RawChannelPosix::ReleaseHandleNoLock(
read_platform_handles_.pop_front();
}
return fd_.Pass();
return std::move(fd_);
}
void RawChannelPosix::SetSerializedFDs(
@ -218,9 +218,9 @@ void RawChannelPosix::SetSerializedFDs(
ScopedPlatformHandleVectorPtr fds(
new PlatformHandleVector(serialized_write_fds->begin() + i,
serialized_write_fds->begin() + i + batch));
fd_message->SetTransportData(make_scoped_ptr(
new TransportData(fds.Pass(), GetSerializedPlatformHandleSize())));
RawChannel::EnqueueMessageNoLock(fd_message.Pass());
fd_message->SetTransportData(make_scoped_ptr(new TransportData(
std::move(fds), GetSerializedPlatformHandleSize())));
RawChannel::EnqueueMessageNoLock(std::move(fd_message));
i += batch;
}
}
@ -269,7 +269,7 @@ ScopedPlatformHandleVectorPtr RawChannelPosix::GetReadPlatformHandles(
read_platform_handles_.erase(
read_platform_handles_.begin(),
read_platform_handles_.begin() + num_platform_handles);
return rv.Pass();
return rv;
}
size_t RawChannelPosix::SerializePlatformHandles(std::vector<int>* fds) {
@ -557,7 +557,7 @@ void RawChannelPosix::WaitToWrite() {
// Static factory method declared in raw_channel.h.
// static
RawChannel* RawChannel::Create(ScopedPlatformHandle handle) {
return new RawChannelPosix(handle.Pass());
return new RawChannelPosix(std::move(handle));
}
size_t RawChannel::GetSerializedPlatformHandleSize() {

@ -6,7 +6,7 @@
#include <stdint.h>
#include <stdio.h>
#include <utility>
#include <vector>
#include "base/bind.h"
@ -197,7 +197,7 @@ class TestMessageReaderAndChecker {
// Tests writing (and verifies reading using our own custom reader).
TEST_F(RawChannelTest, WriteMessage) {
WriteOnlyRawChannelDelegate delegate;
RawChannel* rc = RawChannel::Create(handles[0].Pass());
RawChannel* rc = RawChannel::Create(std::move(handles[0]));
TestMessageReaderAndChecker checker(handles[1].get());
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
@ -283,7 +283,7 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate {
// Tests reading (writing using our own custom writer).
TEST_F(RawChannelTest, OnReadMessage) {
ReadCheckerRawChannelDelegate delegate;
RawChannel* rc = RawChannel::Create(handles[0].Pass());
RawChannel* rc = RawChannel::Create(std::move(handles[0]));
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate)));
@ -380,7 +380,7 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
static const size_t kNumWriteMessagesPerThread = 400;
WriteOnlyRawChannelDelegate writer_delegate;
RawChannel* writer_rc = RawChannel::Create(handles[0].Pass());
RawChannel* writer_rc = RawChannel::Create(std::move(handles[0]));
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&InitOnIOThread, writer_rc,
@ -388,7 +388,7 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
ReadCountdownRawChannelDelegate reader_delegate(kNumWriterThreads *
kNumWriteMessagesPerThread);
RawChannel* reader_rc = RawChannel::Create(handles[1].Pass());
RawChannel* reader_rc = RawChannel::Create(std::move(handles[1]));
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&InitOnIOThread, reader_rc,
@ -479,7 +479,7 @@ class ErrorRecordingRawChannelDelegate
// Tests (fatal) errors.
TEST_F(RawChannelTest, OnError) {
ErrorRecordingRawChannelDelegate delegate(0, true, true);
RawChannel* rc = RawChannel::Create(handles[0].Pass());
RawChannel* rc = RawChannel::Create(std::move(handles[0]));
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate)));
@ -523,7 +523,7 @@ TEST_F(RawChannelTest, ReadUnaffectedByWriteError) {
// Only start up reading here. The system buffer should still contain the
// messages that were written.
ErrorRecordingRawChannelDelegate delegate(kMessageCount, true, true);
RawChannel* rc = RawChannel::Create(handles[0].Pass());
RawChannel* rc = RawChannel::Create(std::move(handles[0]));
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&InitOnIOThread, rc, base::Unretained(&delegate)));
@ -572,7 +572,7 @@ class ReadPlatformHandlesCheckerRawChannelDelegate
{
char buffer[100] = {};
base::ScopedFILE fp(test::FILEFromPlatformHandle(h1.Pass(), "rb"));
base::ScopedFILE fp(test::FILEFromPlatformHandle(std::move(h1), "rb"));
EXPECT_TRUE(fp);
rewind(fp.get());
EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get()));
@ -581,7 +581,7 @@ class ReadPlatformHandlesCheckerRawChannelDelegate
{
char buffer[100] = {};
base::ScopedFILE fp(test::FILEFromPlatformHandle(h2.Pass(), "rb"));
base::ScopedFILE fp(test::FILEFromPlatformHandle(std::move(h2), "rb"));
EXPECT_TRUE(fp);
rewind(fp.get());
EXPECT_EQ(1u, fread(buffer, 1, sizeof(buffer), fp.get()));
@ -608,13 +608,13 @@ TEST_F(RawChannelTest, ReadWritePlatformHandles) {
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
WriteOnlyRawChannelDelegate write_delegate;
RawChannel* rc_write = RawChannel::Create(handles[0].Pass());
RawChannel* rc_write = RawChannel::Create(std::move(handles[0]));
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&InitOnIOThread, rc_write, base::Unretained(&write_delegate)));
ReadPlatformHandlesCheckerRawChannelDelegate read_delegate;
RawChannel* rc_read = RawChannel::Create(handles[1].Pass());
RawChannel* rc_read = RawChannel::Create(std::move(handles[1]));
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&InitOnIOThread, rc_read, base::Unretained(&read_delegate)));
@ -631,16 +631,17 @@ TEST_F(RawChannelTest, ReadWritePlatformHandles) {
const char kHello[] = "hello";
ScopedPlatformHandleVectorPtr platform_handles(new PlatformHandleVector());
platform_handles->push_back(
test::PlatformHandleFromFILE(fp1.Pass()).release());
test::PlatformHandleFromFILE(std::move(fp1)).release());
platform_handles->push_back(
test::PlatformHandleFromFILE(fp2.Pass()).release());
test::PlatformHandleFromFILE(std::move(fp2)).release());
scoped_ptr<MessageInTransit> message(
new MessageInTransit(MessageInTransit::Type::MESSAGE,
sizeof(kHello), kHello));
message->SetTransportData(make_scoped_ptr(new TransportData(
platform_handles.Pass(), rc_write->GetSerializedPlatformHandleSize())));
EXPECT_TRUE(rc_write->WriteMessage(message.Pass()));
message->SetTransportData(make_scoped_ptr(
new TransportData(std::move(platform_handles),
rc_write->GetSerializedPlatformHandleSize())));
EXPECT_TRUE(rc_write->WriteMessage(std::move(message)));
}
read_delegate.Wait();

@ -4,6 +4,8 @@
#include "mojo/edk/system/routed_raw_channel.h"
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "mojo/edk/embedder/embedder_internal.h"
@ -24,7 +26,7 @@ RoutedRawChannel::PendingMessage::~PendingMessage() {
RoutedRawChannel::RoutedRawChannel(
ScopedPlatformHandle handle,
const base::Callback<void(RoutedRawChannel*)>& destruct_callback)
: channel_(RawChannel::Create(handle.Pass())),
: channel_(RawChannel::Create(std::move(handle))),
destruct_callback_(destruct_callback) {
internal::g_io_thread_task_runner->PostTask(
FROM_HERE,
@ -46,7 +48,7 @@ void RoutedRawChannel::AddRoute(uint64_t route_id,
MessageInTransit::View view(pending_messages_[i]->message.size(),
&pending_messages_[i]->message[0]);
if (view.route_id() == route_id) {
delegate->OnReadMessage(view, pending_messages_[i]->handles.Pass());
delegate->OnReadMessage(view, std::move(pending_messages_[i]->handles));
pending_messages_.erase(pending_messages_.begin() + i);
} else {
++i;
@ -77,7 +79,7 @@ void RoutedRawChannel::RemoveRoute(uint64_t route_id) {
MessageInTransit::Type::MESSAGE, arraysize(message_data),
message_data));
message->set_route_id(kInternalRouteId);
channel_->WriteMessage(message.Pass());
channel_->WriteMessage(std::move(message));
}
if (!channel_ && routes_.empty()) {
@ -121,14 +123,14 @@ void RoutedRawChannel::OnReadMessage(
}
if (routes_.find(route_id) != routes_.end()) {
routes_[route_id]->OnReadMessage(message_view, platform_handles.Pass());
routes_[route_id]->OnReadMessage(message_view, std::move(platform_handles));
} else {
scoped_ptr<PendingMessage> msg(new PendingMessage);
msg->message.resize(message_view.total_size());
memcpy(&msg->message[0], message_view.main_buffer(),
message_view.total_size());
msg->handles = platform_handles.Pass();
pending_messages_.push_back(msg.Pass());
msg->handles = std::move(platform_handles);
pending_messages_.push_back(std::move(msg));
}
}

@ -4,6 +4,8 @@
#include "mojo/edk/system/transport_data.h"
#include <utility>
#include "base/logging.h"
#include "mojo/edk/system/configuration.h"
#include "mojo/edk/system/message_in_transit.h"
@ -186,10 +188,9 @@ TransportData::TransportData(scoped_ptr<DispatcherVector> dispatchers)
// |dispatchers_| will be destroyed as it goes out of scope.
}
TransportData::TransportData(
ScopedPlatformHandleVectorPtr platform_handles,
size_t serialized_platform_handle_size)
: buffer_size_(), platform_handles_(platform_handles.Pass()) {
TransportData::TransportData(ScopedPlatformHandleVectorPtr platform_handles,
size_t serialized_platform_handle_size)
: buffer_size_(), platform_handles_(std::move(platform_handles)) {
buffer_size_ = MessageInTransit::RoundUpMessageAlignment(
sizeof(Header) +
platform_handles_->size() * serialized_platform_handle_size);
@ -326,7 +327,7 @@ scoped_ptr<DispatcherVector> TransportData::DeserializeDispatchers(
handle_table[i].type, source, size, platform_handles.get());
}
return dispatchers.Pass();
return dispatchers;
}
} // namespace edk

@ -4,6 +4,8 @@
#include "mojo/edk/test/multiprocess_test_helper.h"
#include <utility>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/process/kill.h"
@ -117,7 +119,7 @@ void MultiprocessTestHelper::ChildSetup() {
ScopedPlatformHandle broker_handle =
PlatformChannelPair::PassClientHandleFromParentProcessFromString(
broker_handle_str);
SetParentPipeHandle(broker_handle.Pass());
SetParentPipeHandle(std::move(broker_handle));
}
// static

@ -4,6 +4,8 @@
#include "mojo/edk/test/multiprocess_test_helper.h"
#include <utility>
#include "base/logging.h"
#include "build/build_config.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
@ -88,7 +90,7 @@ TEST_F(MultiprocessTestHelperTest, MAYBE_PassedChannel) {
helper.StartChild("PassedChannel");
// Take ownership of the handle.
ScopedPlatformHandle handle = helper.server_platform_handle.Pass();
ScopedPlatformHandle handle = std::move(helper.server_platform_handle);
// The handle should be non-blocking.
EXPECT_TRUE(IsNonBlocking(handle.get()));
@ -111,7 +113,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannel) {
// Take ownership of the handle.
ScopedPlatformHandle handle =
MultiprocessTestHelper::client_platform_handle.Pass();
std::move(MultiprocessTestHelper::client_platform_handle);
// The handle should be non-blocking.
EXPECT_TRUE(IsNonBlocking(handle.get()));

@ -85,7 +85,7 @@ base::ScopedFILE FILEFromPlatformHandle(ScopedPlatformHandle h,
CHECK(h.is_valid());
base::ScopedFILE rv(fdopen(h.release().handle, mode));
PCHECK(rv) << "fdopen";
return rv.Pass();
return rv;
}
} // namespace test