diff options
-rw-r--r-- | ui/gfx/gtk_native_view_id_manager.cc | 34 | ||||
-rw-r--r-- | ui/gfx/gtk_native_view_id_manager.h | 23 |
2 files changed, 14 insertions, 43 deletions
diff --git a/ui/gfx/gtk_native_view_id_manager.cc b/ui/gfx/gtk_native_view_id_manager.cc index 14105f8..40a8184 100644 --- a/ui/gfx/gtk_native_view_id_manager.cc +++ b/ui/gfx/gtk_native_view_id_manager.cc @@ -31,10 +31,6 @@ static void OnDestroy(GtkObject* obj, void* arg) { // ----------------------------------------------------------------------------- - -// ----------------------------------------------------------------------------- -// Public functions... - GtkNativeViewManager::GtkNativeViewManager() { } @@ -47,12 +43,11 @@ GtkNativeViewManager* GtkNativeViewManager::GetInstance() { } gfx::NativeViewId GtkNativeViewManager::GetIdForWidget(gfx::NativeView widget) { + DCHECK(CalledOnValidThread()); // This is just for unit tests: if (!widget) return 0; - base::AutoLock locked(lock_); - std::map<gfx::NativeView, gfx::NativeViewId>::const_iterator i = native_view_to_id_.find(widget); @@ -83,8 +78,7 @@ gfx::NativeViewId GtkNativeViewManager::GetIdForWidget(gfx::NativeView widget) { } bool GtkNativeViewManager::GetXIDForId(XID* output, gfx::NativeViewId id) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); std::map<gfx::NativeViewId, NativeViewInfo>::const_iterator i = id_to_info_.find(id); @@ -97,8 +91,7 @@ bool GtkNativeViewManager::GetXIDForId(XID* output, gfx::NativeViewId id) { bool GtkNativeViewManager::GetNativeViewForId(gfx::NativeView* output, gfx::NativeViewId id) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); std::map<gfx::NativeViewId, NativeViewInfo>::const_iterator i = id_to_info_.find(id); @@ -111,8 +104,7 @@ bool GtkNativeViewManager::GetNativeViewForId(gfx::NativeView* output, bool GtkNativeViewManager::GetPermanentXIDForId(XID* output, gfx::NativeViewId id) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); std::map<gfx::NativeViewId, NativeViewInfo>::iterator i = id_to_info_.find(id); @@ -144,8 +136,7 @@ bool GtkNativeViewManager::GetPermanentXIDForId(XID* output, } bool GtkNativeViewManager::AddRefPermanentXID(XID xid) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); std::map<XID, PermanentXIDInfo>::iterator i = perm_xid_to_info_.find(xid); @@ -158,8 +149,7 @@ bool GtkNativeViewManager::AddRefPermanentXID(XID xid) { } void GtkNativeViewManager::ReleasePermanentXID(XID xid) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); std::map<XID, PermanentXIDInfo>::iterator i = perm_xid_to_info_.find(xid); @@ -188,8 +178,7 @@ void GtkNativeViewManager::ReleasePermanentXID(XID xid) { // Private functions... gfx::NativeViewId GtkNativeViewManager::GetWidgetId(gfx::NativeView widget) { - lock_.AssertAcquired(); - + DCHECK(CalledOnValidThread()); std::map<gfx::NativeView, gfx::NativeViewId>::const_iterator i = native_view_to_id_.find(widget); @@ -198,8 +187,7 @@ gfx::NativeViewId GtkNativeViewManager::GetWidgetId(gfx::NativeView widget) { } void GtkNativeViewManager::OnRealize(gfx::NativeView widget) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); const gfx::NativeViewId id = GetWidgetId(widget); std::map<gfx::NativeViewId, NativeViewInfo>::iterator i = id_to_info_.find(id); @@ -211,8 +199,7 @@ void GtkNativeViewManager::OnRealize(gfx::NativeView widget) { } void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); const gfx::NativeViewId id = GetWidgetId(widget); std::map<gfx::NativeViewId, NativeViewInfo>::iterator i = id_to_info_.find(id); @@ -221,8 +208,7 @@ void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) { } void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) { - base::AutoLock locked(lock_); - + DCHECK(CalledOnValidThread()); std::map<gfx::NativeView, gfx::NativeViewId>::iterator i = native_view_to_id_.find(widget); CHECK(i != native_view_to_id_.end()); diff --git a/ui/gfx/gtk_native_view_id_manager.h b/ui/gfx/gtk_native_view_id_manager.h index 2a651a0..aad39ad 100644 --- a/ui/gfx/gtk_native_view_id_manager.h +++ b/ui/gfx/gtk_native_view_id_manager.h @@ -10,6 +10,7 @@ #include "base/memory/singleton.h" #include "base/synchronization/lock.h" +#include "base/threading/non_thread_safe.h" #include "ui/gfx/native_widget_types.h" typedef unsigned long XID; @@ -28,15 +29,13 @@ struct _GtkPreserveWindow; // // Thus, we have this object. It produces random NativeViewIds from GtkWidget // pointers and observes the various signals from the widget for when an X -// window is created, destroyed etc. Thus it provides a thread safe mapping -// from NativeViewIds to the current XID for that widget. -class GtkNativeViewManager { +// window is created, destroyed etc. Thus it provides a mapping from +// NativeViewIds to the current XID for that widget. +class GtkNativeViewManager : public base::NonThreadSafe { public: // Returns the singleton instance. static GtkNativeViewManager* GetInstance(); - // Must be called from the UI thread: - // // Return a NativeViewId for the given widget and attach to the various // signals emitted by that widget. The NativeViewId is pseudo-randomly // allocated so that a compromised renderer trying to guess values will fail @@ -44,8 +43,6 @@ class GtkNativeViewManager { // lifetime of the GtkWidget. gfx::NativeViewId GetIdForWidget(gfx::NativeView widget); - // May be called from any thread: - // // xid: (output) the resulting X window ID, or 0 // id: a value previously returned from GetIdForWidget // returns: true if |id| is a valid id, false otherwise. @@ -54,14 +51,9 @@ class GtkNativeViewManager { // |*xid| is set to 0. bool GetXIDForId(XID* xid, gfx::NativeViewId id); - // May be called from the UI thread: - // // Same as GetXIDForId except it returns the NativeView (GtkWidget*). bool GetNativeViewForId(gfx::NativeView* xid, gfx::NativeViewId id); - // Must be called from the UI thread because we may need the associated - // widget to create a window. - // // Keeping the XID permanent requires a bit of overhead, so it must // be explicitly requested. // @@ -70,14 +62,10 @@ class GtkNativeViewManager { // returns: true if |id| is a valid id, false otherwise. bool GetPermanentXIDForId(XID* xid, gfx::NativeViewId id); - // Can be called from any thread. // Will return false if the given XID isn't permanent or has already been // released. bool AddRefPermanentXID(XID xid); - // Must be called from the UI thread because we may need to access a - // GtkWidget or destroy a GdkWindow. - // // If the widget associated with the XID is still alive, allow the widget // to destroy the associated XID when it wants. Otherwise, destroy the // GdkWindow associated with the XID. @@ -103,9 +91,6 @@ class GtkNativeViewManager { gfx::NativeViewId GetWidgetId(gfx::NativeView id); - // protects native_view_to_id_ and id_to_info_ - base::Lock lock_; - // If asked for an id for the same widget twice, we want to return the same // id. So this records the current mapping. std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; |