Skip to content

Commit

Permalink
ipc: Use base::MessageLoop.
Browse files Browse the repository at this point in the history
BUG=236029
[email protected]

Review URL: https://chromiumcodereview.appspot.com/14383024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197465 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
[email protected] committed Apr 30, 2013
1 parent fb4d0a3 commit fd0a773
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 101 deletions.
4 changes: 2 additions & 2 deletions ipc/ipc_channel_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ bool ChannelFactory::Listen() {

// Watch the fd for connections, and turn any connections into
// active sockets.
MessageLoopForIO::current()->WatchFileDescriptor(
base::MessageLoopForIO::current()->WatchFileDescriptor(
listen_fd_,
true,
MessageLoopForIO::WATCH_READ,
base::MessageLoopForIO::WATCH_READ,
&server_listen_connection_watcher_,
this);
return true;
Expand Down
5 changes: 3 additions & 2 deletions ipc/ipc_channel_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace IPC {
// the socket, it accept()s the connection and passes the new FD to the
// delegate. The delegate is then responsible for creating a new IPC::Channel
// for the FD.
class IPC_EXPORT ChannelFactory : public MessageLoopForIO::Watcher {
class IPC_EXPORT ChannelFactory : public base::MessageLoopForIO::Watcher {
public:
class Delegate {
public:
Expand Down Expand Up @@ -44,7 +44,8 @@ class IPC_EXPORT ChannelFactory : public MessageLoopForIO::Watcher {
virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;

MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_;
base::MessageLoopForIO::FileDescriptorWatcher
server_listen_connection_watcher_;
base::FilePath path_;
Delegate* delegate_;
int listen_fd_;
Expand Down
15 changes: 6 additions & 9 deletions ipc/ipc_channel_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ bool Channel::ChannelImpl::Connect() {
if (server_listen_pipe_ != -1) {
// Watch the pipe for connections, and turn any connections into
// active sockets.
MessageLoopForIO::current()->WatchFileDescriptor(
base::MessageLoopForIO::current()->WatchFileDescriptor(
server_listen_pipe_,
true,
MessageLoopForIO::WATCH_READ,
base::MessageLoopForIO::WATCH_READ,
&server_listen_connection_watcher_,
this);
} else {
Expand Down Expand Up @@ -469,10 +469,10 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {

// Tell libevent to call us back once things are unblocked.
is_blocked_on_write_ = true;
MessageLoopForIO::current()->WatchFileDescriptor(
base::MessageLoopForIO::current()->WatchFileDescriptor(
pipe_,
false, // One shot
MessageLoopForIO::WATCH_WRITE,
base::MessageLoopForIO::WATCH_WRITE,
&write_watcher_,
this);
return true;
Expand Down Expand Up @@ -667,11 +667,8 @@ void Channel::ChannelImpl::OnFileCanWriteWithoutBlocking(int fd) {
}

bool Channel::ChannelImpl::AcceptConnection() {
MessageLoopForIO::current()->WatchFileDescriptor(pipe_,
true,
MessageLoopForIO::WATCH_READ,
&read_watcher_,
this);
base::MessageLoopForIO::current()->WatchFileDescriptor(
pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this);
QueueHelloMessage();

if (mode_ & MODE_CLIENT_FLAG) {
Expand Down
9 changes: 5 additions & 4 deletions ipc/ipc_channel_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
namespace IPC {

class Channel::ChannelImpl : public internal::ChannelReader,
public MessageLoopForIO::Watcher {
public base::MessageLoopForIO::Watcher {
public:
// Mirror methods of Channel, see ipc_channel.h for description.
ChannelImpl(const IPC::ChannelHandle& channel_handle, Mode mode,
Expand Down Expand Up @@ -118,9 +118,10 @@ class Channel::ChannelImpl : public internal::ChannelReader,

// After accepting one client connection on our server socket we want to
// stop listening.
MessageLoopForIO::FileDescriptorWatcher server_listen_connection_watcher_;
MessageLoopForIO::FileDescriptorWatcher read_watcher_;
MessageLoopForIO::FileDescriptorWatcher write_watcher_;
base::MessageLoopForIO::FileDescriptorWatcher
server_listen_connection_watcher_;
base::MessageLoopForIO::FileDescriptorWatcher read_watcher_;
base::MessageLoopForIO::FileDescriptorWatcher write_watcher_;

// Indicates whether we're currently blocked waiting for a write to complete.
bool is_blocked_on_write_;
Expand Down
19 changes: 8 additions & 11 deletions ipc/ipc_channel_posix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class IPCChannelPosixTestListener : public IPC::Listener {
STATUS status() { return status_; }

void QuitRunLoop() {
MessageLoopForIO::current()->QuitNow();
base::MessageLoopForIO::current()->QuitNow();
}

private:
Expand All @@ -105,8 +105,8 @@ class IPCChannelPosixTest : public base::MultiProcessTest {
virtual void SetUp();
virtual void TearDown();

private:
scoped_ptr<MessageLoopForIO> message_loop_;
private:
scoped_ptr<base::MessageLoopForIO> message_loop_;
};

const std::string IPCChannelPosixTest::GetChannelDirName() {
Expand All @@ -126,7 +126,7 @@ const std::string IPCChannelPosixTest::GetConnectionSocketName() {
void IPCChannelPosixTest::SetUp() {
MultiProcessTest::SetUp();
// Construct a fresh IO Message loop for the duration of each test.
message_loop_.reset(new MessageLoopForIO());
message_loop_.reset(new base::MessageLoopForIO());
}

void IPCChannelPosixTest::TearDown() {
Expand Down Expand Up @@ -180,15 +180,12 @@ void IPCChannelPosixTest::SetUpSocket(IPC::ChannelHandle *handle,
}

void IPCChannelPosixTest::SpinRunLoop(base::TimeDelta delay) {
MessageLoopForIO *loop = MessageLoopForIO::current();
base::MessageLoopForIO* loop = base::MessageLoopForIO::current();
// Post a quit task so that this loop eventually ends and we don't hang
// 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,
MessageLoop::QuitClosure(),
delay);
loop->PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), delay);
loop->Run();
}

Expand Down Expand Up @@ -391,7 +388,7 @@ TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) {

// A long running process that connects to us
MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) {
MessageLoopForIO message_loop;
base::MessageLoopForIO message_loop;
IPCChannelPosixTestListener listener(true);
IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
Expand All @@ -404,7 +401,7 @@ MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) {

// Simple external process that shouldn't be able to connect to us.
MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) {
MessageLoopForIO message_loop;
base::MessageLoopForIO message_loop;
IPCChannelPosixTestListener listener(false);
IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName());
IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT);
Expand Down
18 changes: 9 additions & 9 deletions ipc/ipc_channel_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class GenericChannelListener : public IPC::Listener {
virtual void OnChannelError() OVERRIDE {
// There is a race when closing the channel so the last message may be lost.
EXPECT_LE(messages_left_, 1);
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
}

void Init(IPC::Sender* s) {
Expand All @@ -75,7 +75,7 @@ class GenericChannelListener : public IPC::Listener {
protected:
void SendNextMessage() {
if (--messages_left_ <= 0)
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
else
Send(sender_, "Foo");
}
Expand Down Expand Up @@ -133,7 +133,7 @@ TEST_F(IPCChannelTest, ChannelTest) {
Send(sender(), "hello from parent");

// Run message loop.
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

// Close the channel so the client's OnChannelError() gets fired.
channel()->Close();
Expand Down Expand Up @@ -172,7 +172,7 @@ TEST_F(IPCChannelTest, ChannelTestExistingPipe) {
Send(sender(), "hello from parent");

// Run message loop.
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

// Close the channel so the client's OnChannelError() gets fired.
channel()->Close();
Expand All @@ -187,7 +187,7 @@ TEST_F(IPCChannelTest, ChannelProxyTest) {

base::Thread thread("ChannelProxyTestServer");
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
options.message_loop_type = base::MessageLoop::TYPE_IO;
thread.StartWithOptions(options);

// Set up IPC channel proxy.
Expand All @@ -200,7 +200,7 @@ TEST_F(IPCChannelTest, ChannelProxyTest) {
Send(sender(), "hello from parent");

// Run message loop.
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

EXPECT_TRUE(WaitForClientShutdown());

Expand Down Expand Up @@ -240,7 +240,7 @@ TEST_F(IPCChannelTest, MAYBE_SendMessageInChannelConnected) {
Send(sender(), "hello from parent");

// Run message loop.
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();

// Close the channel so the client's OnChannelError() gets fired.
channel()->Close();
Expand All @@ -250,7 +250,7 @@ TEST_F(IPCChannelTest, MAYBE_SendMessageInChannelConnected) {
}

MULTIPROCESS_IPC_TEST_CLIENT_MAIN(GenericClient) {
MessageLoopForIO main_message_loop;
base::MessageLoopForIO main_message_loop;
GenericChannelListener listener;

// Set up IPC channel.
Expand All @@ -261,7 +261,7 @@ MULTIPROCESS_IPC_TEST_CLIENT_MAIN(GenericClient) {
listener.Init(&channel);
Send(&channel, "hello from child");

MessageLoop::current()->Run();
base::MessageLoop::current()->Run();
return 0;
}

Expand Down
24 changes: 14 additions & 10 deletions ipc/ipc_channel_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void Channel::ChannelImpl::Close() {
// Make sure all IO has completed.
base::Time start = base::Time::Now();
while (input_state_.is_pending || output_state_.is_pending) {
MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this);
base::MessageLoopForIO::current()->WaitForIOCompletion(INFINITE, this);
}

while (!output_queue_.empty()) {
Expand Down Expand Up @@ -294,7 +294,7 @@ bool Channel::ChannelImpl::Connect() {
if (pipe_ == INVALID_HANDLE_VALUE)
return false;

MessageLoopForIO::current()->RegisterIOHandler(pipe_, this);
base::MessageLoopForIO::current()->RegisterIOHandler(pipe_, this);

// Check to see if there is a client connected to our pipe...
if (waiting_connect_)
Expand All @@ -304,10 +304,13 @@ bool Channel::ChannelImpl::Connect() {
// Complete setup asynchronously. By not setting input_state_.is_pending
// to true, we indicate to OnIOCompleted that this is the special
// initialization signal.
MessageLoopForIO::current()->PostTask(
FROM_HERE, base::Bind(&Channel::ChannelImpl::OnIOCompleted,
weak_factory_.GetWeakPtr(), &input_state_.context,
0, 0));
base::MessageLoopForIO::current()->PostTask(
FROM_HERE,
base::Bind(&Channel::ChannelImpl::OnIOCompleted,
weak_factory_.GetWeakPtr(),
&input_state_.context,
0,
0));
}

if (!waiting_connect_)
Expand Down Expand Up @@ -353,7 +356,7 @@ bool Channel::ChannelImpl::ProcessConnection() {
}

bool Channel::ChannelImpl::ProcessOutgoingMessages(
MessageLoopForIO::IOContext* context,
base::MessageLoopForIO::IOContext* context,
DWORD bytes_written) {
DCHECK(!waiting_connect_); // Why are we trying to send messages if there's
// no connection?
Expand Down Expand Up @@ -409,9 +412,10 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages(
return true;
}

void Channel::ChannelImpl::OnIOCompleted(MessageLoopForIO::IOContext* context,
DWORD bytes_transfered,
DWORD error) {
void Channel::ChannelImpl::OnIOCompleted(
base::MessageLoopForIO::IOContext* context,
DWORD bytes_transfered,
DWORD error) {
bool ok = true;
DCHECK(thread_check_->CalledOnValidThread());
if (context == &input_state_.context) {
Expand Down
12 changes: 7 additions & 5 deletions ipc/ipc_channel_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ThreadChecker;
namespace IPC {

class Channel::ChannelImpl : public internal::ChannelReader,
public MessageLoopForIO::IOHandler {
public base::MessageLoopForIO::IOHandler {
public:
// Mirror methods of Channel, see ipc_channel.h for description.
ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode,
Expand All @@ -48,17 +48,19 @@ class Channel::ChannelImpl : public internal::ChannelReader,
bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode);

bool ProcessConnection();
bool ProcessOutgoingMessages(MessageLoopForIO::IOContext* context,
bool ProcessOutgoingMessages(base::MessageLoopForIO::IOContext* context,
DWORD bytes_written);

// MessageLoop::IOHandler implementation.
virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
DWORD bytes_transfered, DWORD error);
virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context,
DWORD bytes_transfered,
DWORD error);

private:
struct State {
explicit State(ChannelImpl* channel);
~State();
MessageLoopForIO::IOContext context;
base::MessageLoopForIO::IOContext context;
bool is_pending;
};

Expand Down
10 changes: 5 additions & 5 deletions ipc/ipc_fuzzing_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class FuzzerServerListener : public SimpleListener {
--message_count_;
--pending_messages_;
if (0 == message_count_)
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
}

void ReplyMsgNotHandled(uint32 type_id) {
Expand All @@ -201,7 +201,7 @@ class FuzzerClientListener : public SimpleListener {

virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE {
last_msg_ = new IPC::Message(msg);
MessageLoop::current()->Quit();
base::MessageLoop::current()->Quit();
return true;
}

Expand Down Expand Up @@ -231,7 +231,7 @@ class FuzzerClientListener : public SimpleListener {

private:
bool MsgHandlerInternal(uint32 type_id) {
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();
if (NULL == last_msg_)
return false;
if (FUZZER_ROUTING_ID != last_msg_->routing_id())
Expand All @@ -245,14 +245,14 @@ class FuzzerClientListener : public SimpleListener {
// Runs the fuzzing server child mode. Returns when the preset number of
// messages have been received.
MULTIPROCESS_IPC_TEST_CLIENT_MAIN(FuzzServerClient) {
MessageLoopForIO main_message_loop;
base::MessageLoopForIO main_message_loop;
FuzzerServerListener listener;
IPC::Channel channel(IPCTestBase::GetChannelName("FuzzServerClient"),
IPC::Channel::MODE_CLIENT,
&listener);
CHECK(channel.Connect());
listener.Init(&channel);
MessageLoop::current()->Run();
base::MessageLoop::current()->Run();
return 0;
}

Expand Down
Loading

0 comments on commit fd0a773

Please sign in to comment.