summaryrefslogtreecommitdiffstats
path: root/ui/base/gtk
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 17:57:12 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 17:57:12 +0000
commit444f217666f482c65573e73fb4853fc28f8133a0 (patch)
tree7b8c8c353df24f49f5ffbc2af079af200e6ffa1e /ui/base/gtk
parente3eb921e3f8ad563e1d33e01e9b206122f2e67f5 (diff)
downloadchromium_src-444f217666f482c65573e73fb4853fc28f8133a0.zip
chromium_src-444f217666f482c65573e73fb4853fc28f8133a0.tar.gz
chromium_src-444f217666f482c65573e73fb4853fc28f8133a0.tar.bz2
gtk: Move ScopedGObject into ui/base/gtk/scoped_gobject.h
R=erg@chromium.org TBR=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/9594009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/gtk')
-rw-r--r--ui/base/gtk/scoped_gobject.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/ui/base/gtk/scoped_gobject.h b/ui/base/gtk/scoped_gobject.h
new file mode 100644
index 0000000..5564851
--- /dev/null
+++ b/ui/base/gtk/scoped_gobject.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_BASE_GTK_SCOPED_GOBJECT_H_
+#define UI_BASE_GTK_SCOPED_GOBJECT_H_
+#pragma once
+
+#include <glib-object.h>
+
+#include "base/memory/scoped_ptr.h"
+
+namespace ui {
+
+// It's not legal C++ to have a templatized typedefs, so we wrap it in a
+// struct. When using this, you need to include ::Type. E.g.,
+// ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new());
+template<class T>
+struct ScopedGObject {
+ // A helper class that will g_object_unref |p| when it goes out of scope.
+ // This never adds a ref, it only unrefs.
+ template<class U>
+ struct GObjectUnrefer {
+ void operator()(U* ptr) const {
+ if (ptr)
+ g_object_unref(ptr);
+ }
+ };
+
+ typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type;
+};
+
+} // namespace ui
+
+#endif // UI_BASE_GTK_SCOPED_GOBJECT_H_