Skip to content

Commit

Permalink
ipc: Remove use of MessageLoopProxy and deprecated MessageLoop APIs
Browse files Browse the repository at this point in the history
This patch was autogenerated with https://codereview.chromium.org/1010073002/.

BUG=465354

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

Cr-Commit-Position: refs/heads/master@{#329389}
  • Loading branch information
skyostil authored and Commit bot committed May 12, 2015
1 parent 28140eb commit e687bdf
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 142 deletions.
46 changes: 23 additions & 23 deletions ipc/ipc_channel_nacl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/lock.h"
#include "base/task_runner_util.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/simple_thread.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_logging.h"
Expand Down Expand Up @@ -74,9 +75,9 @@ class ChannelNacl::ReaderThreadRunner
// above callbacks.
ReaderThreadRunner(
int pipe,
base::Callback<void (scoped_ptr<MessageContents>)> data_read_callback,
base::Callback<void ()> failure_callback,
scoped_refptr<base::MessageLoopProxy> main_message_loop);
base::Callback<void(scoped_ptr<MessageContents>)> data_read_callback,
base::Callback<void()> failure_callback,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);

// DelegateSimpleThread implementation. Reads data from the pipe in a loop
// until either we are told to quit or a read fails.
Expand All @@ -86,31 +87,32 @@ class ChannelNacl::ReaderThreadRunner
int pipe_;
base::Callback<void (scoped_ptr<MessageContents>)> data_read_callback_;
base::Callback<void ()> failure_callback_;
scoped_refptr<base::MessageLoopProxy> main_message_loop_;
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;

DISALLOW_COPY_AND_ASSIGN(ReaderThreadRunner);
};

ChannelNacl::ReaderThreadRunner::ReaderThreadRunner(
int pipe,
base::Callback<void (scoped_ptr<MessageContents>)> data_read_callback,
base::Callback<void ()> failure_callback,
scoped_refptr<base::MessageLoopProxy> main_message_loop)
base::Callback<void(scoped_ptr<MessageContents>)> data_read_callback,
base::Callback<void()> failure_callback,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
: pipe_(pipe),
data_read_callback_(data_read_callback),
failure_callback_(failure_callback),
main_message_loop_(main_message_loop) {
main_task_runner_(main_task_runner) {
}

void ChannelNacl::ReaderThreadRunner::Run() {
while (true) {
scoped_ptr<MessageContents> msg_contents(new MessageContents);
bool success = ReadDataOnReaderThread(pipe_, msg_contents.get());
if (success) {
main_message_loop_->PostTask(FROM_HERE,
main_task_runner_->PostTask(
FROM_HERE,
base::Bind(data_read_callback_, base::Passed(&msg_contents)));
} else {
main_message_loop_->PostTask(FROM_HERE, failure_callback_);
main_task_runner_->PostTask(FROM_HERE, failure_callback_);
// Because the read failed, we know we're going to quit. Don't bother
// trying to read again.
return;
Expand Down Expand Up @@ -159,25 +161,23 @@ bool ChannelNacl::Connect() {
// where Channel::Send will be called, and the same thread that should receive
// messages). The constructor might be invoked on another thread (see
// ChannelProxy for an example of that). Therefore, we must wait until Connect
// is called to decide which MessageLoopProxy to pass to ReaderThreadRunner.
reader_thread_runner_.reset(
new ReaderThreadRunner(
pipe_,
base::Bind(&ChannelNacl::DidRecvMsg,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ChannelNacl::ReadDidFail,
weak_ptr_factory_.GetWeakPtr()),
base::MessageLoopProxy::current()));
// is called to decide which SingleThreadTaskRunner to pass to
// ReaderThreadRunner.
reader_thread_runner_.reset(new ReaderThreadRunner(
pipe_,
base::Bind(&ChannelNacl::DidRecvMsg, weak_ptr_factory_.GetWeakPtr()),
base::Bind(&ChannelNacl::ReadDidFail, weak_ptr_factory_.GetWeakPtr()),
base::ThreadTaskRunnerHandle::Get()));
reader_thread_.reset(
new base::DelegateSimpleThread(reader_thread_runner_.get(),
"ipc_channel_nacl reader thread"));
reader_thread_->Start();
waiting_connect_ = false;
// If there were any messages queued before connection, send them.
ProcessOutgoingMessages();
base::MessageLoopProxy::current()->PostTask(FROM_HERE,
base::Bind(&ChannelNacl::CallOnChannelConnected,
weak_ptr_factory_.GetWeakPtr()));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&ChannelNacl::CallOnChannelConnected,
weak_ptr_factory_.GetWeakPtr()));

return true;
}
Expand Down
7 changes: 4 additions & 3 deletions ipc/ipc_channel_posix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/posix/eintr_wrapper.h"
#include "base/process/process.h"
#include "base/single_thread_task_runner.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
#include "ipc/ipc_listener.h"
Expand Down Expand Up @@ -88,7 +89,7 @@ class IPCChannelPosixTestListener : public IPC::Listener {
loop->QuitNow();
} else {
// Die as soon as Run is called.
loop->PostTask(FROM_HERE, loop->QuitClosure());
loop->task_runner()->PostTask(FROM_HERE, loop->QuitClosure());
}
}

Expand Down Expand Up @@ -188,7 +189,7 @@ void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) {
// in the case of a bad test. Usually, the run loop will quit sooner than
// that because all tests use a IPCChannelPosixTestListener which quits the
// current run loop on any channel activity.
loop->PostDelayedTask(FROM_HERE, loop->QuitClosure(), delay);
loop->task_runner()->PostDelayedTask(FROM_HERE, loop->QuitClosure(), delay);
loop->Run();
}

Expand Down
3 changes: 1 addition & 2 deletions ipc/ipc_channel_proxy_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "build/build_config.h"

#include "base/message_loop/message_loop.h"
#include "base/pickle.h"
#include "base/threading/thread.h"
#include "ipc/ipc_message.h"
Expand Down Expand Up @@ -243,7 +242,7 @@ class IPCChannelProxyTest : public IPCTestBase {
thread_->StartWithOptions(options);

listener_.reset(new QuitListener());
CreateChannelProxy(listener_.get(), thread_->message_loop_proxy().get());
CreateChannelProxy(listener_.get(), thread_->task_runner().get());

ASSERT_TRUE(StartClient());
}
Expand Down
3 changes: 1 addition & 2 deletions ipc/ipc_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <string>

#include "base/message_loop/message_loop.h"
#include "base/pickle.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -128,7 +127,7 @@ TEST_F(IPCChannelTest, ChannelProxyTest) {

// Set up IPC channel proxy.
IPC::TestChannelListener listener;
CreateChannelProxy(&listener, thread.message_loop_proxy().get());
CreateChannelProxy(&listener, thread.task_runner().get());
listener.Init(sender());

ASSERT_TRUE(StartClient());
Expand Down
10 changes: 5 additions & 5 deletions ipc/ipc_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include "base/command_line.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "ipc/ipc_message_utils.h"
Expand Down Expand Up @@ -161,7 +162,7 @@ void Logging::OnPostDispatchMessage(const Message& message,
if (base::MessageLoop::current() == main_thread_) {
Log(data);
} else {
main_thread_->PostTask(
main_thread_->task_runner()->PostTask(
FROM_HERE, base::Bind(&Logging::Log, base::Unretained(this), data));
}
}
Expand Down Expand Up @@ -231,9 +232,8 @@ void Logging::Log(const LogData& data) {
queued_logs_.push_back(data);
if (!queue_invoke_later_pending_) {
queue_invoke_later_pending_ = true;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&Logging::OnSendLogs, base::Unretained(this)),
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&Logging::OnSendLogs, base::Unretained(this)),
base::TimeDelta::FromMilliseconds(kLogSendDelayMs));
}
}
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_perftest_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ int PingPongTestClient::RunMain() {
}

scoped_refptr<base::TaskRunner> PingPongTestClient::task_runner() {
return main_message_loop_.message_loop_proxy();
return main_message_loop_.task_runner();
}

LockThreadAffinity::LockThreadAffinity(int cpu_number)
Expand Down
31 changes: 13 additions & 18 deletions ipc/ipc_send_fds_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ extern "C" {

#include "base/callback.h"
#include "base/file_descriptor_posix.h"
#include "base/message_loop/message_loop.h"
#include "base/location.h"
#include "base/pickle.h"
#include "base/posix/eintr_wrapper.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
#include "ipc/ipc_message_attachment_set.h"
#include "ipc/ipc_message_utils.h"
Expand Down Expand Up @@ -250,12 +251,10 @@ class PipeChannelHelper {
out = IPC::Channel::CreateClient(out_handle, &cb_listener_);
// PostTask the connect calls to make sure the callbacks happens
// on the right threads.
in_thread_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&PipeChannelHelper::Connect, in.get()));
out_thread_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&PipeChannelHelper::Connect, out.get()));
in_thread_->task_runner()->PostTask(
FROM_HERE, base::Bind(&PipeChannelHelper::Connect, in.get()));
out_thread_->task_runner()->PostTask(
FROM_HERE, base::Bind(&PipeChannelHelper::Connect, out.get()));
}

static void DestroyChannel(scoped_ptr<IPC::Channel> *c,
Expand All @@ -267,12 +266,10 @@ class PipeChannelHelper {
~PipeChannelHelper() {
base::WaitableEvent a(true, false);
base::WaitableEvent b(true, false);
in_thread_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&PipeChannelHelper::DestroyChannel, &in, &a));
out_thread_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&PipeChannelHelper::DestroyChannel, &out, &b));
in_thread_->task_runner()->PostTask(
FROM_HERE, base::Bind(&PipeChannelHelper::DestroyChannel, &in, &a));
out_thread_->task_runner()->PostTask(
FROM_HERE, base::Bind(&PipeChannelHelper::DestroyChannel, &out, &b));
a.Wait();
b.Wait();
}
Expand Down Expand Up @@ -321,11 +318,9 @@ class IPCMultiSendingFdsTest : public testing::Test {
for (int i = 0; i < pipes_to_send; i++) {
received_.Reset();
std::pair<int, int> pipe_fds = make_socket_pair();
t->message_loop()->PostTask(
FROM_HERE,
base::Bind(&PipeChannelHelper::Send,
base::Unretained(dest),
pipe_fds.second));
t->task_runner()->PostTask(
FROM_HERE, base::Bind(&PipeChannelHelper::Send,
base::Unretained(dest), pipe_fds.second));
char tmp = 'x';
CHECK_EQ(1, HANDLE_EINTR(write(pipe_fds.first, &tmp, 1)));
CHECK_EQ(0, IGNORE_EINTR(close(pipe_fds.first)));
Expand Down
Loading

0 comments on commit e687bdf

Please sign in to comment.