OLD | NEW |
1 // Copyright (c) 2012 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_H_ | 5 #ifndef IPC_IPC_CHANNEL_H_ |
6 #define IPC_IPC_CHANNEL_H_ | 6 #define IPC_IPC_CHANNEL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #if defined(OS_POSIX) | 12 #if defined(OS_POSIX) |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #endif | 14 #endif |
15 | 15 |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/files/scoped_file.h" | 17 #include "base/files/scoped_file.h" |
18 #include "base/process/process.h" | 18 #include "base/process/process.h" |
19 #include "ipc/ipc_channel_handle.h" | 19 #include "ipc/ipc_channel_handle.h" |
20 #include "ipc/ipc_endpoint.h" | 20 #include "ipc/ipc_endpoint.h" |
21 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
22 | 22 |
23 namespace IPC { | 23 namespace IPC { |
24 | 24 |
25 class AttachmentBroker; | |
26 class Listener; | 25 class Listener; |
27 | 26 |
28 //------------------------------------------------------------------------------ | 27 //------------------------------------------------------------------------------ |
29 // See | 28 // See |
30 // http://www.chromium.org/developers/design-documents/inter-process-communicati
on | 29 // http://www.chromium.org/developers/design-documents/inter-process-communicati
on |
31 // for overview of IPC in Chromium. | 30 // for overview of IPC in Chromium. |
32 | 31 |
33 // Channels are implemented using named pipes on Windows, and | 32 // Channels are implemented using named pipes on Windows, and |
34 // socket pairs (or in some special cases unix domain sockets) on POSIX. | 33 // socket pairs (or in some special cases unix domain sockets) on POSIX. |
35 // On Windows we access pipes in various processes by name. | 34 // On Windows we access pipes in various processes by name. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // responsible for settingb up the IPC object | 112 // responsible for settingb up the IPC object |
114 // - An "open" named server: It accepts connections from ANY client. | 113 // - An "open" named server: It accepts connections from ANY client. |
115 // The caller must then implement their own access-control based on the | 114 // The caller must then implement their own access-control based on the |
116 // client process' user Id. | 115 // client process' user Id. |
117 // - Client and named client: In these mode, the Channel merely | 116 // - Client and named client: In these mode, the Channel merely |
118 // connects to the already established IPC object. | 117 // connects to the already established IPC object. |
119 // | 118 // |
120 // Each mode has its own Create*() API to create the Channel object. | 119 // Each mode has its own Create*() API to create the Channel object. |
121 // | 120 // |
122 // TODO(morrita): Replace CreateByModeForProxy() with one of above Create*(). | 121 // TODO(morrita): Replace CreateByModeForProxy() with one of above Create*(). |
123 // | |
124 // TODO(erikchen): Remove default parameter for |broker|. It exists only to | |
125 // make the upcoming refactor decomposable into smaller CLs. | |
126 // http://crbug.com/493414. | |
127 static scoped_ptr<Channel> Create(const IPC::ChannelHandle& channel_handle, | 122 static scoped_ptr<Channel> Create(const IPC::ChannelHandle& channel_handle, |
128 Mode mode, | 123 Mode mode, |
129 Listener* listener, | 124 Listener* listener); |
130 AttachmentBroker* broker = nullptr); | |
131 | 125 |
132 // TODO(erikchen): Remove default parameter for |broker|. It exists only to | |
133 // make the upcoming refactor decomposable into smaller CLs. | |
134 // http://crbug.com/493414. | |
135 static scoped_ptr<Channel> CreateClient( | 126 static scoped_ptr<Channel> CreateClient( |
136 const IPC::ChannelHandle& channel_handle, | 127 const IPC::ChannelHandle& channel_handle, |
137 Listener* listener, | 128 Listener* listener); |
138 AttachmentBroker* broker = nullptr); | |
139 | 129 |
140 // Channels on Windows are named by default and accessible from other | 130 // Channels on Windows are named by default and accessible from other |
141 // processes. On POSIX channels are anonymous by default and not accessible | 131 // processes. On POSIX channels are anonymous by default and not accessible |
142 // from other processes. Named channels work via named unix domain sockets. | 132 // from other processes. Named channels work via named unix domain sockets. |
143 // On Windows MODE_NAMED_SERVER is equivalent to MODE_SERVER and | 133 // On Windows MODE_NAMED_SERVER is equivalent to MODE_SERVER and |
144 // MODE_NAMED_CLIENT is equivalent to MODE_CLIENT. | 134 // MODE_NAMED_CLIENT is equivalent to MODE_CLIENT. |
145 static scoped_ptr<Channel> CreateNamedServer( | 135 static scoped_ptr<Channel> CreateNamedServer( |
146 const IPC::ChannelHandle& channel_handle, | 136 const IPC::ChannelHandle& channel_handle, |
147 Listener* listener, | 137 Listener* listener); |
148 AttachmentBroker* broker); | |
149 static scoped_ptr<Channel> CreateNamedClient( | 138 static scoped_ptr<Channel> CreateNamedClient( |
150 const IPC::ChannelHandle& channel_handle, | 139 const IPC::ChannelHandle& channel_handle, |
151 Listener* listener, | 140 Listener* listener); |
152 AttachmentBroker* broker); | |
153 #if defined(OS_POSIX) | 141 #if defined(OS_POSIX) |
154 // An "open" named server accepts connections from ANY client. | 142 // An "open" named server accepts connections from ANY client. |
155 // The caller must then implement their own access-control based on the | 143 // The caller must then implement their own access-control based on the |
156 // client process' user Id. | 144 // client process' user Id. |
157 static scoped_ptr<Channel> CreateOpenNamedServer( | 145 static scoped_ptr<Channel> CreateOpenNamedServer( |
158 const IPC::ChannelHandle& channel_handle, | 146 const IPC::ChannelHandle& channel_handle, |
159 Listener* listener, | 147 Listener* listener); |
160 AttachmentBroker* broker); | |
161 #endif | 148 #endif |
162 // TODO(erikchen): Remove default parameter for |broker|. It exists only to | |
163 // make the upcoming refactor decomposable into smaller CLs. | |
164 // http://crbug.com/493414. | |
165 static scoped_ptr<Channel> CreateServer( | 149 static scoped_ptr<Channel> CreateServer( |
166 const IPC::ChannelHandle& channel_handle, | 150 const IPC::ChannelHandle& channel_handle, |
167 Listener* listener, | 151 Listener* listener); |
168 AttachmentBroker* broker = nullptr); | |
169 | 152 |
170 ~Channel() override; | 153 ~Channel() override; |
171 | 154 |
172 // TODO(erikchen): Temporary code to help track http://crbug.com/527588. | 155 // TODO(erikchen): Temporary code to help track http://crbug.com/527588. |
173 using MessageVerifier = void (*)(const Message*); | 156 using MessageVerifier = void (*)(const Message*); |
174 static void SetMessageVerifier(MessageVerifier verifier); | 157 static void SetMessageVerifier(MessageVerifier verifier); |
175 static MessageVerifier GetMessageVerifier(); | 158 static MessageVerifier GetMessageVerifier(); |
176 | 159 |
177 // Connect the pipe. On the server side, this will initiate | 160 // Connect the pipe. On the server side, this will initiate |
178 // waiting for connections. On the client, it attempts to | 161 // waiting for connections. On the client, it attempts to |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 255 |
273 #if defined(OS_POSIX) | 256 #if defined(OS_POSIX) |
274 // SocketPair() creates a pair of socket FDs suitable for using with | 257 // SocketPair() creates a pair of socket FDs suitable for using with |
275 // IPC::Channel. | 258 // IPC::Channel. |
276 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); | 259 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); |
277 #endif | 260 #endif |
278 | 261 |
279 } // namespace IPC | 262 } // namespace IPC |
280 | 263 |
281 #endif // IPC_IPC_CHANNEL_H_ | 264 #endif // IPC_IPC_CHANNEL_H_ |
OLD | NEW |