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