diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-29 21:10:32 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-29 21:10:32 +0000 |
commit | cfa4e4bc94157b66e59d02c721387323a06b2af3 (patch) | |
tree | 9550cbf374c1e0249dcde903f5009b22a056c7b7 | |
parent | 4db51ec6941bfbad574f812730206b5519bbe7c4 (diff) | |
download | chromium_src-cfa4e4bc94157b66e59d02c721387323a06b2af3.zip chromium_src-cfa4e4bc94157b66e59d02c721387323a06b2af3.tar.gz chromium_src-cfa4e4bc94157b66e59d02c721387323a06b2af3.tar.bz2 |
Revert 273575 "Introduce IPC::Channel::Create*() to ensure it be..."
Broke win compile.
> Introduce IPC::Channel::Create*() to ensure it being heap-allocated.
>
> This change introduces IPC::Channel::Create*() API to turn
> IPC::Channel into a heap allocated object. This will allow us to
> make Channel a polymorphic class.
>
> This change also tries to hide Channel::Mode from public API
> so that we can simplify channel creation code paths cleaner in
> following changes. ChannelProxy has to follow same pattern to
> finish this cleanup. Such changes will follow.
>
> TEST=none
> BUG=377980
> R=darin@chromium.org,cpu@chromium.org
>
> Review URL: https://codereview.chromium.org/307653003
TBR=morrita@chromium.org
Review URL: https://codereview.chromium.org/304153005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273596 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/pepper_flash_settings_manager.cc | 2 | ||||
-rw-r--r-- | chrome/utility/importer/firefox_importer_unittest_utils_mac.cc | 11 | ||||
-rw-r--r-- | components/nacl/broker/nacl_broker_listener.cc | 3 | ||||
-rw-r--r-- | components/nacl/loader/nacl_ipc_adapter.cc | 3 | ||||
-rw-r--r-- | content/browser/plugin_data_remover_impl.cc | 2 | ||||
-rw-r--r-- | content/browser/plugin_service_impl_browsertest.cc | 2 | ||||
-rw-r--r-- | content/common/child_process_host_impl.cc | 3 | ||||
-rw-r--r-- | content/renderer/render_thread_impl_browsertest.cc | 5 | ||||
-rw-r--r-- | ipc/BUILD.gn | 1 | ||||
-rw-r--r-- | ipc/ipc.gypi | 1 | ||||
-rw-r--r-- | ipc/ipc_channel.h | 57 | ||||
-rw-r--r-- | ipc/ipc_channel_common.cc | 55 | ||||
-rw-r--r-- | ipc/ipc_channel_posix_unittest.cc | 151 | ||||
-rw-r--r-- | ipc/ipc_channel_proxy.cc | 2 | ||||
-rw-r--r-- | ipc/ipc_channel_proxy_unittest.cc | 10 | ||||
-rw-r--r-- | ipc/ipc_channel_unittest.cc | 12 | ||||
-rw-r--r-- | ipc/ipc_fuzzing_tests.cc | 10 | ||||
-rw-r--r-- | ipc/ipc_perftests.cc | 9 | ||||
-rw-r--r-- | ipc/ipc_send_fds_test.cc | 16 | ||||
-rw-r--r-- | ipc/ipc_test_base.cc | 4 | ||||
-rw-r--r-- | ipc/sync_socket_unittest.cc | 10 |
21 files changed, 138 insertions, 231 deletions
diff --git a/chrome/browser/pepper_flash_settings_manager.cc b/chrome/browser/pepper_flash_settings_manager.cc index 7a3230f..1945d67 100644 --- a/chrome/browser/pepper_flash_settings_manager.cc +++ b/chrome/browser/pepper_flash_settings_manager.cc @@ -353,7 +353,7 @@ void PepperFlashSettingsManager::Core::ConnectToChannel( return; } - channel_ = IPC::Channel::CreateClient(handle, this); + channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this)); if (!channel_->Connect()) { DLOG(ERROR) << "Couldn't connect to plugin"; NotifyErrorFromIOThread(); diff --git a/chrome/utility/importer/firefox_importer_unittest_utils_mac.cc b/chrome/utility/importer/firefox_importer_unittest_utils_mac.cc index 9608f63..5c385de 100644 --- a/chrome/utility/importer/firefox_importer_unittest_utils_mac.cc +++ b/chrome/utility/importer/firefox_importer_unittest_utils_mac.cc @@ -130,7 +130,9 @@ bool FFUnitTestDecryptorProxy::Setup(const base::FilePath& nss_path) { message_loop_.reset(new base::MessageLoopForIO()); listener_.reset(new FFDecryptorServerChannelListener()); - channel_ = IPC::Channel::CreateServer(kTestChannelID, listener_.get()); + channel_.reset(new IPC::Channel(kTestChannelID, + IPC::Channel::MODE_SERVER, + listener_.get())); CHECK(channel_->Connect()); listener_->SetSender(channel_.get()); @@ -262,10 +264,9 @@ MULTIPROCESS_IPC_TEST_MAIN(NSSDecrypterChildProcess) { base::MessageLoopForIO main_message_loop; FFDecryptorClientChannelListener listener; - scoped_ptr<IPC::Channel> channel = IPC::Channel::CreateClient( - kTestChannelID, &listener); - CHECK(channel->Connect()); - listener.SetSender(channel.get()); + IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); + CHECK(channel.Connect()); + listener.SetSender(&channel); // run message loop base::MessageLoop::current()->Run(); diff --git a/components/nacl/broker/nacl_broker_listener.cc b/components/nacl/broker/nacl_broker_listener.cc index bceed22..c4f268da 100644 --- a/components/nacl/broker/nacl_broker_listener.cc +++ b/components/nacl/broker/nacl_broker_listener.cc @@ -40,7 +40,8 @@ void NaClBrokerListener::Listen() { std::string channel_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); - channel_ = IPC::Channel::CreateClient(channel_name, this); + channel_.reset(new IPC::Channel( + channel_name, IPC::Channel::MODE_CLIENT, this)); CHECK(channel_->Connect()); base::MessageLoop::current()->Run(); } diff --git a/components/nacl/loader/nacl_ipc_adapter.cc b/components/nacl/loader/nacl_ipc_adapter.cc index d3160e4..1398b22 100644 --- a/components/nacl/loader/nacl_ipc_adapter.cc +++ b/components/nacl/loader/nacl_ipc_adapter.cc @@ -329,7 +329,8 @@ NaClIPCAdapter::NaClIPCAdapter(const IPC::ChannelHandle& handle, cond_var_(&lock_), task_runner_(runner), locked_data_() { - io_thread_data_.channel_ = IPC::Channel::CreateServer(handle, this); + io_thread_data_.channel_.reset( + new IPC::Channel(handle, IPC::Channel::MODE_SERVER, this)); // Note, we can not PostTask for ConnectChannelOnIOThread here. If we did, // and that task ran before this constructor completes, the reference count // would go to 1 and then to 0 because of the Task, before we've been returned diff --git a/content/browser/plugin_data_remover_impl.cc b/content/browser/plugin_data_remover_impl.cc index a318e72..9133e59 100644 --- a/content/browser/plugin_data_remover_impl.cc +++ b/content/browser/plugin_data_remover_impl.cc @@ -226,7 +226,7 @@ class PluginDataRemoverImpl::Context return; DCHECK(!channel_.get()); - channel_ = IPC::Channel::CreateClient(handle, this); + channel_.reset(new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this)); if (!channel_->Connect()) { NOTREACHED() << "Couldn't connect to plugin"; SignalDone(); diff --git a/content/browser/plugin_service_impl_browsertest.cc b/content/browser/plugin_service_impl_browsertest.cc index 7a3271e..44f4754 100644 --- a/content/browser/plugin_service_impl_browsertest.cc +++ b/content/browser/plugin_service_impl_browsertest.cc @@ -60,7 +60,7 @@ class MockPluginProcessHostClient : public PluginProcessHost::Client, ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); ASSERT_TRUE(set_plugin_info_called_); ASSERT_TRUE(!channel_); - channel_ = IPC::Channel::CreateClient(handle, this).release(); + channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this); ASSERT_TRUE(channel_->Connect()); } diff --git a/content/common/child_process_host_impl.cc b/content/common/child_process_host_impl.cc index 1dccab0..9ae7c82 100644 --- a/content/common/child_process_host_impl.cc +++ b/content/common/child_process_host_impl.cc @@ -164,7 +164,8 @@ void ChildProcessHostImpl::ForceShutdown() { std::string ChildProcessHostImpl::CreateChannel() { channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); - channel_ = IPC::Channel::CreateServer(channel_id_, this); + channel_.reset(new IPC::Channel( + channel_id_, IPC::Channel::MODE_SERVER, this)); if (!channel_->Connect()) return std::string(); diff --git a/content/renderer/render_thread_impl_browsertest.cc b/content/renderer/render_thread_impl_browsertest.cc index 11d486e..6715ef3 100644 --- a/content/renderer/render_thread_impl_browsertest.cc +++ b/content/renderer/render_thread_impl_browsertest.cc @@ -57,9 +57,8 @@ TEST_F(RenderThreadImplBrowserTest, std::string channel_id = IPC::Channel::GenerateVerifiedChannelID( std::string()); DummyListener dummy_listener; - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateServer(channel_id, &dummy_listener)); - ASSERT_TRUE(channel->Connect()); + IPC::Channel channel(channel_id, IPC::Channel::MODE_SERVER, &dummy_listener); + ASSERT_TRUE(channel.Connect()); scoped_ptr<MockRenderProcess> mock_process(new MockRenderProcess); // Owned by mock_process. diff --git a/ipc/BUILD.gn b/ipc/BUILD.gn index 3bff55e..9d9e49a 100644 --- a/ipc/BUILD.gn +++ b/ipc/BUILD.gn @@ -8,7 +8,6 @@ component("ipc") { "file_descriptor_set_posix.h", "ipc_channel.cc", "ipc_channel.h", - "ipc_channel_common.cc", "ipc_channel_factory.cc", "ipc_channel_factory.h", "ipc_channel_handle.h", diff --git a/ipc/ipc.gypi b/ipc/ipc.gypi index e7d5cc6..fd23fb0 100644 --- a/ipc/ipc.gypi +++ b/ipc/ipc.gypi @@ -15,7 +15,6 @@ 'file_descriptor_set_posix.h', 'ipc_channel.cc', 'ipc_channel.h', - 'ipc_channel_common.cc', 'ipc_channel_factory.cc', 'ipc_channel_factory.h', 'ipc_channel_handle.h', diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index be8f83c..4426e5d 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -55,15 +55,21 @@ class IPC_EXPORT Channel : public Sender { }; // Some Standard Modes - // TODO(morrita): These are under deprecation work. You should use Create*() - // functions instead. enum Mode { MODE_NONE = MODE_NO_FLAG, MODE_SERVER = MODE_SERVER_FLAG, MODE_CLIENT = MODE_CLIENT_FLAG, + // Channels on Windows are named by default and accessible from other + // processes. On POSIX channels are anonymous by default and not accessible + // from other processes. Named channels work via named unix domain sockets. + // On Windows MODE_NAMED_SERVER is equivalent to MODE_SERVER and + // MODE_NAMED_CLIENT is equivalent to MODE_CLIENT. MODE_NAMED_SERVER = MODE_SERVER_FLAG | MODE_NAMED_FLAG, MODE_NAMED_CLIENT = MODE_CLIENT_FLAG | MODE_NAMED_FLAG, #if defined(OS_POSIX) + // An "open" named server accepts connections from ANY client. + // The caller must then implement their own access-control based on the + // client process' user Id. MODE_OPEN_NAMED_SERVER = MODE_OPEN_ACCESS_FLAG | MODE_SERVER_FLAG | MODE_NAMED_FLAG #endif @@ -100,47 +106,15 @@ class IPC_EXPORT Channel : public Sender { // the file descriptor in the channel handle is != -1, the channel takes // ownership of the file descriptor and will close it appropriately, otherwise // it will create a new descriptor internally. + // |mode| specifies whether this Channel is to operate in server mode or + // client mode. In server mode, the Channel is responsible for setting up the + // IPC object, whereas in client mode, the Channel merely connects to the + // already established IPC object. // |listener| receives a callback on the current thread for each newly // received message. // - // There are four type of modes how channels operate: - // - // - Server and named server: In these modes, the Channel is - // responsible for settingb up the IPC object - // - An "open" named server: It accepts connections from ANY client. - // The caller must then implement their own access-control based on the - // client process' user Id. - // - Client and named client: In these mode, the Channel merely - // connects to the already established IPC object. - // - // Each mode has its own Create*() API to create the Channel object. - // - // TODO(morrita): Replace CreateByModeForProxy() with one of above Create*(). - // - static scoped_ptr<Channel> CreateByModeForProxy( - const IPC::ChannelHandle &channel_handle, Mode mode,Listener* listener); - static scoped_ptr<Channel> CreateClient( - const IPC::ChannelHandle &channel_handle, Listener* listener); - - // Channels on Windows are named by default and accessible from other - // processes. On POSIX channels are anonymous by default and not accessible - // from other processes. Named channels work via named unix domain sockets. - // On Windows MODE_NAMED_SERVER is equivalent to MODE_SERVER and - // MODE_NAMED_CLIENT is equivalent to MODE_CLIENT. - static scoped_ptr<Channel> CreateNamedServer( - const IPC::ChannelHandle &channel_handle, Listener* listener); - static scoped_ptr<Channel> CreateNamedClient( - const IPC::ChannelHandle &channel_handle, Listener* listener); -#if defined(OS_POSIX) - // An "open" named server accepts connections from ANY client. - // The caller must then implement their own access-control based on the - // client process' user Id. - static scoped_ptr<Channel> CreateOpenNamedServer( - const IPC::ChannelHandle &channel_handle, Listener* listener); -#endif - static scoped_ptr<Channel> CreateServer( - const IPC::ChannelHandle &channel_handle, Listener* listener); - + Channel(const IPC::ChannelHandle &channel_handle, Mode mode, + Listener* listener); virtual ~Channel(); @@ -246,9 +220,6 @@ class IPC_EXPORT Channel : public Sender { Channel() : channel_impl_(0) { } private: - Channel(const IPC::ChannelHandle &channel_handle, Mode mode, - Listener* listener); - // PIMPL to which all channel calls are delegated. class ChannelImpl; ChannelImpl *channel_impl_; diff --git a/ipc/ipc_channel_common.cc b/ipc/ipc_channel_common.cc deleted file mode 100644 index c5ceba3e..0000000 --- a/ipc/ipc_channel_common.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ipc/ipc_channel.h" - -namespace IPC { - -// static -scoped_ptr<Channel> Channel::CreateByModeForProxy( - const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, mode, listener)); -} - -// static -scoped_ptr<Channel> Channel::CreateClient( - const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_CLIENT, listener)); -} - -// static -scoped_ptr<Channel> Channel::CreateNamedServer( - const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_NAMED_SERVER, listener)); -} - -// static -scoped_ptr<Channel> Channel::CreateNamedClient( - const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_NAMED_CLIENT, listener)); -} - -#if defined(OS_POSIX) -// static -scoped_ptr<Channel> Channel::CreateOpenNamedServer( - const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_OPEN_NAMED_SERVER, listener)); -} -#endif - -// static -scoped_ptr<Channel> Channel::CreateServer( - const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_SERVER, listener)); -} - - -} // namespace IPC - diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc index d001920..6f3962b 100644 --- a/ipc/ipc_channel_posix_unittest.cc +++ b/ipc/ipc_channel_posix_unittest.cc @@ -204,13 +204,12 @@ TEST_F(IPCChannelPosixTest, BasicListen) { IPC::ChannelHandle handle(kChannelName); SetUpSocket(&handle, IPC::Channel::MODE_NAMED_SERVER); unlink(handle.name.c_str()); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedServer(handle, NULL)); - ASSERT_TRUE(channel->Connect()); - ASSERT_TRUE(channel->AcceptsConnections()); - ASSERT_FALSE(channel->HasAcceptedConnection()); - channel->ResetToAcceptingConnectionState(); - ASSERT_FALSE(channel->HasAcceptedConnection()); + IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_SERVER, NULL); + ASSERT_TRUE(channel.Connect()); + ASSERT_TRUE(channel.AcceptsConnections()); + ASSERT_FALSE(channel.HasAcceptedConnection()); + channel.ResetToAcceptingConnectionState(); + ASSERT_FALSE(channel.HasAcceptedConnection()); } TEST_F(IPCChannelPosixTest, BasicConnected) { @@ -222,18 +221,17 @@ TEST_F(IPCChannelPosixTest, BasicConnected) { base::FileDescriptor fd(pipe_fds[0], false); IPC::ChannelHandle handle(socket_name, fd); - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateServer(handle, NULL)); - ASSERT_TRUE(channel->Connect()); - ASSERT_FALSE(channel->AcceptsConnections()); - channel->Close(); + IPC::Channel channel(handle, IPC::Channel::MODE_SERVER, NULL); + ASSERT_TRUE(channel.Connect()); + ASSERT_FALSE(channel.AcceptsConnections()); + channel.Close(); ASSERT_TRUE(IGNORE_EINTR(close(pipe_fds[1])) == 0); // Make sure that we can use the socket that is created for us by // a standard channel. - scoped_ptr<IPC::Channel> channel2( - IPC::Channel::CreateServer(socket_name, NULL)); - ASSERT_TRUE(channel2->Connect()); - ASSERT_FALSE(channel2->AcceptsConnections()); + IPC::Channel channel2(socket_name, IPC::Channel::MODE_SERVER, NULL); + ASSERT_TRUE(channel2.Connect()); + ASSERT_FALSE(channel2.AcceptsConnections()); } // If a connection closes right before a Send() call, we may end up closing @@ -243,17 +241,15 @@ TEST_F(IPCChannelPosixTest, SendHangTest) { IPCChannelPosixTestListener out_listener(true); IPCChannelPosixTestListener in_listener(true); IPC::ChannelHandle in_handle("IN"); - scoped_ptr<IPC::Channel> in_chan( - IPC::Channel::CreateServer(in_handle, &in_listener)); - base::FileDescriptor out_fd(in_chan->TakeClientFileDescriptor(), false); + IPC::Channel in_chan(in_handle, IPC::Channel::MODE_SERVER, &in_listener); + base::FileDescriptor out_fd(in_chan.TakeClientFileDescriptor(), false); IPC::ChannelHandle out_handle("OUT", out_fd); - scoped_ptr<IPC::Channel> out_chan( - IPC::Channel::CreateClient(out_handle, &out_listener)); - ASSERT_TRUE(in_chan->Connect()); - ASSERT_TRUE(out_chan->Connect()); - in_chan->Close(); // simulate remote process dying at an unfortunate time. + IPC::Channel out_chan(out_handle, IPC::Channel::MODE_CLIENT, &out_listener); + ASSERT_TRUE(in_chan.Connect()); + ASSERT_TRUE(out_chan.Connect()); + in_chan.Close(); // simulate remote process dying at an unfortunate time. // Send will fail, because it cannot write the message. - ASSERT_FALSE(out_chan->Send(new IPC::Message( + ASSERT_FALSE(out_chan.Send(new IPC::Message( 0, // routing_id kQuitMessage, // message type IPC::Message::PRIORITY_NORMAL))); @@ -268,15 +264,13 @@ TEST_F(IPCChannelPosixTest, AcceptHangTest) { IPCChannelPosixTestListener out_listener(true); IPCChannelPosixTestListener in_listener(true); IPC::ChannelHandle in_handle("IN"); - scoped_ptr<IPC::Channel> in_chan( - IPC::Channel::CreateServer(in_handle, &in_listener)); - base::FileDescriptor out_fd(in_chan->TakeClientFileDescriptor(), false); + IPC::Channel in_chan(in_handle, IPC::Channel::MODE_SERVER, &in_listener); + base::FileDescriptor out_fd(in_chan.TakeClientFileDescriptor(), false); IPC::ChannelHandle out_handle("OUT", out_fd); - scoped_ptr<IPC::Channel> out_chan( - IPC::Channel::CreateClient(out_handle, &out_listener)); - ASSERT_TRUE(in_chan->Connect()); - in_chan->Close(); // simulate remote process dying at an unfortunate time. - ASSERT_FALSE(out_chan->Connect()); + IPC::Channel out_chan(out_handle, IPC::Channel::MODE_CLIENT, &out_listener); + ASSERT_TRUE(in_chan.Connect()); + in_chan.Close(); // simulate remote process dying at an unfortunate time. + ASSERT_FALSE(out_chan.Connect()); SpinRunLoop(TestTimeouts::action_max_timeout()); ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status()); } @@ -286,27 +280,26 @@ TEST_F(IPCChannelPosixTest, AdvancedConnected) { IPCChannelPosixTestListener listener(false); IPC::ChannelHandle chan_handle(GetConnectionSocketName()); SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedServer(chan_handle, &listener)); - ASSERT_TRUE(channel->Connect()); - ASSERT_TRUE(channel->AcceptsConnections()); - ASSERT_FALSE(channel->HasAcceptedConnection()); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); + ASSERT_TRUE(channel.Connect()); + ASSERT_TRUE(channel.AcceptsConnections()); + ASSERT_FALSE(channel.HasAcceptedConnection()); base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc"); ASSERT_TRUE(handle); SpinRunLoop(TestTimeouts::action_max_timeout()); ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); - ASSERT_TRUE(channel->HasAcceptedConnection()); + ASSERT_TRUE(channel.HasAcceptedConnection()); IPC::Message* message = new IPC::Message(0, // routing_id kQuitMessage, // message type IPC::Message::PRIORITY_NORMAL); - channel->Send(message); + channel.Send(message); SpinRunLoop(TestTimeouts::action_timeout()); int exit_code = 0; EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); EXPECT_EQ(0, exit_code); ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); - ASSERT_FALSE(channel->HasAcceptedConnection()); + ASSERT_FALSE(channel.HasAcceptedConnection()); } TEST_F(IPCChannelPosixTest, ResetState) { @@ -316,44 +309,42 @@ TEST_F(IPCChannelPosixTest, ResetState) { IPCChannelPosixTestListener listener(false); IPC::ChannelHandle chan_handle(GetConnectionSocketName()); SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedServer(chan_handle, &listener)); - ASSERT_TRUE(channel->Connect()); - ASSERT_TRUE(channel->AcceptsConnections()); - ASSERT_FALSE(channel->HasAcceptedConnection()); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); + ASSERT_TRUE(channel.Connect()); + ASSERT_TRUE(channel.AcceptsConnections()); + ASSERT_FALSE(channel.HasAcceptedConnection()); base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc"); ASSERT_TRUE(handle); SpinRunLoop(TestTimeouts::action_max_timeout()); ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); - ASSERT_TRUE(channel->HasAcceptedConnection()); - channel->ResetToAcceptingConnectionState(); - ASSERT_FALSE(channel->HasAcceptedConnection()); + ASSERT_TRUE(channel.HasAcceptedConnection()); + channel.ResetToAcceptingConnectionState(); + ASSERT_FALSE(channel.HasAcceptedConnection()); base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixTestConnectionProc"); ASSERT_TRUE(handle2); SpinRunLoop(TestTimeouts::action_max_timeout()); ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); - ASSERT_TRUE(channel->HasAcceptedConnection()); + ASSERT_TRUE(channel.HasAcceptedConnection()); IPC::Message* message = new IPC::Message(0, // routing_id kQuitMessage, // message type IPC::Message::PRIORITY_NORMAL); - channel->Send(message); + channel.Send(message); SpinRunLoop(TestTimeouts::action_timeout()); EXPECT_TRUE(base::KillProcess(handle, 0, false)); int exit_code = 0; EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); EXPECT_EQ(0, exit_code); ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); - ASSERT_FALSE(channel->HasAcceptedConnection()); + ASSERT_FALSE(channel.HasAcceptedConnection()); } TEST_F(IPCChannelPosixTest, BadChannelName) { // Test empty name IPC::ChannelHandle handle(""); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedServer(handle, NULL)); - ASSERT_FALSE(channel->Connect()); + IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_SERVER, NULL); + ASSERT_FALSE(channel.Connect()); // Test name that is too long. const char *kTooLongName = "This_is_a_very_long_name_to_proactively_implement" @@ -365,9 +356,8 @@ TEST_F(IPCChannelPosixTest, BadChannelName) { "leading-edge_processes"; EXPECT_GE(strlen(kTooLongName), IPC::kMaxSocketNameLength); IPC::ChannelHandle handle2(kTooLongName); - scoped_ptr<IPC::Channel> channel2( - IPC::Channel::CreateNamedServer(handle2, NULL)); - EXPECT_FALSE(channel2->Connect()); + IPC::Channel channel2(handle2, IPC::Channel::MODE_NAMED_SERVER, NULL); + EXPECT_FALSE(channel2.Connect()); } TEST_F(IPCChannelPosixTest, MultiConnection) { @@ -376,17 +366,16 @@ TEST_F(IPCChannelPosixTest, MultiConnection) { IPCChannelPosixTestListener listener(false); IPC::ChannelHandle chan_handle(GetConnectionSocketName()); SetUpSocket(&chan_handle, IPC::Channel::MODE_NAMED_SERVER); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedServer(chan_handle, &listener)); - ASSERT_TRUE(channel->Connect()); - ASSERT_TRUE(channel->AcceptsConnections()); - ASSERT_FALSE(channel->HasAcceptedConnection()); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); + ASSERT_TRUE(channel.Connect()); + ASSERT_TRUE(channel.AcceptsConnections()); + ASSERT_FALSE(channel.HasAcceptedConnection()); base::ProcessHandle handle = SpawnChild("IPCChannelPosixTestConnectionProc"); ASSERT_TRUE(handle); SpinRunLoop(TestTimeouts::action_max_timeout()); ASSERT_EQ(IPCChannelPosixTestListener::CONNECTED, listener.status()); - ASSERT_TRUE(channel->HasAcceptedConnection()); + ASSERT_TRUE(channel.HasAcceptedConnection()); base::ProcessHandle handle2 = SpawnChild("IPCChannelPosixFailConnectionProc"); ASSERT_TRUE(handle2); SpinRunLoop(TestTimeouts::action_max_timeout()); @@ -394,16 +383,16 @@ TEST_F(IPCChannelPosixTest, MultiConnection) { EXPECT_TRUE(base::WaitForExitCode(handle2, &exit_code)); EXPECT_EQ(exit_code, 0); ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status()); - ASSERT_TRUE(channel->HasAcceptedConnection()); + ASSERT_TRUE(channel.HasAcceptedConnection()); IPC::Message* message = new IPC::Message(0, // routing_id kQuitMessage, // message type IPC::Message::PRIORITY_NORMAL); - channel->Send(message); + channel.Send(message); SpinRunLoop(TestTimeouts::action_timeout()); EXPECT_TRUE(base::WaitForExitCode(handle, &exit_code)); EXPECT_EQ(exit_code, 0); ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); - ASSERT_FALSE(channel->HasAcceptedConnection()); + ASSERT_FALSE(channel.HasAcceptedConnection()); } TEST_F(IPCChannelPosixTest, DoubleServer) { @@ -411,21 +400,18 @@ TEST_F(IPCChannelPosixTest, DoubleServer) { IPCChannelPosixTestListener listener(false); IPCChannelPosixTestListener listener2(false); IPC::ChannelHandle chan_handle(GetConnectionSocketName()); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateServer(chan_handle, &listener)); - scoped_ptr<IPC::Channel> channel2( - IPC::Channel::CreateServer(chan_handle, &listener2)); - ASSERT_TRUE(channel->Connect()); - ASSERT_FALSE(channel2->Connect()); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_SERVER, &listener); + IPC::Channel channel2(chan_handle, IPC::Channel::MODE_SERVER, &listener2); + ASSERT_TRUE(channel.Connect()); + ASSERT_FALSE(channel2.Connect()); } TEST_F(IPCChannelPosixTest, BadMode) { // Test setting up two servers with a bad mode. IPCChannelPosixTestListener listener(false); IPC::ChannelHandle chan_handle(GetConnectionSocketName()); - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateByModeForProxy( - chan_handle, IPC::Channel::MODE_NONE, &listener)); - ASSERT_FALSE(channel->Connect()); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_NONE, &listener); + ASSERT_FALSE(channel.Connect()); } TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { @@ -435,11 +421,10 @@ TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { ASSERT_TRUE(base::DeleteFile(base::FilePath(connection_socket_name), false)); ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( connection_socket_name)); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedServer(chan_handle, &listener)); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( connection_socket_name)); - channel->Close(); + channel.Close(); ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( connection_socket_name)); } @@ -450,9 +435,8 @@ MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { IPCChannelPosixTestListener listener(true); IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedClient(handle, &listener)); - EXPECT_TRUE(channel->Connect()); + IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); + EXPECT_TRUE(channel.Connect()); IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); EXPECT_EQ(IPCChannelPosixTestListener::MESSAGE_RECEIVED, listener.status()); return 0; @@ -464,15 +448,14 @@ MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { IPCChannelPosixTestListener listener(false); IPC::ChannelHandle handle(IPCChannelPosixTest::GetConnectionSocketName()); IPCChannelPosixTest::SetUpSocket(&handle, IPC::Channel::MODE_NAMED_CLIENT); - scoped_ptr<IPC::Channel> channel( - IPC::Channel::CreateNamedClient(handle, &listener)); + IPC::Channel channel(handle, IPC::Channel::MODE_NAMED_CLIENT, &listener); // In this case connect may succeed or fail depending on if the packet // actually gets sent at sendmsg. Since we never delay on send, we may not // see the error. However even if connect succeeds, eventually we will get an // error back since the channel will be closed when we attempt to read from // it. - bool connected = channel->Connect(); + bool connected = channel.Connect(); if (connected) { IPCChannelPosixTest::SpinRunLoop(TestTimeouts::action_max_timeout()); EXPECT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status()); diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc index e88bb5d..7e32018 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -52,7 +52,7 @@ void ChannelProxy::Context::CreateChannel(const IPC::ChannelHandle& handle, const Channel::Mode& mode) { DCHECK(!channel_); channel_id_ = handle.name; - channel_ = Channel::CreateByModeForProxy(handle, mode, this); + channel_.reset(new Channel(handle, mode, this)); } bool ChannelProxy::Context::TryFilters(const Message& message) { diff --git a/ipc/ipc_channel_proxy_unittest.cc b/ipc/ipc_channel_proxy_unittest.cc index 20e42e3..bd2381c 100644 --- a/ipc/ipc_channel_proxy_unittest.cc +++ b/ipc/ipc_channel_proxy_unittest.cc @@ -428,11 +428,11 @@ TEST_F(IPCChannelBadMessageTest, BadMessage) { MULTIPROCESS_IPC_TEST_CLIENT_MAIN(ChannelProxyClient) { base::MessageLoopForIO main_message_loop; ChannelReflectorListener listener; - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( - IPCTestBase::GetChannelName("ChannelProxyClient"), - &listener)); - CHECK(channel->Connect()); - listener.Init(channel.get()); + IPC::Channel channel(IPCTestBase::GetChannelName("ChannelProxyClient"), + IPC::Channel::MODE_CLIENT, + &listener); + CHECK(channel.Connect()); + listener.Init(&channel); base::MessageLoop::current()->Run(); return 0; diff --git a/ipc/ipc_channel_unittest.cc b/ipc/ipc_channel_unittest.cc index b9665db..eea432a 100644 --- a/ipc/ipc_channel_unittest.cc +++ b/ipc/ipc_channel_unittest.cc @@ -254,12 +254,12 @@ MULTIPROCESS_IPC_TEST_CLIENT_MAIN(GenericClient) { GenericChannelListener listener; // Set up IPC channel. - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( - IPCTestBase::GetChannelName("GenericClient"), - &listener)); - CHECK(channel->Connect()); - listener.Init(channel.get()); - Send(channel.get(), "hello from child"); + IPC::Channel channel(IPCTestBase::GetChannelName("GenericClient"), + IPC::Channel::MODE_CLIENT, + &listener); + CHECK(channel.Connect()); + listener.Init(&channel); + Send(&channel, "hello from child"); base::MessageLoop::current()->Run(); return 0; diff --git a/ipc/ipc_fuzzing_tests.cc b/ipc/ipc_fuzzing_tests.cc index 4abcc4c..1ed9acd 100644 --- a/ipc/ipc_fuzzing_tests.cc +++ b/ipc/ipc_fuzzing_tests.cc @@ -247,11 +247,11 @@ class FuzzerClientListener : public SimpleListener { MULTIPROCESS_IPC_TEST_CLIENT_MAIN(FuzzServerClient) { base::MessageLoopForIO main_message_loop; FuzzerServerListener listener; - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( - IPCTestBase::GetChannelName("FuzzServerClient"), - &listener)); - CHECK(channel->Connect()); - listener.Init(channel.get()); + IPC::Channel channel(IPCTestBase::GetChannelName("FuzzServerClient"), + IPC::Channel::MODE_CLIENT, + &listener); + CHECK(channel.Connect()); + listener.Init(&channel); base::MessageLoop::current()->Run(); return 0; } diff --git a/ipc/ipc_perftests.cc b/ipc/ipc_perftests.cc index 3feabda..d4b1abd 100644 --- a/ipc/ipc_perftests.cc +++ b/ipc/ipc_perftests.cc @@ -265,10 +265,11 @@ TEST_F(IPCChannelPerfTest, Performance) { MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) { base::MessageLoopForIO main_message_loop; ChannelReflectorListener listener; - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( - IPCTestBase::GetChannelName("PerformanceClient"), &listener)); - listener.Init(channel.get()); - CHECK(channel->Connect()); + IPC::Channel channel(IPCTestBase::GetChannelName("PerformanceClient"), + IPC::Channel::MODE_CLIENT, + &listener); + listener.Init(&channel); + CHECK(channel.Connect()); base::MessageLoop::current()->Run(); return 0; diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc index 7e6a4e4..aeec890 100644 --- a/ipc/ipc_send_fds_test.cc +++ b/ipc/ipc_send_fds_test.cc @@ -134,10 +134,10 @@ int SendFdsClientCommon(const std::string& test_client_name, MyChannelDescriptorListener listener(expected_inode_num); // Set up IPC channel. - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( - IPCTestBase::GetChannelName(test_client_name), - &listener)); - CHECK(channel->Connect()); + IPC::Channel channel(IPCTestBase::GetChannelName(test_client_name), + IPC::Channel::MODE_CLIENT, + &listener); + CHECK(channel.Connect()); // Run message loop. base::MessageLoop::current()->Run(); @@ -233,10 +233,14 @@ class PipeChannelHelper { void Init() { IPC::ChannelHandle in_handle("IN"); - in = IPC::Channel::CreateServer(in_handle, &null_listener_); + in.reset(new IPC::Channel(in_handle, + IPC::Channel::MODE_SERVER, + &null_listener_)); base::FileDescriptor out_fd(in->TakeClientFileDescriptor(), false); IPC::ChannelHandle out_handle("OUT", out_fd); - out = IPC::Channel::CreateClient(out_handle, &cb_listener_); + out.reset(new IPC::Channel(out_handle, + IPC::Channel::MODE_CLIENT, + &cb_listener_)); // PostTask the connect calls to make sure the callbacks happens // on the right threads. in_thread_->message_loop()->PostTask( diff --git a/ipc/ipc_test_base.cc b/ipc/ipc_test_base.cc index ca45d16..b609e8c 100644 --- a/ipc/ipc_test_base.cc +++ b/ipc/ipc_test_base.cc @@ -69,7 +69,9 @@ void IPCTestBase::CreateChannelFromChannelHandle( IPC::Listener* listener) { CHECK(!channel_.get()); CHECK(!channel_proxy_.get()); - channel_ = IPC::Channel::CreateServer(channel_handle, listener); + channel_.reset(new IPC::Channel(channel_handle, + IPC::Channel::MODE_SERVER, + listener)); } void IPCTestBase::CreateChannelProxy( diff --git a/ipc/sync_socket_unittest.cc b/ipc/sync_socket_unittest.cc index 5527abc..2888607 100644 --- a/ipc/sync_socket_unittest.cc +++ b/ipc/sync_socket_unittest.cc @@ -108,11 +108,11 @@ class SyncSocketServerListener : public IPC::Listener { MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SyncSocketServerClient) { base::MessageLoopForIO main_message_loop; SyncSocketServerListener listener; - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( - IPCTestBase::GetChannelName("SyncSocketServerClient"), - &listener)); - EXPECT_TRUE(channel->Connect()); - listener.Init(channel.get()); + IPC::Channel channel(IPCTestBase::GetChannelName("SyncSocketServerClient"), + IPC::Channel::MODE_CLIENT, + &listener); + EXPECT_TRUE(channel.Connect()); + listener.Init(&channel); base::MessageLoop::current()->Run(); return 0; } |