diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-15 22:25:11 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-15 22:25:11 +0000 |
commit | 1c4947ffee0b7f5672737b542eb6adf466fcb223 (patch) | |
tree | ca2b1631479523a3a397fac842fe0870f422193f /chrome/plugin | |
parent | c0ce93d64e2374f29acf2130c5324dc54762f0fa (diff) | |
download | chromium_src-1c4947ffee0b7f5672737b542eb6adf466fcb223.zip chromium_src-1c4947ffee0b7f5672737b542eb6adf466fcb223.tar.gz chromium_src-1c4947ffee0b7f5672737b542eb6adf466fcb223.tar.bz2 |
WaitableEvent is the replacement for Windows events. Previously in the code, a HANDLE from CreateEvent was used for signaling, both within a process and across processes.
WaitableEvent is the cross platform replacement for this. To convert:
* HANDLE -> base::WaitableEvent*
* ScopedHandle -> scoped_ptr<base::WaitableEvent>
* CreateEvent -> new base::WaitableEvent
* SetEvent -> base::WaitableEvent::Signal
* ResetEvent -> base::WaitableEvent::Reset
* ObjectWatcher -> base::WaitableEventWatcher
* WaitForMultipleObjects -> static base::WaitableEvent::WaitMany
ObjectWatcher remains for Windows specific code. WaitableEventWatcher has an identical interface save,
* It uses WaitableEvents, not HANDLEs
* It returns void from StartWatching and StopWatcher, rather than errors. System internal errors are fatal to the address space
IMPORTANT: There are semantic differences between the different platforms. WaitableEvents on Windows are implemented on top of events. Windows events work across process and this is used mostly for modal dialog support. Windows events can be duplicated with DuplicateHandle.
On other platforms, WaitableEvent works only within a single process. In the future we shall have to replace the current uses of cross-process events with IPCs.
BEWARE: HANDLE, on Windows, is a void *. Since any pointer type coerces to void *, you can pass a WaitableEvent * where a HANDLE is expected without any build-time errors.
Review URL: http://codereview.chromium.org/16554
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8126 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/plugin')
-rw-r--r-- | chrome/plugin/npobject_proxy.cc | 11 | ||||
-rw-r--r-- | chrome/plugin/npobject_proxy.h | 11 | ||||
-rw-r--r-- | chrome/plugin/npobject_util.cc | 2 | ||||
-rw-r--r-- | chrome/plugin/npobject_util.h | 5 | ||||
-rw-r--r-- | chrome/plugin/webplugin_proxy.cc | 12 | ||||
-rw-r--r-- | chrome/plugin/webplugin_proxy.h | 7 |
6 files changed, 32 insertions, 16 deletions
diff --git a/chrome/plugin/npobject_proxy.cc b/chrome/plugin/npobject_proxy.cc index 7df4e5c..3c4f811 100644 --- a/chrome/plugin/npobject_proxy.cc +++ b/chrome/plugin/npobject_proxy.cc @@ -4,6 +4,7 @@ #include "chrome/plugin/npobject_proxy.h" +#include "base/waitable_event.h" #include "chrome/common/plugin_messages.h" #include "chrome/common/win_util.h" #include "chrome/plugin/npobject_util.h" @@ -48,7 +49,7 @@ NPObjectProxy::NPObjectProxy( PluginChannelBase* channel, int route_id, void* npobject_ptr, - HANDLE modal_dialog_event) + base::WaitableEvent* modal_dialog_event) : channel_(channel), route_id_(route_id), npobject_ptr_(npobject_ptr), @@ -67,7 +68,7 @@ NPObjectProxy::~NPObjectProxy() { NPObject* NPObjectProxy::Create(PluginChannelBase* channel, int route_id, void* npobject_ptr, - HANDLE modal_dialog_event) { + base::WaitableEvent* modal_dialog_event) { NPObjectWrapper* obj = reinterpret_cast<NPObjectWrapper*>( NPN_CreateObject(0, &npclass_proxy_)); obj->proxy = new NPObjectProxy( @@ -178,7 +179,7 @@ bool NPObjectProxy::NPInvokePrivate(NPP npp, // messages are pumped). msg->set_pump_messages_event(proxy->modal_dialog_event_); - HANDLE modal_dialog_event_handle = proxy->modal_dialog_event_; + base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_; proxy->Send(msg); @@ -237,7 +238,7 @@ bool NPObjectProxy::NPGetProperty(NPObject *obj, CreateNPIdentifierParam(name, &name_param); NPVariant_Param param; - HANDLE modal_dialog_event_handle = proxy->modal_dialog_event_; + base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_; scoped_refptr<PluginChannelBase> channel(proxy->channel_); proxy->Send(new NPObjectMsg_GetProperty( proxy->route_id(), name_param, ¶m, &result)); @@ -367,7 +368,7 @@ bool NPObjectProxy::NPNEvaluate(NPP npp, // the reasoning behind setting the pump messages event in the sync message. msg->set_pump_messages_event(proxy->modal_dialog_event_); scoped_refptr<PluginChannelBase> channel(proxy->channel_); - HANDLE modal_dialog_event_handle = proxy->modal_dialog_event_; + base::WaitableEvent* modal_dialog_event_handle = proxy->modal_dialog_event_; proxy->Send(msg); // Send may delete proxy. proxy = NULL; diff --git a/chrome/plugin/npobject_proxy.h b/chrome/plugin/npobject_proxy.h index 4157717..dcc4d01 100644 --- a/chrome/plugin/npobject_proxy.h +++ b/chrome/plugin/npobject_proxy.h @@ -16,6 +16,10 @@ class PluginChannelBase; struct NPObject; struct NPVariant_Param; +namespace base { +class WaitableEvent; +} + // When running a plugin in a different process from the renderer, we need to // proxy calls to NPObjects across process boundaries. This happens both ways, // as a plugin can get an NPObject for the window, and a page can get an @@ -29,10 +33,11 @@ class NPObjectProxy : public IPC::Channel::Listener, public: ~NPObjectProxy(); + // modal_dialog_event_ is must be valid for the lifetime of the NPObjectProxy. static NPObject* Create(PluginChannelBase* channel, int route_id, void* npobject_ptr, - HANDLE modal_dialog_event); + base::WaitableEvent* modal_dialog_event); // IPC::Message::Sender implementation: bool Send(IPC::Message* msg); @@ -93,7 +98,7 @@ class NPObjectProxy : public IPC::Channel::Listener, NPObjectProxy(PluginChannelBase* channel, int route_id, void* npobject_ptr, - HANDLE modal_dialog_event); + base::WaitableEvent* modal_dialog_event); // IPC::Channel::Listener implementation: void OnMessageReceived(const IPC::Message& msg); @@ -109,7 +114,7 @@ class NPObjectProxy : public IPC::Channel::Listener, int route_id_; void* npobject_ptr_; scoped_refptr<PluginChannelBase> channel_; - HANDLE modal_dialog_event_; + base::WaitableEvent* modal_dialog_event_; }; #endif // CHROME_PLUGIN_NPOBJECT_PROXY_H_ diff --git a/chrome/plugin/npobject_util.cc b/chrome/plugin/npobject_util.cc index 8936471..f5283f9 100644 --- a/chrome/plugin/npobject_util.cc +++ b/chrome/plugin/npobject_util.cc @@ -200,7 +200,7 @@ void CreateNPVariantParam(const NPVariant& variant, void CreateNPVariant(const NPVariant_Param& param, PluginChannelBase* channel, NPVariant* result, - HANDLE modal_dialog_event) { + base::WaitableEvent* modal_dialog_event) { switch (param.type) { case NPVARIANT_PARAM_VOID: result->type = NPVariantType_Void; diff --git a/chrome/plugin/npobject_util.h b/chrome/plugin/npobject_util.h index cc9347e..ba74a6b 100644 --- a/chrome/plugin/npobject_util.h +++ b/chrome/plugin/npobject_util.h @@ -22,6 +22,9 @@ struct NPIdentifier_Param; struct NPVariant_Param; typedef void *NPIdentifier; +namespace base { +class WaitableEvent; +} // Needs to be called early in the plugin process lifetime, before any // plugin instances are initialized. @@ -52,7 +55,7 @@ void CreateNPVariantParam(const NPVariant& variant, void CreateNPVariant(const NPVariant_Param& param, PluginChannelBase* channel, NPVariant* result, - HANDLE modal_dialog_event); + base::WaitableEvent* modal_dialog_event); // Given a plugin's HWND, returns an event associated with the WebContents // that's set when inside a messagebox. This tells the plugin process that diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index 0bd6ed8..bb7ee5c 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -8,6 +8,7 @@ #include "base/scoped_handle.h" #include "base/shared_memory.h" #include "base/singleton.h" +#include "base/waitable_event.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/plugin_messages.h" #include "chrome/common/win_util.h" @@ -47,7 +48,7 @@ WebPluginProxy::WebPluginProxy( FALSE, 0); DCHECK(result) << "Couldn't duplicate the modal dialog handle for the plugin."; - modal_dialog_event_.Set(event); + modal_dialog_event_.reset(new base::WaitableEvent(event)); } WebPluginProxy::~WebPluginProxy() { @@ -121,7 +122,7 @@ NPObject* WebPluginProxy::GetWindowScriptNPObject() { window_npobject_ = NPObjectProxy::Create(channel_, npobject_route_id, npobject_ptr, - modal_dialog_event_.Get()); + modal_dialog_event_.get()); return window_npobject_; } @@ -141,7 +142,7 @@ NPObject* WebPluginProxy::GetPluginElement() { plugin_element_ = NPObjectProxy::Create(channel_, npobject_route_id, npobject_ptr, - modal_dialog_event_.Get()); + modal_dialog_event_.get()); return plugin_element_; } @@ -170,8 +171,9 @@ void WebPluginProxy::ShowModalHTMLDialog(const GURL& url, int width, int height, // Create a new event and set it. This forces us to pump messages while // waiting for a response (which won't come until the dialog is closed). This // avoids a deadlock. - ScopedHandle event(CreateEvent(NULL, FALSE, TRUE, NULL)); - msg->set_pump_messages_event(event); + scoped_ptr<base::WaitableEvent> event( + new base::WaitableEvent(false, true)); + msg->set_pump_messages_event(event.get()); Send(msg); } diff --git a/chrome/plugin/webplugin_proxy.h b/chrome/plugin/webplugin_proxy.h index c2cefc7..7828abf 100644 --- a/chrome/plugin/webplugin_proxy.h +++ b/chrome/plugin/webplugin_proxy.h @@ -8,12 +8,17 @@ #include "base/hash_tables.h" #include "base/ref_counted.h" #include "base/scoped_handle.h" +#include "base/scoped_ptr.h" #include "base/shared_memory.h" #include "base/timer.h" #include "chrome/common/ipc_message.h" #include "chrome/common/chrome_plugin_api.h" #include "webkit/glue/webplugin.h" +namespace base { +class WaitableEvent; +} + class PluginChannel; class WebPluginDelegateImpl; @@ -126,7 +131,7 @@ class WebPluginProxy : public WebPlugin { gfx::Rect damaged_rect_; bool waiting_for_paint_; uint32 cp_browsing_context_; - ScopedHandle modal_dialog_event_; + scoped_ptr<base::WaitableEvent> modal_dialog_event_; // Variables used for desynchronized windowless plugin painting. See note in // webplugin_delegate_proxy.h for how this works. |