summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_channel_handle.h
diff options
context:
space:
mode:
authoramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-24 02:36:05 +0000
committeramit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-24 02:36:05 +0000
commita7c03d4f3c5b36df2375ff24d5e279221ae65ed1 (patch)
treeee5d8eeab67c65059c0e24697b88ba7532b591c1 /ipc/ipc_channel_handle.h
parente855c3245ecfcb88e8782c2e6f9ad4f75e9eb912 (diff)
downloadchromium_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_channel_handle.h')
-rw-r--r--ipc/ipc_channel_handle.h30
1 files changed, 23 insertions, 7 deletions
diff --git a/ipc/ipc_channel_handle.h b/ipc/ipc_channel_handle.h
index ba034cc..7eceebb 100644
--- a/ipc/ipc_channel_handle.h
+++ b/ipc/ipc_channel_handle.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -12,17 +12,24 @@
#if defined(OS_POSIX)
#include "base/file_descriptor_posix.h"
-#endif
+#elif defined(OS_WIN)
+#include <windows.h>
+#endif // defined (OS_WIN)
// On Windows, any process can create an IPC channel and others can fetch
// it by name. We pass around the channel names over IPC.
+// On Windows the initialization of ChannelHandle with an existing pipe
+// handle is provided for convenience.
+// NOTE: A ChannelHandle with a pipe handle Will NOT be marshalled over IPC.
+
// On POSIX, we instead pass around handles to channel endpoints via IPC.
// When it's time to IPC a new channel endpoint around, we send both the
// channel name as well as a base::FileDescriptor, which is itself a special
// type that knows how to copy a socket endpoint over IPC.
//
-// In sum, when passing a handle to a channel over IPC, use this data structure
-// to work on both Windows and POSIX.
+// In sum, this data structure can be used to pass channel information by name
+// in both Windows and Posix. When passing a handle to a channel over IPC,
+// use this data structure only for POSIX.
namespace IPC {
@@ -35,7 +42,9 @@ struct ChannelHandle {
// processes with different working directories.
ChannelHandle(const std::string& n) : name(n) {}
ChannelHandle(const char* n) : name(n) {}
-#if defined(OS_POSIX)
+#if defined(OS_WIN)
+ explicit ChannelHandle(HANDLE h) : pipe(h) {}
+#elif defined(OS_POSIX)
ChannelHandle(const std::string& n, const base::FileDescriptor& s)
: name(n), socket(s) {}
#endif // defined(OS_POSIX)
@@ -43,8 +52,15 @@ struct ChannelHandle {
std::string name;
#if defined(OS_POSIX)
base::FileDescriptor socket;
-#endif // defined(OS_POSIX)
-
+#elif defined(OS_WIN)
+ // A simple container to automatically initialize pipe handle
+ struct PipeHandle {
+ PipeHandle() : handle(NULL) {}
+ PipeHandle(HANDLE h) : handle(h) {}
+ HANDLE handle;
+ };
+ PipeHandle pipe;
+#endif // defined (OS_WIN)
};
} // namespace IPC