| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <glib.h> | 9 #include <glib.h> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <list> | 11 #include <list> |
| 12 | 12 |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "ui/ui_api.h" | 14 #include "ui/base/ui_export.h" |
| 15 | 15 |
| 16 typedef struct _GObject GObject; | 16 typedef struct _GObject GObject; |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 // This class hooks calls to g_object_weak_ref()/unref() and executes them in | 20 // This class hooks calls to g_object_weak_ref()/unref() and executes them in |
| 21 // FILO order. This is important if there are several hooks to the single object | 21 // FILO order. This is important if there are several hooks to the single object |
| 22 // (set up at different levels of class hierarchy) and the lowest hook (set up | 22 // (set up at different levels of class hierarchy) and the lowest hook (set up |
| 23 // first) is deleting self - it must be called last (among hooks for the given | 23 // first) is deleting self - it must be called last (among hooks for the given |
| 24 // object). Unfortunately Glib does not provide this guarantee. | 24 // object). Unfortunately Glib does not provide this guarantee. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 // MyClass::~MyClass() { | 40 // MyClass::~MyClass() { |
| 41 // if (!destroyed_) { | 41 // if (!destroyed_) { |
| 42 // ui::GObjectDestructorFILO::GetInstance()->Disconnect( | 42 // ui::GObjectDestructorFILO::GetInstance()->Disconnect( |
| 43 // G_OBJECT(my_widget), &OnDestroyedThunk, this); | 43 // G_OBJECT(my_widget), &OnDestroyedThunk, this); |
| 44 // } | 44 // } |
| 45 // } | 45 // } |
| 46 // | 46 // |
| 47 // TODO(glotov): Probably worth adding ScopedGObjectDtor<T>. | 47 // TODO(glotov): Probably worth adding ScopedGObjectDtor<T>. |
| 48 // | 48 // |
| 49 // This class is a singleton. Not thread safe. Must be called within UI thread. | 49 // This class is a singleton. Not thread safe. Must be called within UI thread. |
| 50 class UI_API GObjectDestructorFILO { | 50 class UI_EXPORT GObjectDestructorFILO { |
| 51 public: | 51 public: |
| 52 typedef void (*DestructorHook)(void* context, GObject* where_the_object_was); | 52 typedef void (*DestructorHook)(void* context, GObject* where_the_object_was); |
| 53 | 53 |
| 54 static GObjectDestructorFILO* GetInstance(); | 54 static GObjectDestructorFILO* GetInstance(); |
| 55 void Connect(GObject* object, DestructorHook callback, void* context); | 55 void Connect(GObject* object, DestructorHook callback, void* context); |
| 56 void Disconnect(GObject* object, DestructorHook callback, void* context); | 56 void Disconnect(GObject* object, DestructorHook callback, void* context); |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 struct Hook { | 59 struct Hook { |
| 60 Hook(GObject* o, DestructorHook cb, void* ctx) | 60 Hook(GObject* o, DestructorHook cb, void* ctx) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 81 } | 81 } |
| 82 | 82 |
| 83 HandlerMap handler_map_; | 83 HandlerMap handler_map_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(GObjectDestructorFILO); | 85 DISALLOW_COPY_AND_ASSIGN(GObjectDestructorFILO); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace ui | 88 } // namespace ui |
| 89 | 89 |
| 90 #endif // UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ | 90 #endif // UI_BASE_GTK_G_OBJECT_DESTRUCTOR_FILO_H_ |
| OLD | NEW |