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

Side by Side Diff: ipc/ipc_channel.h

Issue 2141253004: Revert of Adds associated interface support to IPC::Channel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@channel-bindings-1
Patch Set: Created 4 years, 5 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
« no previous file with comments | « ipc/ipc.mojom ('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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
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 "build/build_config.h" 17 #include "build/build_config.h"
18 #include "ipc/ipc_channel_handle.h" 18 #include "ipc/ipc_channel_handle.h"
19 #include "ipc/ipc_endpoint.h" 19 #include "ipc/ipc_endpoint.h"
20 #include "ipc/ipc_message.h" 20 #include "ipc/ipc_message.h"
21 #include "mojo/public/cpp/bindings/associated_group.h"
22 #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
23 #include "mojo/public/cpp/bindings/associated_interface_request.h"
24 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
25 21
26 #if defined(OS_POSIX) 22 #if defined(OS_POSIX)
27 #include <sys/types.h> 23 #include <sys/types.h>
28 #endif 24 #endif
29 25
30 namespace IPC { 26 namespace IPC {
31 27
32 class Listener; 28 class Listener;
33 29
34 //------------------------------------------------------------------------------ 30 //------------------------------------------------------------------------------
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 HELLO_MESSAGE_TYPE = UINT16_MAX, 86 HELLO_MESSAGE_TYPE = UINT16_MAX,
91 // The CLOSE_FD_MESSAGE_TYPE is used in the IPC class to 87 // The CLOSE_FD_MESSAGE_TYPE is used in the IPC class to
92 // work around a bug in sendmsg() on Mac. When an FD is sent 88 // work around a bug in sendmsg() on Mac. When an FD is sent
93 // over the socket, a CLOSE_FD_MESSAGE is sent with hops = 2. 89 // over the socket, a CLOSE_FD_MESSAGE is sent with hops = 2.
94 // The client will return the message with hops = 1, *after* it 90 // The client will return the message with hops = 1, *after* it
95 // has received the message that contains the FD. When we 91 // has received the message that contains the FD. When we
96 // receive it again on the sender side, we close the FD. 92 // receive it again on the sender side, we close the FD.
97 CLOSE_FD_MESSAGE_TYPE = HELLO_MESSAGE_TYPE - 1 93 CLOSE_FD_MESSAGE_TYPE = HELLO_MESSAGE_TYPE - 1
98 }; 94 };
99 95
100 // Helper interface a Channel may implement to expose support for associated
101 // Mojo interfaces.
102 class IPC_EXPORT AssociatedInterfaceSupport {
103 public:
104 using GenericAssociatedInterfaceFactory =
105 base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>;
106
107 virtual ~AssociatedInterfaceSupport() {}
108
109 // Accesses the AssociatedGroup used to associate new interface endpoints
110 // with this Channel.
111 virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0;
112
113 // Adds an interface factory to this channel for interface |name|.
114 virtual void AddGenericAssociatedInterface(
115 const std::string& name,
116 const GenericAssociatedInterfaceFactory& factory) = 0;
117
118 // Requests an associated interface from the remote endpoint.
119 virtual void GetGenericRemoteAssociatedInterface(
120 const std::string& name,
121 mojo::ScopedInterfaceEndpointHandle handle) = 0;
122
123 // Template helper to add an interface factory to this channel.
124 template <typename Interface>
125 using AssociatedInterfaceFactory =
126 base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>;
127 template <typename Interface>
128 void AddAssociatedInterface(
129 const AssociatedInterfaceFactory<Interface>& factory) {
130 AddGenericAssociatedInterface(
131 Interface::Name_,
132 base::Bind(&BindAssociatedInterfaceRequest<Interface>, factory));
133 }
134
135 // Template helper to request a remote associated interface.
136 template <typename Interface>
137 void GetRemoteAssociatedInterface(
138 mojo::AssociatedInterfacePtr<Interface>* proxy) {
139 mojo::AssociatedInterfaceRequest<Interface> request =
140 mojo::GetProxy(proxy, GetAssociatedGroup());
141 GetGenericRemoteAssociatedInterface(
142 Interface::Name_, request.PassHandle());
143 }
144
145 private:
146 template <typename Interface>
147 static void BindAssociatedInterfaceRequest(
148 const AssociatedInterfaceFactory<Interface>& factory,
149 mojo::ScopedInterfaceEndpointHandle handle) {
150 mojo::AssociatedInterfaceRequest<Interface> request;
151 request.Bind(std::move(handle));
152 factory.Run(std::move(request));
153 }
154 };
155
156 // The maximum message size in bytes. Attempting to receive a message of this 96 // The maximum message size in bytes. Attempting to receive a message of this
157 // size or bigger results in a channel error. 97 // size or bigger results in a channel error.
158 static const size_t kMaximumMessageSize = 128 * 1024 * 1024; 98 static const size_t kMaximumMessageSize = 128 * 1024 * 1024;
159 99
160 // Amount of data to read at once from the pipe. 100 // Amount of data to read at once from the pipe.
161 static const size_t kReadBufferSize = 4 * 1024; 101 static const size_t kReadBufferSize = 4 * 1024;
162 102
163 // Maximum persistent read buffer size. Read buffer can grow larger to 103 // Maximum persistent read buffer size. Read buffer can grow larger to
164 // accommodate large messages, but it's recommended to shrink back to this 104 // accommodate large messages, but it's recommended to shrink back to this
165 // value because it fits 99.9% of all messages (see issue 529940 for data). 105 // value because it fits 99.9% of all messages (see issue 529940 for data).
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Close this Channel explicitly. May be called multiple times. 174 // Close this Channel explicitly. May be called multiple times.
235 // On POSIX calling close on an IPC channel that listens for connections will 175 // On POSIX calling close on an IPC channel that listens for connections will
236 // cause it to close any accepted connections, and it will stop listening for 176 // cause it to close any accepted connections, and it will stop listening for
237 // new connections. If you just want to close the currently accepted 177 // new connections. If you just want to close the currently accepted
238 // connection and listen for new ones, use ResetToAcceptingConnectionState. 178 // connection and listen for new ones, use ResetToAcceptingConnectionState.
239 virtual void Close() = 0; 179 virtual void Close() = 0;
240 180
241 // Get its own process id. This value is told to the peer. 181 // Get its own process id. This value is told to the peer.
242 virtual base::ProcessId GetSelfPID() const = 0; 182 virtual base::ProcessId GetSelfPID() const = 0;
243 183
244 // Gets a helper for associating Mojo interfaces with this Channel.
245 //
246 // NOTE: Not all implementations support this.
247 virtual AssociatedInterfaceSupport* GetAssociatedInterfaceSupport();
248
249 // Overridden from ipc::Sender. 184 // Overridden from ipc::Sender.
250 // Send a message over the Channel to the listener on the other end. 185 // Send a message over the Channel to the listener on the other end.
251 // 186 //
252 // |message| must be allocated using operator new. This object will be 187 // |message| must be allocated using operator new. This object will be
253 // deleted once the contents of the Message have been sent. 188 // deleted once the contents of the Message have been sent.
254 bool Send(Message* message) override = 0; 189 bool Send(Message* message) override = 0;
255 190
256 // IsSendThreadSafe returns true iff it's safe to call |Send| from non-IO 191 // IsSendThreadSafe returns true iff it's safe to call |Send| from non-IO
257 // threads. This is constant for the lifetime of the |Channel|. 192 // threads. This is constant for the lifetime of the |Channel|.
258 virtual bool IsSendThreadSafe() const; 193 virtual bool IsSendThreadSafe() const;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 284
350 #if defined(OS_POSIX) 285 #if defined(OS_POSIX)
351 // SocketPair() creates a pair of socket FDs suitable for using with 286 // SocketPair() creates a pair of socket FDs suitable for using with
352 // IPC::Channel. 287 // IPC::Channel.
353 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); 288 IPC_EXPORT bool SocketPair(int* fd1, int* fd2);
354 #endif 289 #endif
355 290
356 } // namespace IPC 291 } // namespace IPC
357 292
358 #endif // IPC_IPC_CHANNEL_H_ 293 #endif // IPC_IPC_CHANNEL_H_
OLDNEW
« no previous file with comments | « ipc/ipc.mojom ('k') | ipc/ipc_channel_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698