diff options
-rw-r--r-- | base/file_descriptor_posix.h | 4 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_helper.cc | 10 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_helper.h | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.cc | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter.h | 3 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 | ||||
-rw-r--r-- | chrome/common/ipc_message_utils.h | 64 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 3 | ||||
-rw-r--r-- | chrome/renderer/render_process.cc | 8 |
9 files changed, 49 insertions, 49 deletions
diff --git a/base/file_descriptor_posix.h b/base/file_descriptor_posix.h index 8ebc5be..0bcd4b6 100644 --- a/base/file_descriptor_posix.h +++ b/base/file_descriptor_posix.h @@ -10,6 +10,10 @@ namespace base { // ----------------------------------------------------------------------------- // We introduct a special structure for file descriptors in order that we are // able to use template specialisation to special-case their handling. +// +// WARNING: (Chromium only) There are subtleties to consider if serialising +// these objects over IPC. See comments in chrome/common/ipc_message_utils.h +// above the template specialisation for this structure. // ----------------------------------------------------------------------------- struct FileDescriptor { FileDescriptor() 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 diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 38ee051..4f04204 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -177,7 +177,6 @@ 'common/ipc_channel_win.h', 'common/ipc_logging.cc', 'common/ipc_logging.h', - 'common/ipc_maybe.h', 'common/ipc_message.cc', 'common/ipc_message.h', 'common/ipc_message_macros.h', diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index e877221..1f54645 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -16,7 +16,6 @@ #if defined(OS_POSIX) #include "chrome/common/file_descriptor_set_posix.h" #endif -#include "chrome/common/ipc_maybe.h" #include "chrome/common/ipc_sync_message.h" #include "chrome/common/thumbnail_score.h" #include "chrome/common/transport_dib.h" @@ -694,14 +693,44 @@ struct ParamTraits<gfx::Size> { }; #if defined(OS_POSIX) +// FileDescriptors may be serialised over IPC channels on POSIX. On the +// receiving side, the FileDescriptor is a valid duplicate of the file +// descriptor which was transmitted: *it is not just a copy of the integer like +// HANDLEs on Windows*. The only exception is if the file descriptor is < 0. In +// this case, the receiving end will see a value of -1. *Zero is a valid file +// descriptor*. +// +// The received file descriptor will have the |auto_close| flag set to true. The +// code which handles the message is responsible for taking ownership of it. +// File descriptors are OS resources and must be closed when no longer needed. +// +// When sending a file descriptor, the file descriptor must be valid at the time +// of transmission. Since transmission is not synchronous, one should consider +// dup()ing any file descriptors to be transmitted and setting the |auto_close| +// flag, which causes the file descriptor to be closed after writing. template<> struct ParamTraits<base::FileDescriptor> { typedef base::FileDescriptor param_type; static void Write(Message* m, const param_type& p) { - if (!m->WriteFileDescriptor(p)) - NOTREACHED(); + const bool valid = p.fd >= 0; + WriteParam(m, valid); + + if (valid) { + if (!m->WriteFileDescriptor(p)) + NOTREACHED(); + } } static bool Read(const Message* m, void** iter, param_type* r) { + bool valid; + if (!ReadParam(m, iter, &valid)) + return false; + + if (!valid) { + r->fd = -1; + r->auto_close = false; + return true; + } + return m->ReadFileDescriptor(iter, r); } static void Log(const param_type& p, std::wstring* l) { @@ -947,34 +976,6 @@ struct ParamTraits<TransportDIB::Id> { }; #endif -template<typename A> -struct ParamTraits<Maybe<A> > { - typedef struct Maybe<A> param_type; - static void Write(Message* m, const param_type& p) { - WriteParam(m, p.valid); - if (p.valid) - WriteParam(m, p.value); - } - static bool Read(const Message* m, void** iter, param_type* r) { - if (!ReadParam(m, iter, &r->valid)) - return false; - - if (r->valid) - return ReadParam(m, iter, &r->value); - return true; - } - static void Log(const param_type& p, std::wstring* l) { - if (p.valid) { - l->append(L"Just "); - ParamTraits<A>::Log(p.value, l); - } else { - l->append(L"Nothing"); - } - - } -}; - - template <> struct ParamTraits<Message> { static void Write(Message* m, const Message& p) { @@ -996,7 +997,6 @@ struct ParamTraits<Message> { } }; - template <> struct ParamTraits<Tuple0> { typedef Tuple0 param_type; diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index db71aa2..d8418e8 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -16,7 +16,6 @@ #include "base/gfx/native_widget_types.h" #include "base/shared_memory.h" #include "chrome/common/ipc_message_macros.h" -#include "chrome/common/ipc_maybe.h" #include "chrome/common/transport_dib.h" #include "skia/include/SkBitmap.h" #include "webkit/glue/console_message_level.h" @@ -1189,7 +1188,7 @@ IPC_BEGIN_MESSAGES(ViewHost) // on its behalf. We return a file descriptor to the POSIX shared memory. IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_AllocTransportDIB, size_t, /* bytes requested */ - IPC::Maybe<TransportDIB::Handle> /* DIB */) + TransportDIB::Handle /* DIB */) // Since the browser keeps handles to the allocated transport DIBs, this // message is sent to tell the browser that it may release them when the diff --git a/chrome/renderer/render_process.cc b/chrome/renderer/render_process.cc index 99b91fa..b10042b 100644 --- a/chrome/renderer/render_process.cc +++ b/chrome/renderer/render_process.cc @@ -190,13 +190,13 @@ TransportDIB* RenderProcess::CreateTransportDIB(size_t size) { #elif defined(OS_MACOSX) // defined(OS_WIN) || defined(OS_LINUX) // Mac creates transport DIBs in the browser, so we need to do a sync IPC to // get one. - IPC::Maybe<TransportDIB::Handle> mhandle; - IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &mhandle); + TransportDIB::Handle handle; + IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle); if (!child_thread()->Send(msg)) return NULL; - if (!mhandle.valid) + if (handle.fd < 0) return NULL; - return TransportDIB::Map(mhandle.value); + return TransportDIB::Map(handle); #endif // defined(OS_MACOSX) } |