diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 21:40:11 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 21:40:11 +0000 |
commit | 2749885f65019b0216f5c0401d0f5a28585eb83f (patch) | |
tree | 166a5090004f63ae435e434d711e2ce335909851 /chrome/browser | |
parent | 06533c0b11ce14b45eb0205fdc28a217eeba763c (diff) | |
download | chromium_src-2749885f65019b0216f5c0401d0f5a28585eb83f.zip chromium_src-2749885f65019b0216f5c0401d0f5a28585eb83f.tar.gz chromium_src-2749885f65019b0216f5c0401d0f5a28585eb83f.tar.bz2 |
POSIX: Rewrite IPC's interaction with FileDescriptor
The FileDescriptor API is clearly too hard to use. It's the only IPC
data type which is non-POD and serialising an invalid file descriptor
is fatal to Chrome on POSIX. The use of Maybe is possibly non-obvious
to non-functional programmers.
This patch merges Maybe and FileDescriptor so that serialising invalid
file descriptors is permitted and results in -1 at the other end.
(Serialising /closed/ a file descriptor is still fatal.) Also, it adds
a pointer in base/file_descriptor.h to instructions for its use with
IPC. Although it's generally bad practice to mention IPC in base, in
this case I cannot find another suitable location.
Review URL: http://codereview.chromium.org/39208
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11041 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 8 insertions, 10 deletions
diff --git a/chrome/browser/renderer_host/render_widget_helper.cc b/chrome/browser/renderer_host/render_widget_helper.cc index 715a85b..24e1710 100644 --- a/chrome/browser/renderer_host/render_widget_helper.cc +++ b/chrome/browser/renderer_host/render_widget_helper.cc @@ -263,21 +263,21 @@ TransportDIB* RenderWidgetHelper::MapTransportDIB(TransportDIB::Id dib_id) { } void RenderWidgetHelper::AllocTransportDIB( - size_t size, IPC::Maybe<TransportDIB::Handle>* result) { + size_t size, TransportDIB::Handle* result) { base::SharedMemory* shared_memory = new base::SharedMemory(); if (!shared_memory->Create(L"", false /* read write */, false /* do not open existing */, size)) { - result->valid = false; + result->fd = -1; + result->auto_close = false; delete shared_memory; return; } - result->valid = true; - shared_memory->GiveToProcess(0 /* pid, not needed */, &result->value); + shared_memory->GiveToProcess(0 /* pid, not needed */, result); // Keep a copy of the file descriptor around AutoLock locked(allocated_dibs_lock_); - allocated_dibs_[shared_memory->id()] = dup(result->value.fd); + allocated_dibs_[shared_memory->id()] = dup(result->fd); } void RenderWidgetHelper::FreeTransportDIB(TransportDIB::Id dib_id) { diff --git a/chrome/browser/renderer_host/render_widget_helper.h b/chrome/browser/renderer_host/render_widget_helper.h index eb13ff0..317a72e 100644 --- a/chrome/browser/renderer_host/render_widget_helper.h +++ b/chrome/browser/renderer_host/render_widget_helper.h @@ -11,7 +11,6 @@ #include "base/ref_counted.h" #include "base/lock.h" #include "base/waitable_event.h" -#include "chrome/common/ipc_maybe.h" #include "chrome/common/modal_dialog_event.h" #include "chrome/common/transport_dib.h" @@ -131,7 +130,7 @@ class RenderWidgetHelper : #if defined(OS_MACOSX) // Called on the IO thread to handle the allocation of a transport DIB - void AllocTransportDIB(size_t size, IPC::Maybe<TransportDIB::Handle>* result); + void AllocTransportDIB(size_t size, TransportDIB::Handle* result); // Called on the IO thread to handle the freeing of a transport DIB void FreeTransportDIB(TransportDIB::Id dib_id); diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc index 1f78df1..4460c37 100644 --- a/chrome/browser/renderer_host/resource_message_filter.cc +++ b/chrome/browser/renderer_host/resource_message_filter.cc @@ -870,7 +870,7 @@ void ResourceMessageFilter::OnSetAudioVolume( #if defined(OS_MACOSX) void ResourceMessageFilter::OnAllocTransportDIB( - size_t size, IPC::Maybe<TransportDIB::Handle>* handle) { + size_t size, TransportDIB::Handle* handle) { render_widget_helper_->AllocTransportDIB(size, handle); } diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h index 679a0ac..823685a 100644 --- a/chrome/browser/renderer_host/resource_message_filter.h +++ b/chrome/browser/renderer_host/resource_message_filter.h @@ -19,7 +19,6 @@ #include "chrome/browser/net/resolve_proxy_msg_helper.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/common/ipc_channel_proxy.h" -#include "chrome/common/ipc_maybe.h" #include "chrome/common/modal_dialog_event.h" #include "chrome/common/notification_observer.h" #include "chrome/common/transport_dib.h" @@ -215,7 +214,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter, // Browser side transport DIB allocation void OnAllocTransportDIB(size_t size, - IPC::Maybe<TransportDIB::Handle>* result); + TransportDIB::Handle* result); void OnFreeTransportDIB(TransportDIB::Id dib_id); // We have our own clipboard service because we want to access the clipboard |