Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/ui/libgtkui/gtk_status_icon.cc

Issue 2696903003: Gtk3: Fix memory leaks (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/libgtkui/gtk_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/ui/libgtkui/gtk_status_icon.h" 5 #include "chrome/browser/ui/libgtkui/gtk_status_icon.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/debug/leak_annotations.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/libgtkui/app_indicator_icon_menu.h" 11 #include "chrome/browser/ui/libgtkui/app_indicator_icon_menu.h"
11 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" 12 #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h"
12 #include "ui/base/models/menu_model.h" 13 #include "ui/base/models/menu_model.h"
13 #include "ui/gfx/image/image_skia.h" 14 #include "ui/gfx/image/image_skia.h"
14 15
15 G_GNUC_BEGIN_IGNORE_DEPRECATIONS 16 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
16 17
17 namespace libgtkui { 18 namespace libgtkui {
18 19
19 Gtk2StatusIcon::Gtk2StatusIcon(const gfx::ImageSkia& image, 20 Gtk2StatusIcon::Gtk2StatusIcon(const gfx::ImageSkia& image,
20 const base::string16& tool_tip) { 21 const base::string16& tool_tip) {
21 GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(*image.bitmap()); 22 GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(*image.bitmap());
22 gtk_status_icon_ = gtk_status_icon_new_from_pixbuf(pixbuf); 23 {
24 #if GTK_MAJOR_VERSION == 3
25 // Gtk3 has a bug that leaks 384 bytes when creating a
26 // GtkStatusIcon. It will not be fixed since the status icon was
27 // deprectaed in version 3.14. Luckily, Chromium doesn't need to
28 // create a status icon very often, if at all.
29 ANNOTATE_SCOPED_MEMORY_LEAK;
30 #endif
31 gtk_status_icon_ = gtk_status_icon_new_from_pixbuf(pixbuf);
32 }
23 g_object_unref(pixbuf); 33 g_object_unref(pixbuf);
24 34
25 g_signal_connect(gtk_status_icon_, "activate", G_CALLBACK(OnClickThunk), 35 g_signal_connect(gtk_status_icon_, "activate", G_CALLBACK(OnClickThunk),
26 this); 36 this);
27 g_signal_connect(gtk_status_icon_, "popup_menu", 37 g_signal_connect(gtk_status_icon_, "popup_menu",
28 G_CALLBACK(OnContextMenuRequestedThunk), this); 38 G_CALLBACK(OnContextMenuRequestedThunk), this);
29 SetToolTip(tool_tip); 39 SetToolTip(tool_tip);
30 } 40 }
31 41
32 Gtk2StatusIcon::~Gtk2StatusIcon() { 42 Gtk2StatusIcon::~Gtk2StatusIcon() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 guint button, 75 guint button,
66 guint32 activate_time) { 76 guint32 activate_time) {
67 if (menu_.get()) { 77 if (menu_.get()) {
68 gtk_menu_popup(menu_->GetGtkMenu(), NULL, NULL, 78 gtk_menu_popup(menu_->GetGtkMenu(), NULL, NULL,
69 gtk_status_icon_position_menu, gtk_status_icon_, button, 79 gtk_status_icon_position_menu, gtk_status_icon_, button,
70 activate_time); 80 activate_time);
71 } 81 }
72 } 82 }
73 83
74 } // namespace libgtkui 84 } // namespace libgtkui
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/libgtkui/gtk_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698