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
3 // found in the LICENSE file.
5 #ifndef UI_GFX_SCOPED_GOBJECT_H_
6 #define UI_GFX_SCOPED_GOBJECT_H_
8 #include <glib-object.h>
10 #include "base/memory/scoped_ptr.h"
14 // It's not legal C++ to have a templatized typedefs, so we wrap it in a
15 // struct. When using this, you need to include ::Type. E.g.,
16 // ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new());
18 struct ScopedGObject
{
19 // A helper class that will g_object_unref |p| when it goes out of scope.
20 // This never adds a ref, it only unrefs.
22 struct GObjectUnrefer
{
23 void operator()(U
* ptr
) const {
29 typedef scoped_ptr
<T
, GObjectUnrefer
<T
> > Type
;
34 #endif // UI_GFX_SCOPED_GOBJECT_H_