Commit d9674614 authored by morrita@chromium.org's avatar morrita@chromium.org

Rename IPC::ChannelFactory to UnixDomainSocketAcceptor.

ChannelFactory doesn't create any channel and it just listens on
and accepts from a unix socket. So this change renames it to
represent what it actually does.

R=darin@chromium.org,cpu@chromium.org,jeremya@chromium.org,tapted@chromium.org
TEST=none
BUG=377980

Review URL: https://codereview.chromium.org/305973002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284231 0039d316-1c4b-4281-b951-d872f2087c98
parent 6d9e0587
......@@ -28,6 +28,8 @@
'chrome_main_app_mode_mac.mm',
'extension_app_shim_handler_mac.cc',
'extension_app_shim_handler_mac.h',
'unix_domain_socket_acceptor.cc',
'unix_domain_socket_acceptor.h',
],
},
], # targets
......
......@@ -34,8 +34,8 @@ class AppShimHost : public IPC::Listener,
virtual ~AppShimHost();
// Creates a new server-side IPC channel at |handle|, which should contain a
// file descriptor of a channel created by an IPC::ChannelFactory, and begins
// listening for messages on it.
// file descriptor of a channel created by an UnixDomainSocketAcceptor,
// and begins listening for messages on it.
void ServeChannel(const IPC::ChannelHandle& handle);
protected:
......
......@@ -205,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(AppShimHostManagerBrowserTest,
PRE_ReCreate) {
test::AppShimHostManagerTestApi test_api(
g_browser_process->platform_part()->app_shim_host_manager());
EXPECT_TRUE(test_api.factory());
EXPECT_TRUE(test_api.acceptor());
}
// Ensure the domain socket can be re-created after a prior browser process has
......@@ -214,7 +214,7 @@ IN_PROC_BROWSER_TEST_F(AppShimHostManagerBrowserTest,
ReCreate) {
test::AppShimHostManagerTestApi test_api(
g_browser_process->platform_part()->app_shim_host_manager());
EXPECT_TRUE(test_api.factory());
EXPECT_TRUE(test_api.acceptor());
}
// Tests for the files created by AppShimHostManager.
......
......@@ -6,9 +6,9 @@
#define APPS_APP_SHIM_APP_SHIM_HOST_MANAGER_MAC_H_
#include "apps/app_shim/extension_app_shim_handler_mac.h"
#include "apps/app_shim/unix_domain_socket_acceptor.h"
#include "base/memory/ref_counted.h"
#include "content/public/browser/browser_thread.h"
#include "ipc/ipc_channel_factory.h"
namespace base {
class FilePath;
......@@ -19,11 +19,11 @@ class AppShimHostManagerTestApi;
}
// The AppShimHostManager receives connections from app shims on a UNIX
// socket (|factory_|) and creates a helper object to manage the connection.
class AppShimHostManager
: public IPC::ChannelFactory::Delegate,
public base::RefCountedThreadSafe<
AppShimHostManager, content::BrowserThread::DeleteOnUIThread> {
// socket (|acceptor_|) and creates a helper object to manage the connection.
class AppShimHostManager : public apps::UnixDomainSocketAcceptor::Delegate,
public base::RefCountedThreadSafe<
AppShimHostManager,
content::BrowserThread::DeleteOnUIThread> {
public:
AppShimHostManager();
......@@ -44,11 +44,11 @@ class AppShimHostManager
friend class test::AppShimHostManagerTestApi;
virtual ~AppShimHostManager();
// IPC::ChannelFactory::Delegate implementation.
// UnixDomainSocketAcceptor::Delegate implementation.
virtual void OnClientConnected(const IPC::ChannelHandle& handle) OVERRIDE;
virtual void OnListenError() OVERRIDE;
// The |factory_| must be created on a thread which allows blocking I/O, so
// The |acceptor_| must be created on a thread which allows blocking I/O, so
// part of the initialization of this class must be carried out on the file
// thread.
void InitOnFileThread();
......@@ -63,7 +63,7 @@ class AppShimHostManager
base::FilePath directory_in_tmp_;
scoped_ptr<IPC::ChannelFactory> factory_;
scoped_ptr<apps::UnixDomainSocketAcceptor> acceptor_;
apps::ExtensionAppShimHandler extension_app_shim_handler_;
......
......@@ -64,7 +64,7 @@ void AppShimHostManager::Init() {
}
AppShimHostManager::~AppShimHostManager() {
factory_.reset();
acceptor_.reset();
if (!did_init_)
return;
......@@ -105,10 +105,10 @@ void AppShimHostManager::InitOnFileThread() {
return;
}
// IPC::ChannelFactory creates the socket immediately.
// UnixDomainSocketAcceptor creates the socket immediately.
base::FilePath socket_path =
directory_in_tmp_.Append(app_mode::kAppShimSocketShortName);
factory_.reset(new IPC::ChannelFactory(socket_path, this));
acceptor_.reset(new apps::UnixDomainSocketAcceptor(socket_path, this));
// Create a symlink to the socket in the user data dir. This lets the shim
// process started from Finder find the actual socket path by following the
......@@ -125,7 +125,7 @@ void AppShimHostManager::InitOnFileThread() {
void AppShimHostManager::ListenOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!factory_->Listen()) {
if (!acceptor_->Listen()) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&AppShimHostManager::OnListenError, this));
......@@ -142,7 +142,7 @@ void AppShimHostManager::OnClientConnected(
void AppShimHostManager::OnListenError() {
// TODO(tapted): Set a timeout and attempt to reconstruct the channel. Until
// cases where the error could occur are better known, just reset the factory
// cases where the error could occur are better known, just reset the acceptor
// to allow failure to be communicated via the test API.
factory_.reset();
acceptor_.reset();
}
......@@ -15,8 +15,8 @@ AppShimHostManagerTestApi::AppShimHostManagerTestApi(
DCHECK(host_manager_);
}
IPC::ChannelFactory* AppShimHostManagerTestApi::factory() {
return host_manager_->factory_.get();
apps::UnixDomainSocketAcceptor* AppShimHostManagerTestApi::acceptor() {
return host_manager_->acceptor_.get();
}
const base::FilePath& AppShimHostManagerTestApi::directory_in_tmp() {
......
......@@ -13,8 +13,8 @@ namespace base {
class FilePath;
}
namespace IPC {
class ChannelFactory;
namespace apps {
class UnixDomainSocketAcceptor;
}
namespace test {
......@@ -23,7 +23,7 @@ class AppShimHostManagerTestApi {
public:
explicit AppShimHostManagerTestApi(AppShimHostManager* host_manager);
IPC::ChannelFactory* factory();
apps::UnixDomainSocketAcceptor* acceptor();
const base::FilePath& directory_in_tmp();
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ipc/ipc_channel_factory.h"
#include "apps/app_shim/unix_domain_socket_acceptor.h"
#include "base/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "ipc/unix_domain_socket_util.h"
namespace IPC {
namespace apps {
ChannelFactory::ChannelFactory(const base::FilePath& path, Delegate* delegate)
UnixDomainSocketAcceptor::UnixDomainSocketAcceptor(const base::FilePath& path,
Delegate* delegate)
: path_(path), delegate_(delegate), listen_fd_(-1) {
DCHECK(delegate_);
CreateSocket();
}
ChannelFactory::~ChannelFactory() {
UnixDomainSocketAcceptor::~UnixDomainSocketAcceptor() {
Close();
}
bool ChannelFactory::CreateSocket() {
bool UnixDomainSocketAcceptor::CreateSocket() {
DCHECK(listen_fd_ < 0);
// Create the socket.
return CreateServerUnixDomainSocket(path_, &listen_fd_);
return IPC::CreateServerUnixDomainSocket(path_, &listen_fd_);
}
bool ChannelFactory::Listen() {
bool UnixDomainSocketAcceptor::Listen() {
if (listen_fd_ < 0)
return false;
......@@ -44,10 +45,10 @@ bool ChannelFactory::Listen() {
}
// Called by libevent when we can read from the fd without blocking.
void ChannelFactory::OnFileCanReadWithoutBlocking(int fd) {
void UnixDomainSocketAcceptor::OnFileCanReadWithoutBlocking(int fd) {
DCHECK(fd == listen_fd_);
int new_fd = -1;
if (!ServerAcceptConnection(listen_fd_, &new_fd)) {
if (!IPC::ServerAcceptConnection(listen_fd_, &new_fd)) {
Close();
delegate_->OnListenError();
return;
......@@ -61,19 +62,19 @@ void ChannelFactory::OnFileCanReadWithoutBlocking(int fd) {
}
// Verify that the IPC channel peer is running as the same user.
if (!IsPeerAuthorized(scoped_fd.get()))
if (!IPC::IsPeerAuthorized(scoped_fd.get()))
return;
ChannelHandle handle(std::string(),
base::FileDescriptor(scoped_fd.release(), true));
IPC::ChannelHandle handle(std::string(),
base::FileDescriptor(scoped_fd.release(), true));
delegate_->OnClientConnected(handle);
}
void ChannelFactory::OnFileCanWriteWithoutBlocking(int fd) {
void UnixDomainSocketAcceptor::OnFileCanWriteWithoutBlocking(int fd) {
NOTREACHED() << "Listen fd should never be writable.";
}
void ChannelFactory::Close() {
void UnixDomainSocketAcceptor::Close() {
if (listen_fd_ < 0)
return;
if (IGNORE_EINTR(close(listen_fd_)) < 0)
......@@ -86,4 +87,4 @@ void ChannelFactory::Close() {
server_listen_connection_watcher_.StopWatchingFileDescriptor();
}
} // namespace IPC
} // namespace apps
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IPC_IPC_CHANNEL_FACTORY_H_
#define IPC_IPC_CHANNEL_FACTORY_H_
#ifndef APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_
#define APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_export.h"
namespace IPC {
namespace apps {
// A ChannelFactory listens on a UNIX domain socket. When a client connects to
// the socket, it accept()s the connection and passes the new FD to the
// delegate. The delegate is then responsible for creating a new IPC::Channel
// for the FD.
class IPC_EXPORT ChannelFactory : public base::MessageLoopForIO::Watcher {
// A UnixDomainSocketAcceptor listens on a UNIX domain socket. When a
// client connects to the socket, it accept()s the connection and
// passes the new FD to the delegate. The delegate is then responsible
// for creating a new IPC::Channel for the FD.
class UnixDomainSocketAcceptor : public base::MessageLoopForIO::Watcher {
public:
class Delegate {
public:
// Called when a client connects to the factory. It is the delegate's
// responsibility to create an IPC::Channel for the handle, or else close
// the file descriptor contained therein.
virtual void OnClientConnected(const ChannelHandle& handle) = 0;
virtual void OnClientConnected(const IPC::ChannelHandle& handle) = 0;
// Called when an error occurs and the channel is closed.
virtual void OnListenError() = 0;
};
ChannelFactory(const base::FilePath& path, Delegate* delegate);
UnixDomainSocketAcceptor(const base::FilePath& path, Delegate* delegate);
virtual ~ChannelFactory();
virtual ~UnixDomainSocketAcceptor();
// Call this to start listening on the socket.
bool Listen();
......@@ -45,14 +44,14 @@ class IPC_EXPORT ChannelFactory : public base::MessageLoopForIO::Watcher {
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
base::MessageLoopForIO::FileDescriptorWatcher
server_listen_connection_watcher_;
server_listen_connection_watcher_;
base::FilePath path_;
Delegate* delegate_;
int listen_fd_;
DISALLOW_COPY_AND_ASSIGN(ChannelFactory);
DISALLOW_COPY_AND_ASSIGN(UnixDomainSocketAcceptor);
};
} // namespace IPC
} // namespace apps
#endif // IPC_IPC_CHANNEL_FACTORY_H_
#endif // APPS_APP_SHIM_UNIX_DOMAIN_SOCKET_ACCEPTOR_H_
......@@ -9,8 +9,6 @@ component("ipc") {
"ipc_channel.cc",
"ipc_channel.h",
"ipc_channel_common.cc",
"ipc_channel_factory.cc",
"ipc_channel_factory.h",
"ipc_channel_handle.h",
"ipc_channel_nacl.cc",
"ipc_channel_nacl.h",
......@@ -70,7 +68,7 @@ component("ipc") {
if (is_win || is_ios) {
sources -= [
"ipc_channel_factory.cc",
"unix_domain_socket_acceptor.cc",
"unix_domain_socket_util.cc",
]
}
......
......@@ -16,8 +16,6 @@
'ipc_channel.cc',
'ipc_channel.h',
'ipc_channel_common.cc',
'ipc_channel_factory.cc',
'ipc_channel_factory.h',
'ipc_channel_handle.h',
'ipc_channel_nacl.cc',
'ipc_channel_nacl.h',
......@@ -77,14 +75,12 @@
['>(nacl_untrusted_build)==1', {
'sources!': [
'ipc_channel.cc',
'ipc_channel_factory.cc',
'ipc_channel_posix.cc',
'unix_domain_socket_util.cc',
],
}],
['OS == "win" or OS == "ios"', {
'sources!': [
'ipc_channel_factory.cc',
'unix_domain_socket_util.cc',
],
}],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment