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