Make PlatformFileForTransit a class on Windows.
This is required to transition consumers of PlatformFileForTransit into using
attachment brokering. Alias PlatformFileForTransit to base::SharedMemoryHandle,
since that class has the exact semantics required for brokering a HANDLE.
I tried to avoid unnecessary functionality changes, but couldn't avoid changing
some logic in NaclHostMessageFilter and DesktopSessionProxy. Both classes
receive an IPC message that contain a HANDLE from the sender process, and try to
copy the HANDLE into the current process. By switching to an
attachment-brokerable class, PlatformFileForTransit is automatically brokered,
so the duplication logic is no longer required.
Expect future CLs to convert the remaining consumers of PlatformFileForTransit
into using attachment brokering.
BUG=493414
Review URL: https://codereview.chromium.org/1830853002
Cr-Commit-Position: refs/heads/master@{#383849}
diff --git a/ipc/ipc_platform_file.cc b/ipc/ipc_platform_file.cc
index 97c176f..a9b7b880 100644
--- a/ipc/ipc_platform_file.cc
+++ b/ipc/ipc_platform_file.cc
@@ -16,18 +16,18 @@
bool close_source_handle) {
IPC::PlatformFileForTransit out_handle;
#if defined(OS_WIN)
+ HANDLE raw_handle = INVALID_HANDLE_VALUE;
DWORD options = DUPLICATE_SAME_ACCESS;
if (close_source_handle)
options |= DUPLICATE_CLOSE_SOURCE;
if (handle == INVALID_HANDLE_VALUE ||
- !::DuplicateHandle(::GetCurrentProcess(),
- handle,
- process,
- &out_handle,
- 0,
- FALSE,
- options)) {
+ !::DuplicateHandle(::GetCurrentProcess(), handle, process, &raw_handle, 0,
+ FALSE, options)) {
out_handle = IPC::InvalidPlatformFileForTransit();
+ } else {
+ out_handle =
+ IPC::PlatformFileForTransit(raw_handle, base::GetProcId(process));
+ out_handle.SetOwnershipPassesToIPC(true);
}
#elif defined(OS_POSIX)
// If asked to close the source, we can simply re-use the source fd instead of