OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_FACTORY_H_ | 5 #ifndef APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_ |
6 #define IPC_IPC_CHANNEL_FACTORY_H_ | 6 #define APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "ipc/ipc_channel_handle.h" | 10 #include "ipc/ipc_channel_handle.h" |
11 #include "ipc/ipc_export.h" | |
12 | 11 |
13 namespace IPC { | 12 namespace apps { |
14 | 13 |
15 // A ChannelFactory listens on a UNIX domain socket. When a client connects to | 14 // A UnixDomainSocketAcceptor listens on a UNIX domain socket. When a |
16 // the socket, it accept()s the connection and passes the new FD to the | 15 // client connects to the socket, it accept()s the connection and |
17 // delegate. The delegate is then responsible for creating a new IPC::Channel | 16 // passes the new FD to the delegate. The delegate is then responsible |
18 // for the FD. | 17 // for creating a new IPC::Channel for the FD. |
19 class IPC_EXPORT ChannelFactory : public base::MessageLoopForIO::Watcher { | 18 class UnixDomainSocketAcceptor : public base::MessageLoopForIO::Watcher { |
20 public: | 19 public: |
21 class Delegate { | 20 class Delegate { |
22 public: | 21 public: |
23 // Called when a client connects to the factory. It is the delegate's | 22 // Called when a client connects to the factory. It is the delegate's |
24 // responsibility to create an IPC::Channel for the handle, or else close | 23 // responsibility to create an IPC::Channel for the handle, or else close |
25 // the file descriptor contained therein. | 24 // the file descriptor contained therein. |
26 virtual void OnClientConnected(const ChannelHandle& handle) = 0; | 25 virtual void OnClientConnected(const IPC::ChannelHandle& handle) = 0; |
27 | 26 |
28 // Called when an error occurs and the channel is closed. | 27 // Called when an error occurs and the channel is closed. |
29 virtual void OnListenError() = 0; | 28 virtual void OnListenError() = 0; |
30 }; | 29 }; |
31 | 30 |
32 ChannelFactory(const base::FilePath& path, Delegate* delegate); | 31 UnixDomainSocketAcceptor(const base::FilePath& path, Delegate* delegate); |
33 | 32 |
34 virtual ~ChannelFactory(); | 33 virtual ~UnixDomainSocketAcceptor(); |
35 | 34 |
36 // Call this to start listening on the socket. | 35 // Call this to start listening on the socket. |
37 bool Listen(); | 36 bool Listen(); |
38 | 37 |
39 // Close and unlink the socket, and stop accepting connections. | 38 // Close and unlink the socket, and stop accepting connections. |
40 void Close(); | 39 void Close(); |
41 | 40 |
42 private: | 41 private: |
43 bool CreateSocket(); | 42 bool CreateSocket(); |
44 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 43 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
45 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 44 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
46 | 45 |
47 base::MessageLoopForIO::FileDescriptorWatcher | 46 base::MessageLoopForIO::FileDescriptorWatcher |
48 server_listen_connection_watcher_; | 47 server_listen_connection_watcher_; |
49 base::FilePath path_; | 48 base::FilePath path_; |
50 Delegate* delegate_; | 49 Delegate* delegate_; |
51 int listen_fd_; | 50 int listen_fd_; |
52 | 51 |
53 DISALLOW_COPY_AND_ASSIGN(ChannelFactory); | 52 DISALLOW_COPY_AND_ASSIGN(UnixDomainSocketAcceptor); |
54 }; | 53 }; |
55 | 54 |
56 } // namespace IPC | 55 } // namespace apps |
57 | 56 |
58 #endif // IPC_IPC_CHANNEL_FACTORY_H_ | 57 #endif // APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_ |
OLD | NEW |