OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IPC_IPC_CHANNEL_HANDLE_H_ | 5 #ifndef IPC_IPC_CHANNEL_HANDLE_H_ |
6 #define IPC_IPC_CHANNEL_HANDLE_H_ | 6 #define IPC_IPC_CHANNEL_HANDLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 #if defined(OS_POSIX) | 13 #if defined(OS_POSIX) |
14 #include "base/file_descriptor_posix.h" | 14 #include "base/file_descriptor_posix.h" |
15 #endif | 15 #endif |
16 #if defined(OS_WIN) | |
jam
2012/01/20 23:25:06
nit: in this file and ipc_message_utils.cc, if the
| |
17 #include <windows.h> | |
18 #endif // defined (OS_WIN) | |
16 | 19 |
17 // On Windows, any process can create an IPC channel and others can fetch | 20 // On Windows, any process can create an IPC channel and others can fetch |
18 // it by name. We pass around the channel names over IPC. | 21 // it by name. We pass around the channel names over IPC. |
22 // On Windows the initialization of ChannelHandle with an existing pipe | |
23 // handle is provided for convenience. | |
24 // NOTE: A ChannelHandle with a pipe handle Will NOT be marshalled over IPC. | |
25 | |
19 // On POSIX, we instead pass around handles to channel endpoints via IPC. | 26 // On POSIX, we instead pass around handles to channel endpoints via IPC. |
20 // When it's time to IPC a new channel endpoint around, we send both the | 27 // When it's time to IPC a new channel endpoint around, we send both the |
21 // channel name as well as a base::FileDescriptor, which is itself a special | 28 // channel name as well as a base::FileDescriptor, which is itself a special |
22 // type that knows how to copy a socket endpoint over IPC. | 29 // type that knows how to copy a socket endpoint over IPC. |
23 // | 30 // |
24 // In sum, when passing a handle to a channel over IPC, use this data structure | 31 // In sum, this data structure can be used to pass channel information by name |
25 // to work on both Windows and POSIX. | 32 // in both Windows and Posix. When passing a handle to a channel over IPC, |
33 // use this data structure only for POSIX. | |
26 | 34 |
27 namespace IPC { | 35 namespace IPC { |
28 | 36 |
29 struct ChannelHandle { | 37 struct ChannelHandle { |
30 // Note that serialization for this object is defined in the ParamTraits | 38 // Note that serialization for this object is defined in the ParamTraits |
31 // template specialization in ipc_message_utils.h. | 39 // template specialization in ipc_message_utils.h. |
32 ChannelHandle() {} | 40 ChannelHandle() {} |
33 // The name that is passed in should be an absolute path for Posix. | 41 // The name that is passed in should be an absolute path for Posix. |
34 // Otherwise there may be a problem in IPC communication between | 42 // Otherwise there may be a problem in IPC communication between |
35 // processes with different working directories. | 43 // processes with different working directories. |
36 ChannelHandle(const std::string& n) : name(n) {} | 44 ChannelHandle(const std::string& n) : name(n) {} |
37 ChannelHandle(const char* n) : name(n) {} | 45 ChannelHandle(const char* n) : name(n) {} |
46 #if defined(OS_WIN) | |
47 explicit ChannelHandle(HANDLE h) : pipe(h) {} | |
48 #endif // defined (OS_WIN) | |
38 #if defined(OS_POSIX) | 49 #if defined(OS_POSIX) |
39 ChannelHandle(const std::string& n, const base::FileDescriptor& s) | 50 ChannelHandle(const std::string& n, const base::FileDescriptor& s) |
40 : name(n), socket(s) {} | 51 : name(n), socket(s) {} |
41 #endif // defined(OS_POSIX) | 52 #endif // defined(OS_POSIX) |
42 | 53 |
43 std::string name; | 54 std::string name; |
44 #if defined(OS_POSIX) | 55 #if defined(OS_POSIX) |
45 base::FileDescriptor socket; | 56 base::FileDescriptor socket; |
46 #endif // defined(OS_POSIX) | 57 #endif // defined(OS_POSIX) |
47 | 58 #if defined(OS_WIN) |
59 // A simple container to automatically initialize pipe handle | |
60 struct PipeHandle { | |
61 PipeHandle() : handle(NULL) {} | |
62 PipeHandle(HANDLE h) : handle(h) {} | |
63 HANDLE handle; | |
64 }; | |
65 PipeHandle pipe; | |
66 #endif // defined (OS_WIN) | |
48 }; | 67 }; |
49 | 68 |
50 } // namespace IPC | 69 } // namespace IPC |
51 | 70 |
52 #endif // IPC_IPC_CHANNEL_HANDLE_H_ | 71 #endif // IPC_IPC_CHANNEL_HANDLE_H_ |
OLD | NEW |