OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MOJO_SHELL_DOMAIN_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_ | |
6 #define MOJO_SHELL_DOMAIN_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_ | |
7 | |
8 #include <sys/types.h> | |
9 | |
10 #include <string> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/callback.h" | |
14 #include "base/macros.h" | |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "mojo/shell/domain_socket/completion_callback.h" | |
17 #include "mojo/shell/domain_socket/socket_descriptor.h" | |
18 | |
19 namespace mojo { | |
20 namespace shell { | |
21 | |
22 class SocketLibevent; | |
23 | |
24 // Unix Domain Server Socket Implementation. Supports abstract namespaces on | |
25 // Linux and Android. | |
26 class UnixDomainServerSocket { | |
27 public: | |
28 // Credentials of a peer process connected to the socket. | |
29 struct Credentials { | |
30 pid_t process_id; | |
31 uid_t user_id; | |
32 gid_t group_id; | |
33 }; | |
34 | |
35 // Callback that returns whether the already connected client, identified by | |
36 // its credentials, is allowed to keep the connection open. Note that | |
37 // the socket is closed immediately in case the callback returns false. | |
38 typedef base::Callback<bool(const Credentials&)> AuthCallback; | |
39 | |
40 UnixDomainServerSocket(const AuthCallback& auth_callack, | |
41 bool use_abstract_namespace); | |
42 ~UnixDomainServerSocket(); | |
43 | |
44 // Gets credentials of peer to check permissions. | |
45 static bool GetPeerCredentials(SocketDescriptor socket_fd, | |
46 Credentials* credentials); | |
47 | |
48 int ListenWithPath(const std::string& unix_domain_path, int backlog); | |
49 | |
50 // Accepts an incoming connection on |listen_socket_|, but passes back | |
51 // a raw SocketDescriptor instead of a StreamSocket. | |
52 int Accept(SocketDescriptor* socket_descriptor, | |
53 const CompletionCallback& callback); | |
54 | |
55 private: | |
56 // A callback to wrap the setting of the out-parameter to Accept(). | |
57 // This allows the internal machinery of that call to be implemented in | |
58 // a manner that's agnostic to the caller's desired output. | |
59 typedef base::Callback<void(scoped_ptr<SocketLibevent>)> SetterCallback; | |
60 | |
61 int DoAccept(const SetterCallback& setter_callback, | |
62 const CompletionCallback& callback); | |
63 void AcceptCompleted(const SetterCallback& setter_callback, | |
64 const CompletionCallback& callback, | |
65 int rv); | |
66 bool AuthenticateAndGetStreamSocket(const SetterCallback& setter_callback); | |
67 | |
68 scoped_ptr<SocketLibevent> listen_socket_; | |
69 const AuthCallback auth_callback_; | |
70 const bool use_abstract_namespace_; | |
71 | |
72 scoped_ptr<SocketLibevent> accept_socket_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket); | |
75 }; | |
76 | |
77 } // namespace shell | |
78 } // namespace mojo | |
79 | |
80 #endif // MOJO_SHELL_DOMAIN_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_ | |
OLD | NEW |