summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormorrita <morrita@chromium.org>2014-10-20 16:53:25 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-20 23:53:50 +0000
commita409ccc3182ae1cb91fe7937a6c60f8d80755436 (patch)
treede8d2996aa21b74beefef4d5bc85cfae6ede8bec
parent71187e343e2a8005dff92649b3013ba5019f974a (diff)
downloadchromium_src-a409ccc3182ae1cb91fe7937a6c60f8d80755436.zip
chromium_src-a409ccc3182ae1cb91fe7937a6c60f8d80755436.tar.gz
chromium_src-a409ccc3182ae1cb91fe7937a6c60f8d80755436.tar.bz2
Refactoring: Make IPC::Channel::TakeClientFileDescriptor() a ScopedFD.
By using base::ScopedFD, the ownership of the returned FD becomes clearer. BUG=415294 R=brettw@chromium.org, jam@chromium.org, yzshen@chromium.org, sehr@chromium.org TBR=gene@chromium.org Review URL: https://codereview.chromium.org/621613002 Cr-Commit-Position: refs/heads/master@{#300381}
-rw-r--r--base/file_descriptor_posix.h2
-rw-r--r--chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc2
-rw-r--r--components/nacl/browser/nacl_process_host.cc6
-rw-r--r--components/nacl/loader/nacl_ipc_adapter.cc2
-rw-r--r--components/nacl/loader/nacl_ipc_adapter.h3
-rw-r--r--components/nacl/loader/nacl_listener.cc2
-rw-r--r--components/nacl/loader/nacl_trusted_listener.cc2
-rw-r--r--content/browser/child_process_launcher.cc20
-rw-r--r--content/browser/gpu/gpu_process_host.cc6
-rw-r--r--content/browser/plugin_process_host.cc6
-rw-r--r--content/browser/ppapi_plugin_process_host.cc6
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc8
-rw-r--r--content/browser/utility_process_host_impl.cc6
-rw-r--r--content/common/child_process_host_impl.cc2
-rw-r--r--content/common/child_process_host_impl.h2
-rw-r--r--content/common/gpu/gpu_channel.cc4
-rw-r--r--content/common/gpu/gpu_channel.h2
-rw-r--r--content/common/gpu/gpu_channel_manager.cc6
-rw-r--r--content/plugin/plugin_channel.h2
-rw-r--r--content/plugin/plugin_thread.cc2
-rw-r--r--content/ppapi_plugin/ppapi_thread.cc2
-rw-r--r--content/public/common/child_process_host.h3
-rw-r--r--content/public/common/sandboxed_process_launcher_delegate.h4
-rw-r--r--ipc/ipc_channel.h3
-rw-r--r--ipc/ipc_channel_posix.cc6
-rw-r--r--ipc/ipc_channel_posix.h2
-rw-r--r--ipc/ipc_channel_posix_unittest.cc10
-rw-r--r--ipc/ipc_channel_proxy.cc2
-rw-r--r--ipc/ipc_channel_proxy.h2
-rw-r--r--ipc/ipc_send_fds_test.cc5
-rw-r--r--ipc/ipc_test_sink.cc4
-rw-r--r--ipc/ipc_test_sink.h2
-rw-r--r--ipc/mojo/ipc_channel_mojo.cc2
-rw-r--r--ipc/mojo/ipc_channel_mojo.h2
-rw-r--r--ipc/mojo/ipc_mojo_bootstrap.cc2
-rw-r--r--ipc/mojo/ipc_mojo_bootstrap.h2
-rw-r--r--ppapi/proxy/proxy_channel.cc2
-rw-r--r--ppapi/proxy/proxy_channel.h3
38 files changed, 78 insertions, 71 deletions
diff --git a/base/file_descriptor_posix.h b/base/file_descriptor_posix.h
index c730be6..376ad39 100644
--- a/base/file_descriptor_posix.h
+++ b/base/file_descriptor_posix.h
@@ -6,6 +6,7 @@
#define BASE_FILE_DESCRIPTOR_POSIX_H_
#include "base/files/file.h"
+#include "base/files/scoped_file.h"
namespace base {
@@ -24,6 +25,7 @@ struct FileDescriptor {
}
FileDescriptor(File file) : fd(file.TakePlatformFile()), auto_close(true) {}
+ explicit FileDescriptor(ScopedFD fd) : fd(fd.release()), auto_close(true) {}
bool operator==(const FileDescriptor& other) const {
return (fd == other.fd && auto_close == other.auto_close);
diff --git a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc
index a6fc19e..1ffdd53 100644
--- a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc
+++ b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc
@@ -450,7 +450,7 @@ base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch(
#if defined(OS_POSIX)
base::FileHandleMappingVector ipc_file_list;
ipc_file_list.push_back(std::make_pair(
- startup_channel_->TakeClientFileDescriptor(),
+ startup_channel_->TakeClientFileDescriptor().release(),
kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor));
base::LaunchOptions options;
options.fds_to_remap = &ipc_file_list;
diff --git a/components/nacl/browser/nacl_process_host.cc b/components/nacl/browser/nacl_process_host.cc
index 3b6ddcf..00c1201 100644
--- a/components/nacl/browser/nacl_process_host.cc
+++ b/components/nacl/browser/nacl_process_host.cc
@@ -179,14 +179,14 @@ class NaClSandboxedProcessLauncherDelegate
virtual bool ShouldUseZygote() override {
return true;
}
- virtual int GetIpcFd() override {
- return ipc_fd_;
+ virtual base::ScopedFD TakeIpcFd() override {
+ return ipc_fd_.Pass();
}
#endif // OS_WIN
private:
#if defined(OS_POSIX)
- int ipc_fd_;
+ base::ScopedFD ipc_fd_;
#endif // OS_POSIX
};
diff --git a/components/nacl/loader/nacl_ipc_adapter.cc b/components/nacl/loader/nacl_ipc_adapter.cc
index fd95796..5d28152 100644
--- a/components/nacl/loader/nacl_ipc_adapter.cc
+++ b/components/nacl/loader/nacl_ipc_adapter.cc
@@ -460,7 +460,7 @@ NaClDesc* NaClIPCAdapter::MakeNaClDesc() {
}
#if defined(OS_POSIX)
-int NaClIPCAdapter::TakeClientFileDescriptor() {
+base::ScopedFD NaClIPCAdapter::TakeClientFileDescriptor() {
return io_thread_data_.channel_->TakeClientFileDescriptor();
}
#endif
diff --git a/components/nacl/loader/nacl_ipc_adapter.h b/components/nacl/loader/nacl_ipc_adapter.h
index 84e756d..a18aed7 100644
--- a/components/nacl/loader/nacl_ipc_adapter.h
+++ b/components/nacl/loader/nacl_ipc_adapter.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/files/scoped_file.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
@@ -106,7 +107,7 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>,
NaClDesc* MakeNaClDesc();
#if defined(OS_POSIX)
- int TakeClientFileDescriptor();
+ base::ScopedFD TakeClientFileDescriptor();
#endif
// Listener implementation.
diff --git a/components/nacl/loader/nacl_listener.cc b/components/nacl/loader/nacl_listener.cc
index 80e04c6..6eb3c14 100644
--- a/components/nacl/loader/nacl_listener.cc
+++ b/components/nacl/loader/nacl_listener.cc
@@ -146,7 +146,7 @@ scoped_refptr<NaClIPCAdapter> SetUpIPCAdapter(
ipc_adapter->ConnectChannel();
#if defined(OS_POSIX)
handle->socket =
- base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor(), true);
+ base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor());
#endif
// Pass a NaClDesc to the untrusted side. This will hold a ref to the
diff --git a/components/nacl/loader/nacl_trusted_listener.cc b/components/nacl/loader/nacl_trusted_listener.cc
index d9e5633..4c67a09 100644
--- a/components/nacl/loader/nacl_trusted_listener.cc
+++ b/components/nacl/loader/nacl_trusted_listener.cc
@@ -26,7 +26,7 @@ IPC::ChannelHandle NaClTrustedListener::TakeClientChannelHandle() {
IPC::ChannelHandle handle = channel_handle_;
#if defined(OS_POSIX)
handle.socket =
- base::FileDescriptor(channel_->TakeClientFileDescriptor(), true);
+ base::FileDescriptor(channel_->TakeClientFileDescriptor());
#endif
return handle;
}
diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc
index ab9bd91..e47bebc 100644
--- a/content/browser/child_process_launcher.cc
+++ b/content/browser/child_process_launcher.cc
@@ -87,7 +87,7 @@ class ChildProcessLauncher::Context
// We need to close the client end of the IPC channel to reliably detect
// child termination. We will close this fd after we create the child
// process which is asynchronous on Android.
- ipcfd_ = delegate->GetIpcFd();
+ ipcfd_.reset(delegate->TakeIpcFd().release());
#endif
BrowserThread::PostTask(
BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
@@ -189,14 +189,14 @@ class ChildProcessLauncher::Context
#if defined(OS_WIN)
bool launch_elevated = delegate->ShouldLaunchElevated();
#elif defined(OS_ANDROID)
- int ipcfd = delegate->GetIpcFd();
+ // Uses |ipcfd_| instead of |ipcfd| on Android.
#elif defined(OS_MACOSX)
base::EnvironmentMap env = delegate->GetEnvironment();
- int ipcfd = delegate->GetIpcFd();
+ base::ScopedFD ipcfd = delegate->TakeIpcFd();
#elif defined(OS_POSIX)
bool use_zygote = delegate->ShouldUseZygote();
base::EnvironmentMap env = delegate->GetEnvironment();
- int ipcfd = delegate->GetIpcFd();
+ base::ScopedFD ipcfd = delegate->TakeIpcFd();
#endif
scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line);
base::TimeTicks begin_launch_time = base::TimeTicks::Now();
@@ -215,7 +215,12 @@ class ChildProcessLauncher::Context
cmd_line->GetSwitchValueASCII(switches::kProcessType);
scoped_ptr<FileDescriptorInfo> files_to_register(
FileDescriptorInfoImpl::Create());
- files_to_register->Share(kPrimaryIPCChannel, ipcfd);
+
+#if defined(OS_ANDROID)
+ files_to_register->Share(kPrimaryIPCChannel, this_object->ipcfd_.get());
+#else
+ files_to_register->Transfer(kPrimaryIPCChannel, ipcfd.Pass());
+#endif
base::StatsTable* stats_table = base::StatsTable::current();
if (stats_table &&
base::SharedMemory::IsHandleValid(
@@ -247,7 +252,6 @@ class ChildProcessLauncher::Context
base::ProcessHandle handle = base::kNullProcessHandle;
// We need to close the client end of the IPC channel to reliably detect
// child termination.
- base::ScopedFD ipcfd_closer(ipcfd);
#if !defined(OS_MACOSX)
GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess(
@@ -345,7 +349,7 @@ class ChildProcessLauncher::Context
base::Process process) {
#if defined(OS_ANDROID)
// Finally close the ipcfd
- base::ScopedFD ipcfd_closer(ipcfd_);
+ base::ScopedFD ipcfd_closer = ipcfd_.Pass();
#endif
starting_ = false;
process_ = process.Pass();
@@ -433,7 +437,7 @@ class ChildProcessLauncher::Context
bool terminate_child_on_shutdown_;
#if defined(OS_ANDROID)
// The fd to close after creating the process.
- int ipcfd_;
+ base::ScopedFD ipcfd_;
#elif defined(OS_POSIX) && !defined(OS_MACOSX)
bool zygote_;
#endif
diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc
index 41d4431..0b4bfa8 100644
--- a/content/browser/gpu/gpu_process_host.cc
+++ b/content/browser/gpu/gpu_process_host.cc
@@ -250,8 +250,8 @@ class GpuSandboxedProcessLauncherDelegate
}
#elif defined(OS_POSIX)
- virtual int GetIpcFd() override {
- return ipc_fd_;
+ virtual base::ScopedFD TakeIpcFd() override {
+ return ipc_fd_.Pass();
}
#endif // OS_WIN
@@ -259,7 +259,7 @@ class GpuSandboxedProcessLauncherDelegate
#if defined(OS_WIN)
base::CommandLine* cmd_line_;
#elif defined(OS_POSIX)
- int ipc_fd_;
+ base::ScopedFD ipc_fd_;
#endif // OS_WIN
};
diff --git a/content/browser/plugin_process_host.cc b/content/browser/plugin_process_host.cc
index 9f4a06b..c256759 100644
--- a/content/browser/plugin_process_host.cc
+++ b/content/browser/plugin_process_host.cc
@@ -112,14 +112,14 @@ class PluginSandboxedProcessLauncherDelegate
}
#elif defined(OS_POSIX)
- virtual int GetIpcFd() override {
- return ipc_fd_;
+ virtual base::ScopedFD TakeIpcFd() override {
+ return ipc_fd_.Pass();
}
#endif // OS_WIN
private:
#if defined(OS_POSIX)
- int ipc_fd_;
+ base::ScopedFD ipc_fd_;
#endif // OS_POSIX
DISALLOW_COPY_AND_ASSIGN(PluginSandboxedProcessLauncherDelegate);
diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc
index 8346abf..34c3a7d 100644
--- a/content/browser/ppapi_plugin_process_host.cc
+++ b/content/browser/ppapi_plugin_process_host.cc
@@ -76,15 +76,15 @@ class PpapiPluginSandboxedProcessLauncherDelegate
.GetSwitchValueNative(switches::kPpapiPluginLauncher);
return !is_broker_ && plugin_launcher.empty() && info_.is_sandboxed;
}
- virtual int GetIpcFd() override {
- return ipc_fd_;
+ virtual base::ScopedFD TakeIpcFd() override {
+ return ipc_fd_.Pass();
}
#endif // OS_WIN
private:
#if defined(OS_POSIX)
const PepperPluginInfo& info_;
- int ipc_fd_;
+ base::ScopedFD ipc_fd_;
#endif // OS_POSIX
bool is_broker_;
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index ba098dd..2762b07 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -307,7 +307,7 @@ class RendererSandboxedProcessLauncherDelegate
public:
explicit RendererSandboxedProcessLauncherDelegate(IPC::ChannelProxy* channel)
#if defined(OS_POSIX)
- : ipc_fd_(channel->TakeClientFileDescriptor())
+ : ipc_fd_(channel->TakeClientFileDescriptor())
#endif // OS_POSIX
{}
@@ -328,14 +328,14 @@ class RendererSandboxedProcessLauncherDelegate
browser_command_line.GetSwitchValueNative(switches::kRendererCmdPrefix);
return renderer_prefix.empty();
}
- virtual int GetIpcFd() override {
- return ipc_fd_;
+ virtual base::ScopedFD TakeIpcFd() override {
+ return ipc_fd_.Pass();
}
#endif // OS_WIN
private:
#if defined(OS_POSIX)
- int ipc_fd_;
+ base::ScopedFD ipc_fd_;
#endif // OS_POSIX
};
diff --git a/content/browser/utility_process_host_impl.cc b/content/browser/utility_process_host_impl.cc
index 36f9097..848d208 100644
--- a/content/browser/utility_process_host_impl.cc
+++ b/content/browser/utility_process_host_impl.cc
@@ -65,8 +65,8 @@ class UtilitySandboxedProcessLauncherDelegate
virtual base::EnvironmentMap GetEnvironment() override {
return env_;
}
- virtual int GetIpcFd() override {
- return ipc_fd_;
+ virtual base::ScopedFD TakeIpcFd() override {
+ return ipc_fd_.Pass();
}
#endif // OS_WIN
@@ -79,7 +79,7 @@ class UtilitySandboxedProcessLauncherDelegate
#elif defined(OS_POSIX)
base::EnvironmentMap env_;
bool no_sandbox_;
- int ipc_fd_;
+ base::ScopedFD ipc_fd_;
#endif // OS_WIN
};
diff --git a/content/common/child_process_host_impl.cc b/content/common/child_process_host_impl.cc
index a1fa5fc..6bf0d7e 100644
--- a/content/common/child_process_host_impl.cc
+++ b/content/common/child_process_host_impl.cc
@@ -188,7 +188,7 @@ bool ChildProcessHostImpl::IsChannelOpening() {
}
#if defined(OS_POSIX)
-int ChildProcessHostImpl::TakeClientFileDescriptor() {
+base::ScopedFD ChildProcessHostImpl::TakeClientFileDescriptor() {
return channel_->TakeClientFileDescriptor();
}
#endif
diff --git a/content/common/child_process_host_impl.h b/content/common/child_process_host_impl.h
index dad543b..43e3e24 100644
--- a/content/common/child_process_host_impl.h
+++ b/content/common/child_process_host_impl.h
@@ -61,7 +61,7 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
virtual bool IsChannelOpening() override;
virtual void AddFilter(IPC::MessageFilter* filter) override;
#if defined(OS_POSIX)
- virtual int TakeClientFileDescriptor() override;
+ virtual base::ScopedFD TakeClientFileDescriptor() override;
#endif
private:
diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc
index 4290bf9..817751d 100644
--- a/content/common/gpu/gpu_channel.cc
+++ b/content/common/gpu/gpu_channel.cc
@@ -456,10 +456,10 @@ std::string GpuChannel::GetChannelName() {
}
#if defined(OS_POSIX)
-int GpuChannel::TakeRendererFileDescriptor() {
+base::ScopedFD GpuChannel::TakeRendererFileDescriptor() {
if (!channel_) {
NOTREACHED();
- return -1;
+ return base::ScopedFD();
}
return channel_->TakeClientFileDescriptor();
}
diff --git a/content/common/gpu/gpu_channel.h b/content/common/gpu/gpu_channel.h
index cfa71d1..32f9b09 100644
--- a/content/common/gpu/gpu_channel.h
+++ b/content/common/gpu/gpu_channel.h
@@ -72,7 +72,7 @@ class GpuChannel : public IPC::Listener, public IPC::Sender {
std::string GetChannelName();
#if defined(OS_POSIX)
- int TakeRendererFileDescriptor();
+ base::ScopedFD TakeRendererFileDescriptor();
#endif // defined(OS_POSIX)
base::ProcessId renderer_pid() const { return channel_->GetPeerPID(); }
diff --git a/content/common/gpu/gpu_channel_manager.cc b/content/common/gpu/gpu_channel_manager.cc
index b1ddad0..9a8a0f4 100644
--- a/content/common/gpu/gpu_channel_manager.cc
+++ b/content/common/gpu/gpu_channel_manager.cc
@@ -197,9 +197,9 @@ void GpuChannelManager::OnEstablishChannel(int client_id,
#if defined(OS_POSIX)
// On POSIX, pass the renderer-side FD. Also mark it as auto-close so
// that it gets closed after it has been sent.
- int renderer_fd = channel->TakeRendererFileDescriptor();
- DCHECK_NE(-1, renderer_fd);
- channel_handle.socket = base::FileDescriptor(renderer_fd, true);
+ base::ScopedFD renderer_fd = channel->TakeRendererFileDescriptor();
+ DCHECK(renderer_fd.is_valid());
+ channel_handle.socket = base::FileDescriptor(renderer_fd.Pass());
#endif
gpu_channels_.set(client_id, channel.Pass());
diff --git a/content/plugin/plugin_channel.h b/content/plugin/plugin_channel.h
index ec79dd0..27e0e93 100644
--- a/content/plugin/plugin_channel.h
+++ b/content/plugin/plugin_channel.h
@@ -51,7 +51,7 @@ class PluginChannel : public NPChannelBase {
void set_incognito(bool value) { incognito_ = value; }
#if defined(OS_POSIX)
- int TakeRendererFileDescriptor() {
+ base::ScopedFD TakeRendererFileDescriptor() {
return channel_->TakeClientFileDescriptor();
}
#endif
diff --git a/content/plugin/plugin_thread.cc b/content/plugin/plugin_thread.cc
index f1b8d95..2663b0f 100644
--- a/content/plugin/plugin_thread.cc
+++ b/content/plugin/plugin_thread.cc
@@ -146,7 +146,7 @@ void PluginThread::OnCreateChannel(int renderer_id,
#if defined(OS_POSIX)
// On POSIX, pass the renderer-side FD.
channel_handle.socket =
- base::FileDescriptor(channel->TakeRendererFileDescriptor(), true);
+ base::FileDescriptor(channel->TakeRendererFileDescriptor());
#endif
channel->set_incognito(incognito);
}
diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc
index 142f647..45d8951 100644
--- a/content/ppapi_plugin/ppapi_thread.cc
+++ b/content/ppapi_plugin/ppapi_thread.cc
@@ -492,7 +492,7 @@ bool PpapiThread::SetupRendererChannel(base::ProcessId renderer_pid,
// On POSIX, transfer ownership of the renderer-side (client) FD.
// This ensures this process will be notified when it is closed even if a
// connection is not established.
- handle->socket = base::FileDescriptor(dispatcher->TakeRendererFD(), true);
+ handle->socket = base::FileDescriptor(dispatcher->TakeRendererFD());
if (handle->socket.fd == -1)
return false;
#endif
diff --git a/content/public/common/child_process_host.h b/content/public/common/child_process_host.h
index c8abede..d5b0e69 100644
--- a/content/public/common/child_process_host.h
+++ b/content/public/common/child_process_host.h
@@ -5,6 +5,7 @@
#ifndef CONTENT_PULIC_COMMON_CHILD_PROCESS_HOST_H_
#define CONTENT_PULIC_COMMON_CHILD_PROCESS_HOST_H_
+#include "base/files/scoped_file.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "ipc/ipc_channel_proxy.h"
@@ -98,7 +99,7 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
#if defined(OS_POSIX)
// See IPC::Channel::TakeClientFileDescriptor.
- virtual int TakeClientFileDescriptor() = 0;
+ virtual base::ScopedFD TakeClientFileDescriptor() = 0;
#endif
};
diff --git a/content/public/common/sandboxed_process_launcher_delegate.h b/content/public/common/sandboxed_process_launcher_delegate.h
index 3f634a1..134fc0f 100644
--- a/content/public/common/sandboxed_process_launcher_delegate.h
+++ b/content/public/common/sandboxed_process_launcher_delegate.h
@@ -6,8 +6,8 @@
#define CONTENT_PUBLIC_COMMON_SANDBOXED_PROCESS_LAUNCHER_DELEGATE_H_
#include "base/environment.h"
+#include "base/files/scoped_file.h"
#include "base/process/process.h"
-
#include "content/common/content_export.h"
#if defined(OS_MACOSX)
@@ -64,7 +64,7 @@ class CONTENT_EXPORT SandboxedProcessLauncherDelegate {
virtual base::EnvironmentMap GetEnvironment();
// Return the file descriptor for the IPC channel.
- virtual int GetIpcFd() = 0;
+ virtual base::ScopedFD TakeIpcFd() = 0;
#if defined(OS_MACOSX)
// Gets the Mac SandboxType to enforce on the process. Return
diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h
index f6bd504..a7982e5 100644
--- a/ipc/ipc_channel.h
+++ b/ipc/ipc_channel.h
@@ -12,6 +12,7 @@
#endif
#include "base/compiler_specific.h"
+#include "base/files/scoped_file.h"
#include "base/process/process.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_message.h"
@@ -189,7 +190,7 @@ class IPC_EXPORT Channel : public Sender {
// Same as GetClientFileDescriptor, but transfers the ownership of the
// file descriptor to the caller.
// This method can be called on any thread.
- virtual int TakeClientFileDescriptor() = 0;
+ virtual base::ScopedFD TakeClientFileDescriptor() = 0;
#endif // defined(OS_POSIX) && !defined(OS_NACL)
// Returns true if a named server channel is initialized on the given channel
diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc
index 2dfd17e..c864db2 100644
--- a/ipc/ipc_channel_posix.cc
+++ b/ipc/ipc_channel_posix.cc
@@ -557,12 +557,12 @@ int ChannelPosix::GetClientFileDescriptor() const {
return client_pipe_.get();
}
-int ChannelPosix::TakeClientFileDescriptor() {
+base::ScopedFD ChannelPosix::TakeClientFileDescriptor() {
base::AutoLock lock(client_pipe_lock_);
if (!client_pipe_.is_valid())
- return -1;
+ return base::ScopedFD();
PipeMap::GetInstance()->Remove(pipe_name_);
- return client_pipe_.release();
+ return client_pipe_.Pass();
}
void ChannelPosix::CloseClientFileDescriptor() {
diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h
index c6da141..717e43e 100644
--- a/ipc/ipc_channel_posix.h
+++ b/ipc/ipc_channel_posix.h
@@ -65,7 +65,7 @@ class IPC_EXPORT ChannelPosix : public Channel,
virtual base::ProcessId GetPeerPID() const override;
virtual base::ProcessId GetSelfPID() const override;
virtual int GetClientFileDescriptor() const override;
- virtual int TakeClientFileDescriptor() override;
+ virtual base::ScopedFD TakeClientFileDescriptor() override;
// Returns true if the channel supports listening for connections.
bool AcceptsConnections() const;
diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc
index b61b345..d5346b9 100644
--- a/ipc/ipc_channel_posix_unittest.cc
+++ b/ipc/ipc_channel_posix_unittest.cc
@@ -246,9 +246,8 @@ TEST_F(IPCChannelPosixTest, SendHangTest) {
IPC::ChannelHandle in_handle("IN");
scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix(
in_handle, IPC::Channel::MODE_SERVER, &in_listener));
- base::FileDescriptor out_fd(
- in_chan->TakeClientFileDescriptor(), false);
- IPC::ChannelHandle out_handle("OUT", out_fd);
+ IPC::ChannelHandle out_handle(
+ "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor()));
scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix(
out_handle, IPC::Channel::MODE_CLIENT, &out_listener));
ASSERT_TRUE(in_chan->Connect());
@@ -272,9 +271,8 @@ TEST_F(IPCChannelPosixTest, AcceptHangTest) {
IPC::ChannelHandle in_handle("IN");
scoped_ptr<IPC::ChannelPosix> in_chan(new IPC::ChannelPosix(
in_handle, IPC::Channel::MODE_SERVER, &in_listener));
- base::FileDescriptor out_fd(
- in_chan->TakeClientFileDescriptor(), false);
- IPC::ChannelHandle out_handle("OUT", out_fd);
+ IPC::ChannelHandle out_handle(
+ "OUT", base::FileDescriptor(in_chan->TakeClientFileDescriptor()));
scoped_ptr<IPC::ChannelPosix> out_chan(new IPC::ChannelPosix(
out_handle, IPC::Channel::MODE_CLIENT, &out_listener));
ASSERT_TRUE(in_chan->Connect());
diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc
index f74dc83..e2d7ad4 100644
--- a/ipc/ipc_channel_proxy.cc
+++ b/ipc/ipc_channel_proxy.cc
@@ -446,7 +446,7 @@ int ChannelProxy::GetClientFileDescriptor() {
return channel->GetClientFileDescriptor();
}
-int ChannelProxy::TakeClientFileDescriptor() {
+base::ScopedFD ChannelProxy::TakeClientFileDescriptor() {
DCHECK(CalledOnValidThread());
Channel* channel = context_.get()->channel_.get();
diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h
index 00d5f42..84abc65 100644
--- a/ipc/ipc_channel_proxy.h
+++ b/ipc/ipc_channel_proxy.h
@@ -122,7 +122,7 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
#if defined(OS_POSIX) && !defined(OS_NACL)
// Calls through to the underlying channel's methods.
int GetClientFileDescriptor();
- int TakeClientFileDescriptor();
+ base::ScopedFD TakeClientFileDescriptor();
#endif // defined(OS_POSIX)
protected:
diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc
index fcba77f..3961fa1 100644
--- a/ipc/ipc_send_fds_test.cc
+++ b/ipc/ipc_send_fds_test.cc
@@ -234,9 +234,8 @@ class PipeChannelHelper {
void Init() {
IPC::ChannelHandle in_handle("IN");
in = IPC::Channel::CreateServer(in_handle, &null_listener_);
- base::FileDescriptor out_fd(
- in->TakeClientFileDescriptor(), false);
- IPC::ChannelHandle out_handle("OUT", out_fd);
+ IPC::ChannelHandle out_handle(
+ "OUT", base::FileDescriptor(in->TakeClientFileDescriptor()));
out = IPC::Channel::CreateClient(out_handle, &cb_listener_);
// PostTask the connect calls to make sure the callbacks happens
// on the right threads.
diff --git a/ipc/ipc_test_sink.cc b/ipc/ipc_test_sink.cc
index e97cffd..1f76c04 100644
--- a/ipc/ipc_test_sink.cc
+++ b/ipc/ipc_test_sink.cc
@@ -100,9 +100,9 @@ int TestSink::GetClientFileDescriptor() const {
return -1;
}
-int TestSink::TakeClientFileDescriptor() {
+base::ScopedFD TestSink::TakeClientFileDescriptor() {
NOTREACHED();
- return -1;
+ return base::ScopedFD();
}
#endif // defined(OS_POSIX) && !defined(OS_NACL)
diff --git a/ipc/ipc_test_sink.h b/ipc/ipc_test_sink.h
index 8154552..13386f1 100644
--- a/ipc/ipc_test_sink.h
+++ b/ipc/ipc_test_sink.h
@@ -85,7 +85,7 @@ class TestSink : public Channel {
#if defined(OS_POSIX) && !defined(OS_NACL)
virtual int GetClientFileDescriptor() const override;
- virtual int TakeClientFileDescriptor() override;
+ virtual base::ScopedFD TakeClientFileDescriptor() override;
#endif // defined(OS_POSIX) && !defined(OS_NACL)
// Used by the source of the messages to send the message to the sink. This
diff --git a/ipc/mojo/ipc_channel_mojo.cc b/ipc/mojo/ipc_channel_mojo.cc
index e99e717..0672a22 100644
--- a/ipc/mojo/ipc_channel_mojo.cc
+++ b/ipc/mojo/ipc_channel_mojo.cc
@@ -213,7 +213,7 @@ int ChannelMojo::GetClientFileDescriptor() const {
return bootstrap_->GetClientFileDescriptor();
}
-int ChannelMojo::TakeClientFileDescriptor() {
+base::ScopedFD ChannelMojo::TakeClientFileDescriptor() {
return bootstrap_->TakeClientFileDescriptor();
}
diff --git a/ipc/mojo/ipc_channel_mojo.h b/ipc/mojo/ipc_channel_mojo.h
index 696d744..4752fab 100644
--- a/ipc/mojo/ipc_channel_mojo.h
+++ b/ipc/mojo/ipc_channel_mojo.h
@@ -98,7 +98,7 @@ class IPC_MOJO_EXPORT ChannelMojo : public Channel,
#if defined(OS_POSIX) && !defined(OS_NACL)
virtual int GetClientFileDescriptor() const override;
- virtual int TakeClientFileDescriptor() override;
+ virtual base::ScopedFD TakeClientFileDescriptor() override;
// These access protected API of IPC::Message, which has ChannelMojo
// as a friend class.
diff --git a/ipc/mojo/ipc_mojo_bootstrap.cc b/ipc/mojo/ipc_mojo_bootstrap.cc
index 626dc17..7233de0 100644
--- a/ipc/mojo/ipc_mojo_bootstrap.cc
+++ b/ipc/mojo/ipc_mojo_bootstrap.cc
@@ -211,7 +211,7 @@ int MojoBootstrap::GetClientFileDescriptor() const {
return channel_->GetClientFileDescriptor();
}
-int MojoBootstrap::TakeClientFileDescriptor() {
+base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() {
return channel_->TakeClientFileDescriptor();
}
#endif // defined(OS_POSIX) && !defined(OS_NACL)
diff --git a/ipc/mojo/ipc_mojo_bootstrap.h b/ipc/mojo/ipc_mojo_bootstrap.h
index 4f4f9ee..540becf 100644
--- a/ipc/mojo/ipc_mojo_bootstrap.h
+++ b/ipc/mojo/ipc_mojo_bootstrap.h
@@ -51,7 +51,7 @@ class IPC_MOJO_EXPORT MojoBootstrap : public Listener {
#if defined(OS_POSIX) && !defined(OS_NACL)
int GetClientFileDescriptor() const;
- int TakeClientFileDescriptor();
+ base::ScopedFD TakeClientFileDescriptor();
#endif // defined(OS_POSIX) && !defined(OS_NACL)
protected:
diff --git a/ppapi/proxy/proxy_channel.cc b/ppapi/proxy/proxy_channel.cc
index 7a7dfaa..45c2a77 100644
--- a/ppapi/proxy/proxy_channel.cc
+++ b/ppapi/proxy/proxy_channel.cc
@@ -53,7 +53,7 @@ void ProxyChannel::OnChannelError() {
}
#if defined(OS_POSIX) && !defined(OS_NACL)
-int ProxyChannel::TakeRendererFD() {
+base::ScopedFD ProxyChannel::TakeRendererFD() {
DCHECK(channel());
return channel()->TakeClientFileDescriptor();
}
diff --git a/ppapi/proxy/proxy_channel.h b/ppapi/proxy/proxy_channel.h
index 873bc09..97069be 100644
--- a/ppapi/proxy/proxy_channel.h
+++ b/ppapi/proxy/proxy_channel.h
@@ -5,6 +5,7 @@
#ifndef PPAPI_PROXY_PROXY_CHANNEL_H_
#define PPAPI_PROXY_PROXY_CHANNEL_H_
+#include "base/files/scoped_file.h"
#include "base/memory/scoped_ptr.h"
#include "base/process/process.h"
#include "ipc/ipc_listener.h"
@@ -81,7 +82,7 @@ class PPAPI_PROXY_EXPORT ProxyChannel
}
#if defined(OS_POSIX) && !defined(OS_NACL)
- int TakeRendererFD();
+ base::ScopedFD TakeRendererFD();
#endif
protected: