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.
5 #ifndef CHROME_BROWSER_APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_
6 #define CHROME_BROWSER_APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_
8 #include "base/files/file_path.h"
9 #include "base/message_loop/message_loop.h"
10 #include "ipc/ipc_channel_handle.h"
14 // A UnixDomainSocketAcceptor listens on a UNIX domain socket. When a
15 // client connects to the socket, it accept()s the connection and
16 // passes the new FD to the delegate. The delegate is then responsible
17 // for creating a new IPC::Channel for the FD.
18 class UnixDomainSocketAcceptor
: public base::MessageLoopForIO::Watcher
{
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 IPC::ChannelHandle
& handle
) = 0;
27 // Called when an error occurs and the channel is closed.
28 virtual void OnListenError() = 0;
31 UnixDomainSocketAcceptor(const base::FilePath
& path
, Delegate
* delegate
);
33 ~UnixDomainSocketAcceptor() override
;
35 // Call this to start listening on the socket.
38 // Close and unlink the socket, and stop accepting connections.
43 void OnFileCanReadWithoutBlocking(int fd
) override
;
44 void OnFileCanWriteWithoutBlocking(int fd
) override
;
46 base::MessageLoopForIO::FileDescriptorWatcher
47 server_listen_connection_watcher_
;
52 DISALLOW_COPY_AND_ASSIGN(UnixDomainSocketAcceptor
);
57 #endif // CHROME_BROWSER_APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_