diff options
author | amit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 02:36:05 +0000 |
---|---|---|
committer | amit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 02:36:05 +0000 |
commit | a7c03d4f3c5b36df2375ff24d5e279221ae65ed1 (patch) | |
tree | ee5d8eeab67c65059c0e24697b88ba7532b591c1 /ipc/ipc_tests.cc | |
parent | e855c3245ecfcb88e8782c2e6f9ad4f75e9eb912 (diff) | |
download | chromium_src-a7c03d4f3c5b36df2375ff24d5e279221ae65ed1.zip chromium_src-a7c03d4f3c5b36df2375ff24d5e279221ae65ed1.tar.gz chromium_src-a7c03d4f3c5b36df2375ff24d5e279221ae65ed1.tar.bz2 |
Initialize IPC:ChannelHandle from existing HANDLE
1] Add a ctor to IPC:ChannelHandle that takes a pipe HANDLE.
2] Corresponding change in Channel::ChannelImpl::CreatePipe to
attach to the given pipe instead of creating a new one.
Being able to hand over a pipe handle to IPC::Channel in this way has
other advantages such as using anonymous pipes and safer connections
between process with different level of privileges. Here's how it
can be done:
Server Process:
- Create a server pipe, anonymous pipe is fine too.
- Server creates a client handle of pipe using CreateFile.
- Use DuplicateHandle to duplicate this handle for the client process.
- pass over the handle value to the client process, say using comman line.
Client process:
- Simply receive the handle from the server and hand it over to
IPC:Channel using IPC::ChannelHandle.
Apart from being more flexible, this is more secure as it removes
the 'connection window' while using names.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/9150030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_tests.cc')
-rw-r--r-- | ipc/ipc_tests.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/ipc/ipc_tests.cc b/ipc/ipc_tests.cc index b6fd38b..2a78f44 100644 --- a/ipc/ipc_tests.cc +++ b/ipc/ipc_tests.cc @@ -240,6 +240,47 @@ TEST_F(IPCChannelTest, ChannelTest) { base::CloseProcessHandle(process_handle); } +#if defined(OS_WIN) +TEST_F(IPCChannelTest, ChannelTestExistingPipe) { + MyChannelListener channel_listener; + // Setup IPC channel with existing pipe. Specify name in Chrome format. + std::string name("\\\\.\\pipe\\chrome."); + name.append(kTestClientChannel); + const DWORD open_mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | + FILE_FLAG_FIRST_PIPE_INSTANCE; + HANDLE pipe = CreateNamedPipeA(name.c_str(), + open_mode, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, + 1, + 4096, + 4096, + 5000, + NULL); + IPC::Channel chan(IPC::ChannelHandle(pipe), IPC::Channel::MODE_SERVER, + &channel_listener); + // Channel will duplicate the handle. + CloseHandle(pipe); + ASSERT_TRUE(chan.Connect()); + + channel_listener.Init(&chan); + + base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT, &chan); + ASSERT_TRUE(process_handle); + + Send(&chan, "hello from parent"); + + // Run message loop. + MessageLoop::current()->Run(); + + // Close Channel so client gets its OnChannelError() callback fired. + chan.Close(); + + // Cleanup child process. + EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000)); + base::CloseProcessHandle(process_handle); +} +#endif // defined (OS_WIN) + TEST_F(IPCChannelTest, ChannelProxyTest) { MyChannelListener channel_listener; |