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 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h"
9 #include "base/logging.h"
13 OwnedWidgetGtk::~OwnedWidgetGtk() {
17 void OwnedWidgetGtk::Own(GtkWidget
* widget
) {
22 // We want to make sure that Own() was called properly, right after the
23 // widget was created. There should be a floating reference.
24 DCHECK(g_object_is_floating(widget
));
26 // Sink the floating reference, we should now own this reference.
27 g_object_ref_sink(widget
);
31 void OwnedWidgetGtk::Destroy() {
35 GtkWidget
* widget
= widget_
;
37 gtk_widget_destroy(widget
);
39 DCHECK(!g_object_is_floating(widget
));
40 // NOTE: Assumes some implementation details about glib internals.
41 DCHECK_EQ(G_OBJECT(widget
)->ref_count
, 1U);
42 g_object_unref(widget
);
45 } // namespace libgtk2ui