From 8d5ea3d089053573a623ef9f19a5e9ddde3fb14e Mon Sep 17 00:00:00 2001 From: erikchen Date: Wed, 13 Apr 2016 10:14:59 -0700 Subject: [PATCH] Refactor: Remove BrokerGetFileHandleForProcess. The method is no longer necessary, since callers can directly call IPC::GetPlatformFileForTransit. BUG=493414 Review URL: https://codereview.chromium.org/1869093002 Cr-Commit-Position: refs/heads/master@{#387012} --- .../pepper/pepper_file_io_host.cc | 10 ++----- content/common/BUILD.gn | 1 - content/common/sandbox_util.cc | 25 ------------------ content/common/sandbox_util.h | 26 ------------------- content/content_common.gypi | 3 --- content/ppapi_plugin/ppapi_thread.cc | 11 +------- .../renderer/pepper/host_array_buffer_var.cc | 1 - .../pepper_proxy_channel_delegate_impl.cc | 8 ++---- .../pepper/renderer_ppapi_host_impl.cc | 5 ++-- 9 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 content/common/sandbox_util.cc delete mode 100644 content/common/sandbox_util.h diff --git a/content/browser/renderer_host/pepper/pepper_file_io_host.cc b/content/browser/renderer_host/pepper/pepper_file_io_host.cc index eea865bd9df505..bf8bd1ab515f83 100644 --- a/content/browser/renderer_host/pepper/pepper_file_io_host.cc +++ b/content/browser/renderer_host/pepper/pepper_file_io_host.cc @@ -15,13 +15,13 @@ #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h" #include "content/browser/renderer_host/pepper/pepper_security_helper.h" #include "content/common/fileapi/file_system_messages.h" -#include "content/common/sandbox_util.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/storage_partition.h" #include "content/public/common/content_client.h" +#include "ipc/ipc_platform_file.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_file_io.h" #include "ppapi/host/dispatch_host_message.h" @@ -480,14 +480,8 @@ void PepperFileIOHost::SendOpenErrorReply( bool PepperFileIOHost::AddFileToReplyContext( int32_t open_flags, ppapi::host::ReplyMessageContext* reply_context) const { - base::ProcessId plugin_process_id = - base::GetProcId(browser_ppapi_host_->GetPluginProcess().Handle()); - if (plugin_process_id == base::kNullProcessId) - plugin_process_id = resolved_render_process_id_; - IPC::PlatformFileForTransit transit_file = - BrokerGetFileHandleForProcess(file_.GetPlatformFile(), plugin_process_id, - false); + IPC::GetPlatformFileForTransit(file_.GetPlatformFile(), false); if (transit_file == IPC::InvalidPlatformFileForTransit()) return false; diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn index fc115a824896ff..9ff78fe061d85a 100644 --- a/content/common/BUILD.gn +++ b/content/common/BUILD.gn @@ -315,7 +315,6 @@ source_set("common") { "pepper_renderer_instance_data.h", "plugin_list.cc", "plugin_list.h", - "sandbox_util.cc", ] } diff --git a/content/common/sandbox_util.cc b/content/common/sandbox_util.cc deleted file mode 100644 index 75b3977f4d63ce..00000000000000 --- a/content/common/sandbox_util.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2012 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 "content/common/sandbox_util.h" - -#include "build/build_config.h" -#include "content/public/common/sandbox_init.h" -#include "ipc/ipc_platform_file.h" - -#if defined(OS_POSIX) -#include -#endif - -namespace content { - -IPC::PlatformFileForTransit BrokerGetFileHandleForProcess( - base::PlatformFile handle, - base::ProcessId target_process_id, - bool should_close_source) { - return IPC::GetPlatformFileForTransit(handle, should_close_source); -} - -} // namespace content - diff --git a/content/common/sandbox_util.h b/content/common/sandbox_util.h deleted file mode 100644 index 54814dfff53ad2..00000000000000 --- a/content/common/sandbox_util.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2013 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 CONTENT_COMMON_SANDBOX_UTIL_H_ -#define CONTENT_COMMON_SANDBOX_UTIL_H_ - -#include "base/process/process.h" -#include "ipc/ipc_platform_file.h" - -// This file contains cross-platform sandbox code internal to content. - -namespace content { - -// Platform neutral wrapper for making an exact copy of a handle for use in -// the target process. On Windows this wraps BrokerDuplicateHandle() with the -// DUPLICATE_SAME_ACCESS flag. On posix it behaves essentially the same as -// IPC::GetFileHandleForProcess() -IPC::PlatformFileForTransit BrokerGetFileHandleForProcess( - base::PlatformFile handle, - base::ProcessId target_process_id, - bool should_close_source); - -} // namespace content - -#endif // CONTENT_COMMON_SANDBOX_UTIL_H_ diff --git a/content/content_common.gypi b/content/content_common.gypi index 78cc02b86250df..c4a59dfa73a2b5 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -539,8 +539,6 @@ 'common/sandbox_linux/sandbox_seccomp_bpf_linux.h', 'common/sandbox_mac.h', 'common/sandbox_mac.mm', - 'common/sandbox_util.cc', - 'common/sandbox_util.h', 'common/sandbox_win.cc', 'common/sandbox_win.h', 'common/savable_subframe.h', @@ -707,7 +705,6 @@ 'common/pepper_renderer_instance_data.h', 'common/plugin_list.cc', 'common/plugin_list.h', - 'common/sandbox_util.cc', 'public/common/pepper_plugin_info.cc', 'public/common/pepper_plugin_info.h', ], diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc index 8e0724b5e6b98a..469fb78442db65 100644 --- a/content/ppapi_plugin/ppapi_thread.cc +++ b/content/ppapi_plugin/ppapi_thread.cc @@ -28,7 +28,6 @@ #include "content/child/child_discardable_shared_memory_manager.h" #include "content/child/child_process.h" #include "content/common/child_process_messages.h" -#include "content/common/sandbox_util.h" #include "content/ppapi_plugin/broker_process_dispatcher.h" #include "content/ppapi_plugin/plugin_process_dispatcher.h" #include "content/ppapi_plugin/ppapi_blink_platform_impl.h" @@ -192,15 +191,7 @@ IPC::PlatformFileForTransit PpapiThread::ShareHandleWithRemote( base::PlatformFile handle, base::ProcessId peer_pid, bool should_close_source) { -#if defined(OS_WIN) - if (peer_handle_.IsValid()) { - DCHECK(is_broker_); - return IPC::GetPlatformFileForTransit(handle, should_close_source); - } -#endif - - DCHECK(peer_pid != base::kNullProcessId); - return BrokerGetFileHandleForProcess(handle, peer_pid, should_close_source); + return IPC::GetPlatformFileForTransit(handle, should_close_source); } base::SharedMemoryHandle PpapiThread::ShareSharedMemoryHandleWithRemote( diff --git a/content/renderer/pepper/host_array_buffer_var.cc b/content/renderer/pepper/host_array_buffer_var.cc index 4d8a92123670ff..a4899c3b02e821 100644 --- a/content/renderer/pepper/host_array_buffer_var.cc +++ b/content/renderer/pepper/host_array_buffer_var.cc @@ -13,7 +13,6 @@ #include "base/memory/shared_memory.h" #include "base/process/process_handle.h" #include "content/common/pepper_file_util.h" -#include "content/common/sandbox_util.h" #include "content/renderer/pepper/host_globals.h" #include "content/renderer/pepper/plugin_module.h" #include "content/renderer/pepper/renderer_ppapi_host_impl.h" diff --git a/content/renderer/pepper/pepper_proxy_channel_delegate_impl.cc b/content/renderer/pepper/pepper_proxy_channel_delegate_impl.cc index 9b0341591a8a4e..c97d6a5c56a834 100644 --- a/content/renderer/pepper/pepper_proxy_channel_delegate_impl.cc +++ b/content/renderer/pepper/pepper_proxy_channel_delegate_impl.cc @@ -6,11 +6,7 @@ #include "build/build_config.h" #include "content/child/child_process.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) +#include "ipc/ipc_platform_file.h" namespace content { @@ -33,7 +29,7 @@ PepperProxyChannelDelegateImpl::ShareHandleWithRemote( base::PlatformFile handle, base::ProcessId remote_pid, bool should_close_source) { - return BrokerGetFileHandleForProcess(handle, remote_pid, should_close_source); + return IPC::GetPlatformFileForTransit(handle, should_close_source); } base::SharedMemoryHandle diff --git a/content/renderer/pepper/renderer_ppapi_host_impl.cc b/content/renderer/pepper/renderer_ppapi_host_impl.cc index e694406dfe50c7..15589f7da271e7 100644 --- a/content/renderer/pepper/renderer_ppapi_host_impl.cc +++ b/content/renderer/pepper/renderer_ppapi_host_impl.cc @@ -11,7 +11,6 @@ #include "base/process/process_handle.h" #include "base/single_thread_task_runner.h" #include "base/thread_task_runner_handle.h" -#include "content/common/sandbox_util.h" #include "content/renderer/pepper/fullscreen_container.h" #include "content/renderer/pepper/host_globals.h" #include "content/renderer/pepper/pepper_browser_connection.h" @@ -23,6 +22,7 @@ #include "content/renderer/render_view_impl.h" #include "content/renderer/render_widget_fullscreen_pepper.h" #include "ipc/ipc_message.h" +#include "ipc/ipc_platform_file.h" #include "ppapi/host/ppapi_host.h" #include "ppapi/proxy/host_dispatcher.h" #include "third_party/WebKit/public/platform/WebRect.h" @@ -225,8 +225,7 @@ IPC::PlatformFileForTransit RendererPpapiHostImpl::ShareHandleWithRemote( // Duplicate the file handle for in process mode so this function // has the same semantics for both in process mode and out of // process mode (i.e., the remote side must cloes the handle). - return BrokerGetFileHandleForProcess( - handle, base::GetCurrentProcId(), should_close_source); + return IPC::GetPlatformFileForTransit(handle, should_close_source); } return dispatcher_->ShareHandleWithRemote(handle, should_close_source); }