diff options
author | Hajime Morrita <morrita@chromium.org> | 2015-03-03 11:30:27 -0800 |
---|---|---|
committer | Hajime Morrita <morrita@chromium.org> | 2015-03-03 19:32:43 +0000 |
commit | b5b5a39410603c0c85433144dfb3b67f93392f76 (patch) | |
tree | c0de96a77ecd5129e4a30776143250633979eb2f | |
parent | 0dff61b30acdd95d2411f965448c3f9b8724bc07 (diff) | |
download | chromium_src-b5b5a39410603c0c85433144dfb3b67f93392f76.zip chromium_src-b5b5a39410603c0c85433144dfb3b67f93392f76.tar.gz chromium_src-b5b5a39410603c0c85433144dfb3b67f93392f76.tar.bz2 |
ChannelMojo: Reduce the number of dup() call
Some crash reports suggest that dup() occasionally fails in the wild.
It is used to simplify the code presuming that dup() doesn't fail
there, but apparently that isn't true.
This change skips dup() when the PlatformFileAttachment owns the
file. It helps decreasing the number of dup() calls.
BUG=457869
R=agl@chromium.org, viettrungluu@chromium.org
TBR=agl@chromium.org
Review URL: https://codereview.chromium.org/959533002
Cr-Commit-Position: refs/heads/master@{#317957}
(cherry picked from commit 98ac98f2e5ab1766c9850b5d9a424f47bdf10205)
Review URL: https://codereview.chromium.org/975853002
Cr-Commit-Position: refs/branch-heads/2311@{#107}
Cr-Branched-From: 09b7de5dd7254947cd4306de907274fa63373d48-refs/heads/master@{#317474}
-rw-r--r-- | ipc/mojo/ipc_channel_mojo.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/ipc/mojo/ipc_channel_mojo.cc b/ipc/mojo/ipc_channel_mojo.cc index c3c6e0c..45dfb84 100644 --- a/ipc/mojo/ipc_channel_mojo.cc +++ b/ipc/mojo/ipc_channel_mojo.cc @@ -165,6 +165,15 @@ void ServerChannelMojo::Close() { ChannelMojo::Close(); } +#if defined(OS_POSIX) && !defined(OS_NACL) + +base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) { + return attachment->Owns() ? base::ScopedFD(attachment->TakePlatformFile()) + : base::ScopedFD(dup(attachment->file())); +} + +#endif + } // namespace //------------------------------------------------------------------------------ @@ -359,10 +368,10 @@ MojoResult ChannelMojo::ReadFromMessageAttachmentSet( case MessageAttachment::TYPE_PLATFORM_FILE: #if defined(OS_POSIX) && !defined(OS_NACL) { - base::PlatformFile file = - dup(static_cast<IPC::internal::PlatformFileAttachment*>( - attachment.get())->file()); - if (file == -1) { + base::ScopedFD file = + TakeOrDupFile(static_cast<IPC::internal::PlatformFileAttachment*>( + attachment.get())); + if (!file.is_valid()) { DPLOG(WARNING) << "Failed to dup FD to transmit."; set->CommitAll(); return MOJO_RESULT_UNKNOWN; @@ -371,7 +380,7 @@ MojoResult ChannelMojo::ReadFromMessageAttachmentSet( MojoHandle wrapped_handle; MojoResult wrap_result = CreatePlatformHandleWrapper( mojo::embedder::ScopedPlatformHandle( - mojo::embedder::PlatformHandle(file)), + mojo::embedder::PlatformHandle(file.release())), &wrapped_handle); if (MOJO_RESULT_OK != wrap_result) { DLOG(WARNING) << "Pipe failed to wrap handles. Closing: " |