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) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 MODE_NO_FLAG = 0x0, | 48 MODE_NO_FLAG = 0x0, |
49 MODE_SERVER_FLAG = 0x1, | 49 MODE_SERVER_FLAG = 0x1, |
50 MODE_CLIENT_FLAG = 0x2, | 50 MODE_CLIENT_FLAG = 0x2, |
51 MODE_NAMED_FLAG = 0x4, | 51 MODE_NAMED_FLAG = 0x4, |
52 #if defined(OS_POSIX) | 52 #if defined(OS_POSIX) |
53 MODE_OPEN_ACCESS_FLAG = 0x8, // Don't restrict access based on client UID. | 53 MODE_OPEN_ACCESS_FLAG = 0x8, // Don't restrict access based on client UID. |
54 #endif | 54 #endif |
55 }; | 55 }; |
56 | 56 |
57 // Some Standard Modes | 57 // Some Standard Modes |
58 // TODO(morrita): These are under deprecation work. You should use Create*() | |
59 // functions instead. | |
60 enum Mode { | 58 enum Mode { |
61 MODE_NONE = MODE_NO_FLAG, | 59 MODE_NONE = MODE_NO_FLAG, |
62 MODE_SERVER = MODE_SERVER_FLAG, | 60 MODE_SERVER = MODE_SERVER_FLAG, |
63 MODE_CLIENT = MODE_CLIENT_FLAG, | 61 MODE_CLIENT = MODE_CLIENT_FLAG, |
| 62 // Channels on Windows are named by default and accessible from other |
| 63 // processes. On POSIX channels are anonymous by default and not accessible |
| 64 // from other processes. Named channels work via named unix domain sockets. |
| 65 // On Windows MODE_NAMED_SERVER is equivalent to MODE_SERVER and |
| 66 // MODE_NAMED_CLIENT is equivalent to MODE_CLIENT. |
64 MODE_NAMED_SERVER = MODE_SERVER_FLAG | MODE_NAMED_FLAG, | 67 MODE_NAMED_SERVER = MODE_SERVER_FLAG | MODE_NAMED_FLAG, |
65 MODE_NAMED_CLIENT = MODE_CLIENT_FLAG | MODE_NAMED_FLAG, | 68 MODE_NAMED_CLIENT = MODE_CLIENT_FLAG | MODE_NAMED_FLAG, |
66 #if defined(OS_POSIX) | 69 #if defined(OS_POSIX) |
| 70 // An "open" named server accepts connections from ANY client. |
| 71 // The caller must then implement their own access-control based on the |
| 72 // client process' user Id. |
67 MODE_OPEN_NAMED_SERVER = MODE_OPEN_ACCESS_FLAG | MODE_SERVER_FLAG | | 73 MODE_OPEN_NAMED_SERVER = MODE_OPEN_ACCESS_FLAG | MODE_SERVER_FLAG | |
68 MODE_NAMED_FLAG | 74 MODE_NAMED_FLAG |
69 #endif | 75 #endif |
70 }; | 76 }; |
71 | 77 |
72 // Messages internal to the IPC implementation are defined here. | 78 // Messages internal to the IPC implementation are defined here. |
73 // Uses Maximum value of message type (uint16), to avoid conflicting | 79 // Uses Maximum value of message type (uint16), to avoid conflicting |
74 // with normal message types, which are enumeration constants starting from 0. | 80 // with normal message types, which are enumeration constants starting from 0. |
75 enum { | 81 enum { |
76 // The Hello message is sent by the peer when the channel is connected. | 82 // The Hello message is sent by the peer when the channel is connected. |
(...skipping 16 matching lines...) Expand all Loading... |
93 | 99 |
94 // Amount of data to read at once from the pipe. | 100 // Amount of data to read at once from the pipe. |
95 static const size_t kReadBufferSize = 4 * 1024; | 101 static const size_t kReadBufferSize = 4 * 1024; |
96 | 102 |
97 // Initialize a Channel. | 103 // Initialize a Channel. |
98 // | 104 // |
99 // |channel_handle| identifies the communication Channel. For POSIX, if | 105 // |channel_handle| identifies the communication Channel. For POSIX, if |
100 // the file descriptor in the channel handle is != -1, the channel takes | 106 // the file descriptor in the channel handle is != -1, the channel takes |
101 // ownership of the file descriptor and will close it appropriately, otherwise | 107 // ownership of the file descriptor and will close it appropriately, otherwise |
102 // it will create a new descriptor internally. | 108 // it will create a new descriptor internally. |
| 109 // |mode| specifies whether this Channel is to operate in server mode or |
| 110 // client mode. In server mode, the Channel is responsible for setting up the |
| 111 // IPC object, whereas in client mode, the Channel merely connects to the |
| 112 // already established IPC object. |
103 // |listener| receives a callback on the current thread for each newly | 113 // |listener| receives a callback on the current thread for each newly |
104 // received message. | 114 // received message. |
105 // | 115 // |
106 // There are four type of modes how channels operate: | 116 Channel(const IPC::ChannelHandle &channel_handle, Mode mode, |
107 // | 117 Listener* listener); |
108 // - Server and named server: In these modes, the Channel is | |
109 // responsible for settingb up the IPC object | |
110 // - An "open" named server: It accepts connections from ANY client. | |
111 // The caller must then implement their own access-control based on the | |
112 // client process' user Id. | |
113 // - Client and named client: In these mode, the Channel merely | |
114 // connects to the already established IPC object. | |
115 // | |
116 // Each mode has its own Create*() API to create the Channel object. | |
117 // | |
118 // TODO(morrita): Replace CreateByModeForProxy() with one of above Create*(). | |
119 // | |
120 static scoped_ptr<Channel> CreateByModeForProxy( | |
121 const IPC::ChannelHandle &channel_handle, Mode mode,Listener* listener); | |
122 static scoped_ptr<Channel> CreateClient( | |
123 const IPC::ChannelHandle &channel_handle, Listener* listener); | |
124 | |
125 // Channels on Windows are named by default and accessible from other | |
126 // processes. On POSIX channels are anonymous by default and not accessible | |
127 // from other processes. Named channels work via named unix domain sockets. | |
128 // On Windows MODE_NAMED_SERVER is equivalent to MODE_SERVER and | |
129 // MODE_NAMED_CLIENT is equivalent to MODE_CLIENT. | |
130 static scoped_ptr<Channel> CreateNamedServer( | |
131 const IPC::ChannelHandle &channel_handle, Listener* listener); | |
132 static scoped_ptr<Channel> CreateNamedClient( | |
133 const IPC::ChannelHandle &channel_handle, Listener* listener); | |
134 #if defined(OS_POSIX) | |
135 // An "open" named server accepts connections from ANY client. | |
136 // The caller must then implement their own access-control based on the | |
137 // client process' user Id. | |
138 static scoped_ptr<Channel> CreateOpenNamedServer( | |
139 const IPC::ChannelHandle &channel_handle, Listener* listener); | |
140 #endif | |
141 static scoped_ptr<Channel> CreateServer( | |
142 const IPC::ChannelHandle &channel_handle, Listener* listener); | |
143 | |
144 | 118 |
145 virtual ~Channel(); | 119 virtual ~Channel(); |
146 | 120 |
147 // Connect the pipe. On the server side, this will initiate | 121 // Connect the pipe. On the server side, this will initiate |
148 // waiting for connections. On the client, it attempts to | 122 // waiting for connections. On the client, it attempts to |
149 // connect to a pre-existing pipe. Note, calling Connect() | 123 // connect to a pre-existing pipe. Note, calling Connect() |
150 // will not block the calling thread and may complete | 124 // will not block the calling thread and may complete |
151 // asynchronously. | 125 // asynchronously. |
152 bool Connect() WARN_UNUSED_RESULT; | 126 bool Connect() WARN_UNUSED_RESULT; |
153 | 127 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 #endif | 213 #endif |
240 | 214 |
241 protected: | 215 protected: |
242 // Used in Chrome by the TestSink to provide a dummy channel implementation | 216 // Used in Chrome by the TestSink to provide a dummy channel implementation |
243 // for testing. TestSink overrides the "interesting" functions in Channel so | 217 // for testing. TestSink overrides the "interesting" functions in Channel so |
244 // no actual implementation is needed. This will cause un-overridden calls to | 218 // no actual implementation is needed. This will cause un-overridden calls to |
245 // segfault. Do not use outside of test code! | 219 // segfault. Do not use outside of test code! |
246 Channel() : channel_impl_(0) { } | 220 Channel() : channel_impl_(0) { } |
247 | 221 |
248 private: | 222 private: |
249 Channel(const IPC::ChannelHandle &channel_handle, Mode mode, | |
250 Listener* listener); | |
251 | |
252 // PIMPL to which all channel calls are delegated. | 223 // PIMPL to which all channel calls are delegated. |
253 class ChannelImpl; | 224 class ChannelImpl; |
254 ChannelImpl *channel_impl_; | 225 ChannelImpl *channel_impl_; |
255 }; | 226 }; |
256 | 227 |
257 #if defined(OS_POSIX) | 228 #if defined(OS_POSIX) |
258 // SocketPair() creates a pair of socket FDs suitable for using with | 229 // SocketPair() creates a pair of socket FDs suitable for using with |
259 // IPC::Channel. | 230 // IPC::Channel. |
260 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); | 231 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); |
261 #endif | 232 #endif |
262 | 233 |
263 } // namespace IPC | 234 } // namespace IPC |
264 | 235 |
265 #endif // IPC_IPC_CHANNEL_H_ | 236 #endif // IPC_IPC_CHANNEL_H_ |
OLD | NEW |