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