| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ | 5 #ifndef UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ |
| 6 #define UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ | 6 #define UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ |
| 7 | 7 |
| 8 #include <glib.h> | 8 #include <glib.h> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "ui/base/ui_export.h" | 13 #include "ui/base/ui_base_export.h" |
| 14 | 14 |
| 15 template <typename T> struct DefaultSingletonTraits; | 15 template <typename T> struct DefaultSingletonTraits; |
| 16 | 16 |
| 17 typedef struct _GObject GObject; | 17 typedef struct _GObject GObject; |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 // This class hooks calls to g_object_weak_ref()/unref() and executes them in | 21 // This class hooks calls to g_object_weak_ref()/unref() and executes them in |
| 22 // FILO order. This is important if there are several hooks to the single object | 22 // FILO order. This is important if there are several hooks to the single object |
| 23 // (set up at different levels of class hierarchy) and the lowest hook (set up | 23 // (set up at different levels of class hierarchy) and the lowest hook (set up |
| (...skipping 17 matching lines...) Expand all Loading... |
| 41 // MyClass::~MyClass() { | 41 // MyClass::~MyClass() { |
| 42 // if (!destroyed_) { | 42 // if (!destroyed_) { |
| 43 // ui::GObjectDestructorFILO::GetInstance()->Disconnect( | 43 // ui::GObjectDestructorFILO::GetInstance()->Disconnect( |
| 44 // G_OBJECT(my_widget), &OnDestroyedThunk, this); | 44 // G_OBJECT(my_widget), &OnDestroyedThunk, this); |
| 45 // } | 45 // } |
| 46 // } | 46 // } |
| 47 // | 47 // |
| 48 // TODO(glotov): Probably worth adding ScopedGObjectDtor<T>. | 48 // TODO(glotov): Probably worth adding ScopedGObjectDtor<T>. |
| 49 // | 49 // |
| 50 // This class is a singleton. Not thread safe. Must be called within UI thread. | 50 // This class is a singleton. Not thread safe. Must be called within UI thread. |
| 51 class UI_EXPORT GObjectDestructorFILO { | 51 class UI_BASE_EXPORT GObjectDestructorFILO { |
| 52 public: | 52 public: |
| 53 typedef void (*DestructorHook)(void* context, GObject* where_the_object_was); | 53 typedef void (*DestructorHook)(void* context, GObject* where_the_object_was); |
| 54 | 54 |
| 55 static GObjectDestructorFILO* GetInstance(); | 55 static GObjectDestructorFILO* GetInstance(); |
| 56 void Connect(GObject* object, DestructorHook callback, void* context); | 56 void Connect(GObject* object, DestructorHook callback, void* context); |
| 57 void Disconnect(GObject* object, DestructorHook callback, void* context); | 57 void Disconnect(GObject* object, DestructorHook callback, void* context); |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 struct Hook { | 60 struct Hook { |
| 61 Hook(GObject* o, DestructorHook cb, void* ctx) | 61 Hook(GObject* o, DestructorHook cb, void* ctx) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 HandlerMap handler_map_; | 84 HandlerMap handler_map_; |
| 85 | 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(GObjectDestructorFILO); | 86 DISALLOW_COPY_AND_ASSIGN(GObjectDestructorFILO); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 } // namespace ui | 89 } // namespace ui |
| 90 | 90 |
| 91 #endif // UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ | 91 #endif // UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ |
| OLD | NEW |