0

Further clean up pepper's use of SharedMemory.

This CL uses the new methods content::BrokerDuplicateSharedMemoryHandle() and
base::SharedMemory::DuplicateHandle() to remove some duplicated code. This CL
changes the implementation of ShareSharedMemoryhandleWithRemote() to no longer
assume that the SharedMemoryHandle is backed by a POSIX fd.

BUG=466437

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

Cr-Commit-Position: refs/heads/master@{#332903}
This commit is contained in:
erikchen
2015-06-04 13:44:18 -07:00
committed by Commit bot
parent a7f6fc4017
commit fc29ad99d6
5 changed files with 44 additions and 49 deletions

@@ -202,16 +202,24 @@ IPC::PlatformFileForTransit PpapiThread::ShareHandleWithRemote(
base::SharedMemoryHandle PpapiThread::ShareSharedMemoryHandleWithRemote( base::SharedMemoryHandle PpapiThread::ShareSharedMemoryHandleWithRemote(
const base::SharedMemoryHandle& handle, const base::SharedMemoryHandle& handle,
base::ProcessId remote_pid) { base::ProcessId remote_pid) {
base::PlatformFile local_platform_file = #if defined(OS_WIN)
#if defined(OS_POSIX) if (peer_handle_.IsValid()) {
handle.fd; DCHECK(is_broker_);
#elif defined(OS_WIN) return IPC::GetFileHandleForProcess(handle, peer_handle_.Get(), false);
handle; }
#else
#error Not implemented.
#endif #endif
return PpapiThread::ShareHandleWithRemote(local_platform_file, remote_pid,
false); DCHECK(remote_pid != base::kNullProcessId);
#if defined(OS_WIN) || defined(OS_MACOSX)
base::SharedMemoryHandle duped_handle;
bool success =
BrokerDuplicateSharedMemoryHandle(handle, remote_pid, &duped_handle);
if (success)
return duped_handle;
return base::SharedMemory::NULLHandle();
#else
return base::SharedMemory::DuplicateHandle(handle);
#endif // defined(OS_WIN) || defined(OS_MACOSX)
} }
std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() { std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() {

@@ -7,6 +7,10 @@
#include "content/child/child_process.h" #include "content/child/child_process.h"
#include "content/common/sandbox_util.h" #include "content/common/sandbox_util.h"
#if defined(OS_WIN) || defined(OS_MACOSX)
#include "content/public/common/sandbox_init.h"
#endif // defined(OS_WIN) || defined(OS_MACOSX)
namespace content { namespace content {
PepperProxyChannelDelegateImpl::~PepperProxyChannelDelegateImpl() {} PepperProxyChannelDelegateImpl::~PepperProxyChannelDelegateImpl() {}
@@ -35,15 +39,16 @@ base::SharedMemoryHandle
PepperProxyChannelDelegateImpl::ShareSharedMemoryHandleWithRemote( PepperProxyChannelDelegateImpl::ShareSharedMemoryHandleWithRemote(
const base::SharedMemoryHandle& handle, const base::SharedMemoryHandle& handle,
base::ProcessId remote_pid) { base::ProcessId remote_pid) {
base::PlatformFile local_platform_file = #if defined(OS_WIN) || defined(OS_MACOSX)
#if defined(OS_POSIX) base::SharedMemoryHandle duped_handle;
handle.fd; bool success =
#elif defined(OS_WIN) BrokerDuplicateSharedMemoryHandle(handle, remote_pid, &duped_handle);
handle; if (success)
return duped_handle;
return base::SharedMemory::NULLHandle();
#else #else
#error Not implemented. return base::SharedMemory::DuplicateHandle(handle);
#endif #endif // defined(OS_WIN) || defined(OS_MACOSX)
return ShareHandleWithRemote(local_platform_file, remote_pid, false);
} }
} // namespace content } // namespace content

@@ -234,15 +234,11 @@ IPC::PlatformFileForTransit RendererPpapiHostImpl::ShareHandleWithRemote(
base::SharedMemoryHandle base::SharedMemoryHandle
RendererPpapiHostImpl::ShareSharedMemoryHandleWithRemote( RendererPpapiHostImpl::ShareSharedMemoryHandleWithRemote(
const base::SharedMemoryHandle& handle) { const base::SharedMemoryHandle& handle) {
base::PlatformFile local_platform_file = if (!dispatcher_) {
#if defined(OS_POSIX) DCHECK(is_running_in_process_);
handle.fd; return base::SharedMemory::DuplicateHandle(handle);
#elif defined(OS_WIN) }
handle; return dispatcher_->ShareSharedMemoryHandleWithRemote(handle);
#else
#error Not implemented.
#endif
return ShareHandleWithRemote(local_platform_file, false);
} }
bool RendererPpapiHostImpl::IsRunningInProcess() const { bool RendererPpapiHostImpl::IsRunningInProcess() const {

@@ -260,14 +260,8 @@ PluginProxyTestHarness::PluginDelegateMock::ShareHandleWithRemote(
base::SharedMemoryHandle base::SharedMemoryHandle
PluginProxyTestHarness::PluginDelegateMock::ShareSharedMemoryHandleWithRemote( PluginProxyTestHarness::PluginDelegateMock::ShareSharedMemoryHandleWithRemote(
const base::SharedMemoryHandle& handle, const base::SharedMemoryHandle& handle,
base::ProcessId remote_pid) { base::ProcessId /* remote_pid */) {
#if defined(OS_POSIX) return base::SharedMemory::DuplicateHandle(handle);
return ShareHandleWithRemote(handle.fd, remote_pid, false);
#elif defined(OS_WIN)
return ShareHandleWithRemote(handle, remote_pid, false);
#else
#error Not implemented.
#endif
} }
std::set<PP_Instance>* std::set<PP_Instance>*
@@ -506,14 +500,8 @@ HostProxyTestHarness::DelegateMock::ShareHandleWithRemote(
base::SharedMemoryHandle base::SharedMemoryHandle
HostProxyTestHarness::DelegateMock::ShareSharedMemoryHandleWithRemote( HostProxyTestHarness::DelegateMock::ShareSharedMemoryHandleWithRemote(
const base::SharedMemoryHandle& handle, const base::SharedMemoryHandle& handle,
base::ProcessId remote_pid) { base::ProcessId /*remote_pid*/) {
#if defined(OS_POSIX) return base::SharedMemory::DuplicateHandle(handle);
return ShareHandleWithRemote(handle.fd, remote_pid, false);
#elif defined(OS_WIN)
return ShareHandleWithRemote(handle, remote_pid, false);
#else
#error Not implemented.
#endif
} }
// HostProxyTest --------------------------------------------------------------- // HostProxyTest ---------------------------------------------------------------

@@ -76,13 +76,11 @@ IPC::PlatformFileForTransit ProxyChannel::ShareHandleWithRemote(
base::SharedMemoryHandle ProxyChannel::ShareSharedMemoryHandleWithRemote( base::SharedMemoryHandle ProxyChannel::ShareSharedMemoryHandleWithRemote(
const base::SharedMemoryHandle& handle) { const base::SharedMemoryHandle& handle) {
#if defined(OS_POSIX) if (!channel_.get())
return ShareHandleWithRemote(handle.fd, false); return base::SharedMemory::NULLHandle();
#elif defined(OS_WIN)
return ShareHandleWithRemote(handle, false); DCHECK(peer_pid_ != base::kNullProcessId);
#else return delegate_->ShareSharedMemoryHandleWithRemote(handle, peer_pid_);
#error Not implemented.
#endif
} }
bool ProxyChannel::Send(IPC::Message* msg) { bool ProxyChannel::Send(IPC::Message* msg) {