Refactor HpackDecoder's public API to ease integration into SpdyFramer.
[chromium-blink-merge.git] / ui / gfx / scoped_gobject.h
blob58a772984233aa3d4f9a27aa9ca0655db15b2e0c
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"
12 namespace ui {
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());
17 template<class T>
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.
21 template<class U>
22 struct GObjectUnrefer {
23 void operator()(U* ptr) const {
24 if (ptr)
25 g_object_unref(ptr);
29 typedef scoped_ptr<T, GObjectUnrefer<T> > Type;
32 } // namespace ui
34 #endif // UI_GFX_SCOPED_GOBJECT_H_