| 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. |
| 58 enum Mode { | 60 enum Mode { |
| 59 MODE_NONE = MODE_NO_FLAG, | 61 MODE_NONE = MODE_NO_FLAG, |
| 60 MODE_SERVER = MODE_SERVER_FLAG, | 62 MODE_SERVER = MODE_SERVER_FLAG, |
| 61 MODE_CLIENT = MODE_CLIENT_FLAG, | 63 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. | |
| 67 MODE_NAMED_SERVER = MODE_SERVER_FLAG | MODE_NAMED_FLAG, | 64 MODE_NAMED_SERVER = MODE_SERVER_FLAG | MODE_NAMED_FLAG, |
| 68 MODE_NAMED_CLIENT = MODE_CLIENT_FLAG | MODE_NAMED_FLAG, | 65 MODE_NAMED_CLIENT = MODE_CLIENT_FLAG | MODE_NAMED_FLAG, |
| 69 #if defined(OS_POSIX) | 66 #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. | |
| 73 MODE_OPEN_NAMED_SERVER = MODE_OPEN_ACCESS_FLAG | MODE_SERVER_FLAG | | 67 MODE_OPEN_NAMED_SERVER = MODE_OPEN_ACCESS_FLAG | MODE_SERVER_FLAG | |
| 74 MODE_NAMED_FLAG | 68 MODE_NAMED_FLAG |
| 75 #endif | 69 #endif |
| 76 }; | 70 }; |
| 77 | 71 |
| 78 // Messages internal to the IPC implementation are defined here. | 72 // Messages internal to the IPC implementation are defined here. |
| 79 // Uses Maximum value of message type (uint16), to avoid conflicting | 73 // Uses Maximum value of message type (uint16), to avoid conflicting |
| 80 // with normal message types, which are enumeration constants starting from 0. | 74 // with normal message types, which are enumeration constants starting from 0. |
| 81 enum { | 75 enum { |
| 82 // The Hello message is sent by the peer when the channel is connected. | 76 // The Hello message is sent by the peer when the channel is connected. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 99 | 93 |
| 100 // Amount of data to read at once from the pipe. | 94 // Amount of data to read at once from the pipe. |
| 101 static const size_t kReadBufferSize = 4 * 1024; | 95 static const size_t kReadBufferSize = 4 * 1024; |
| 102 | 96 |
| 103 // Initialize a Channel. | 97 // Initialize a Channel. |
| 104 // | 98 // |
| 105 // |channel_handle| identifies the communication Channel. For POSIX, if | 99 // |channel_handle| identifies the communication Channel. For POSIX, if |
| 106 // the file descriptor in the channel handle is != -1, the channel takes | 100 // the file descriptor in the channel handle is != -1, the channel takes |
| 107 // ownership of the file descriptor and will close it appropriately, otherwise | 101 // ownership of the file descriptor and will close it appropriately, otherwise |
| 108 // it will create a new descriptor internally. | 102 // 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. | |
| 113 // |listener| receives a callback on the current thread for each newly | 103 // |listener| receives a callback on the current thread for each newly |
| 114 // received message. | 104 // received message. |
| 115 // | 105 // |
| 116 Channel(const IPC::ChannelHandle &channel_handle, Mode mode, | 106 // There are four type of modes how channels operate: |
| 117 Listener* listener); | 107 // |
| 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 |
| 118 | 144 |
| 119 virtual ~Channel(); | 145 virtual ~Channel(); |
| 120 | 146 |
| 121 // Connect the pipe. On the server side, this will initiate | 147 // Connect the pipe. On the server side, this will initiate |
| 122 // waiting for connections. On the client, it attempts to | 148 // waiting for connections. On the client, it attempts to |
| 123 // connect to a pre-existing pipe. Note, calling Connect() | 149 // connect to a pre-existing pipe. Note, calling Connect() |
| 124 // will not block the calling thread and may complete | 150 // will not block the calling thread and may complete |
| 125 // asynchronously. | 151 // asynchronously. |
| 126 bool Connect() WARN_UNUSED_RESULT; | 152 bool Connect() WARN_UNUSED_RESULT; |
| 127 | 153 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 #endif | 239 #endif |
| 214 | 240 |
| 215 protected: | 241 protected: |
| 216 // Used in Chrome by the TestSink to provide a dummy channel implementation | 242 // Used in Chrome by the TestSink to provide a dummy channel implementation |
| 217 // for testing. TestSink overrides the "interesting" functions in Channel so | 243 // for testing. TestSink overrides the "interesting" functions in Channel so |
| 218 // no actual implementation is needed. This will cause un-overridden calls to | 244 // no actual implementation is needed. This will cause un-overridden calls to |
| 219 // segfault. Do not use outside of test code! | 245 // segfault. Do not use outside of test code! |
| 220 Channel() : channel_impl_(0) { } | 246 Channel() : channel_impl_(0) { } |
| 221 | 247 |
| 222 private: | 248 private: |
| 249 Channel(const IPC::ChannelHandle &channel_handle, Mode mode, |
| 250 Listener* listener); |
| 251 |
| 223 // PIMPL to which all channel calls are delegated. | 252 // PIMPL to which all channel calls are delegated. |
| 224 class ChannelImpl; | 253 class ChannelImpl; |
| 225 ChannelImpl *channel_impl_; | 254 ChannelImpl *channel_impl_; |
| 226 }; | 255 }; |
| 227 | 256 |
| 228 #if defined(OS_POSIX) | 257 #if defined(OS_POSIX) |
| 229 // SocketPair() creates a pair of socket FDs suitable for using with | 258 // SocketPair() creates a pair of socket FDs suitable for using with |
| 230 // IPC::Channel. | 259 // IPC::Channel. |
| 231 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); | 260 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); |
| 232 #endif | 261 #endif |
| 233 | 262 |
| 234 } // namespace IPC | 263 } // namespace IPC |
| 235 | 264 |
| 236 #endif // IPC_IPC_CHANNEL_H_ | 265 #endif // IPC_IPC_CHANNEL_H_ |
| OLD | NEW |