Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: ipc/ipc_channel.h

Issue 307653003: Introduce IPC::Channel::Create*() to ensure it being heap-allocated. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc.gypi ('k') | ipc/ipc_channel_common.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 // Amount of data to read at once from the pipe. 100 // Amount of data to read at once from the pipe.
101 static const size_t kReadBufferSize = 4 * 1024; 101 static const size_t kReadBufferSize = 4 * 1024;
102 102
103 // Initialize a Channel. 103 // Initialize a Channel.
104 // 104 //
105 // |channel_handle| identifies the communication Channel. For POSIX, if 105 // |channel_handle| identifies the communication Channel. For POSIX, if
106 // 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
107 // ownership of the file descriptor and will close it appropriately, otherwise 107 // ownership of the file descriptor and will close it appropriately, otherwise
108 // 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.
113 // |listener| receives a callback on the current thread for each newly 109 // |listener| receives a callback on the current thread for each newly
114 // received message. 110 // received message.
115 // 111 //
116 Channel(const IPC::ChannelHandle &channel_handle, Mode mode, 112 // There are four type of modes how channels operate:
117 Listener* listener); 113 //
114 // - Server and named server: In these modes, the Channel is
115 // responsible for settingb up the IPC object
116 // - An "open" named server: It accepts connections from ANY client.
117 // The caller must then implement their own access-control based on the
118 // client process' user Id.
119 // - Client and named client: In these mode, the Channel merely
120 // connects to the already established IPC object.
121 //
122 // Each mode has its own Create*() API to create the Channel object.
123 //
124 // FIXME(morrita): Replace CreateByModeForProxy() with one of above Create*().
darin (slow to review) 2014/05/28 19:47:14 nit: in Chromium unlike Blink, we use TODO(user) i
Hajime Morrita 2014/05/28 22:32:24 Done.
125 //
126 static Channel* CreateByModeForProxy(const IPC::ChannelHandle &channel_handle,
darin (slow to review) 2014/05/28 19:47:14 nit: these should return scoped_ptr<Channel>.
darin (slow to review) 2014/05/28 19:47:14 Perhaps the documentation that currently exists fo
Hajime Morrita 2014/05/28 22:32:24 Done.
127 Mode mode,Listener* listener);
128 static Channel* CreateClient(const IPC::ChannelHandle &channel_handle,
129 Listener* listener);
130 static Channel* CreateNamedServer(const IPC::ChannelHandle &channel_handle,
131 Listener* listener);
132 static Channel* CreateNamedClient(const IPC::ChannelHandle &channel_handle,
133 Listener* listener);
134 static Channel* CreateOpenNamedServer(
darin (slow to review) 2014/05/28 19:47:14 It seems like CreateOpenNamedServer should be guar
Hajime Morrita 2014/05/28 22:32:24 Done.
135 const IPC::ChannelHandle &channel_handle, Listener* listener);
136 static Channel* CreateServer(const IPC::ChannelHandle &channel_handle,
137 Listener* listener);
138
118 139
119 virtual ~Channel(); 140 virtual ~Channel();
120 141
121 // Connect the pipe. On the server side, this will initiate 142 // Connect the pipe. On the server side, this will initiate
122 // waiting for connections. On the client, it attempts to 143 // waiting for connections. On the client, it attempts to
123 // connect to a pre-existing pipe. Note, calling Connect() 144 // connect to a pre-existing pipe. Note, calling Connect()
124 // will not block the calling thread and may complete 145 // will not block the calling thread and may complete
125 // asynchronously. 146 // asynchronously.
126 bool Connect() WARN_UNUSED_RESULT; 147 bool Connect() WARN_UNUSED_RESULT;
127 148
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 #endif 234 #endif
214 235
215 protected: 236 protected:
216 // Used in Chrome by the TestSink to provide a dummy channel implementation 237 // Used in Chrome by the TestSink to provide a dummy channel implementation
217 // for testing. TestSink overrides the "interesting" functions in Channel so 238 // for testing. TestSink overrides the "interesting" functions in Channel so
218 // no actual implementation is needed. This will cause un-overridden calls to 239 // no actual implementation is needed. This will cause un-overridden calls to
219 // segfault. Do not use outside of test code! 240 // segfault. Do not use outside of test code!
220 Channel() : channel_impl_(0) { } 241 Channel() : channel_impl_(0) { }
221 242
222 private: 243 private:
244 Channel(const IPC::ChannelHandle &channel_handle, Mode mode,
245 Listener* listener);
246
223 // PIMPL to which all channel calls are delegated. 247 // PIMPL to which all channel calls are delegated.
224 class ChannelImpl; 248 class ChannelImpl;
225 ChannelImpl *channel_impl_; 249 ChannelImpl *channel_impl_;
226 }; 250 };
227 251
228 #if defined(OS_POSIX) 252 #if defined(OS_POSIX)
229 // SocketPair() creates a pair of socket FDs suitable for using with 253 // SocketPair() creates a pair of socket FDs suitable for using with
230 // IPC::Channel. 254 // IPC::Channel.
231 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); 255 IPC_EXPORT bool SocketPair(int* fd1, int* fd2);
232 #endif 256 #endif
233 257
234 } // namespace IPC 258 } // namespace IPC
235 259
236 #endif // IPC_IPC_CHANNEL_H_ 260 #endif // IPC_IPC_CHANNEL_H_
OLDNEW
« no previous file with comments | « ipc/ipc.gypi ('k') | ipc/ipc_channel_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698