diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 22:37:35 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-21 22:37:35 +0000 |
commit | 21f9414ce35d4c1548fe6e9179a701701436c578 (patch) | |
tree | 56bdda45cbcfd1602926daadd1dc227a0b31b652 /base | |
parent | ac9deb95ac477b8827e1ec04ab6d05601891976f (diff) | |
download | chromium_src-21f9414ce35d4c1548fe6e9179a701701436c578.zip chromium_src-21f9414ce35d4c1548fe6e9179a701701436c578.tar.gz chromium_src-21f9414ce35d4c1548fe6e9179a701701436c578.tar.bz2 |
Move gtk_settings_get_default() call to the UI thread.
BUG=19971
Review URL: http://codereview.chromium.org/173216
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24034 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/mime_util.h | 7 | ||||
-rw-r--r-- | base/mime_util_linux.cc | 32 |
2 files changed, 33 insertions, 6 deletions
diff --git a/base/mime_util.h b/base/mime_util.h index 4b67e46..7e1593b 100644 --- a/base/mime_util.h +++ b/base/mime_util.h @@ -20,6 +20,13 @@ std::string GetFileMimeType(const FilePath& filepath); // Get the mime type for a byte vector. std::string GetDataMimeType(const std::string& data); +#if defined(OS_LINUX) +// This detects the current GTK theme by calling gtk_settings_get_default(). +// It should only be executed on the UI thread and must be called before +// GetMimeIcon(). +void DetectGtkTheme(); +#endif + // Gets the file name for an icon given the mime type and icon pixel size. // Where an icon is a square image of |size| x |size|. // This will try to find the closest matching icon. If that's not available, diff --git a/base/mime_util_linux.cc b/base/mime_util_linux.cc index c5fe60c..b42122f 100644 --- a/base/mime_util_linux.cc +++ b/base/mime_util_linux.cc @@ -15,6 +15,7 @@ #include "base/file_util.h" #include "base/logging.h" +#include "base/message_loop.h" #include "base/scoped_ptr.h" #include "base/singleton.h" #include "base/string_util.h" @@ -46,6 +47,11 @@ class MimeUtilConstants { time_t last_check_time_; + // This is set by DetectGtkTheme(). We cache it so that we can access the + // theme name from threads that aren't allowed to call + // gtk_settings_get_default(). + std::string gtk_theme_name_; + private: MimeUtilConstants() : kUpdateInterval(5), @@ -489,13 +495,9 @@ void InitDefaultThemes() { default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme); } else { // Assume it's Gnome and use GTK to figure out the theme. - gchar* gtk_theme_name; - g_object_get(gtk_settings_get_default(), - "gtk-icon-theme-name", - >k_theme_name, NULL); - default_themes[1] = IconTheme::LoadTheme(gtk_theme_name); + default_themes[1] = IconTheme::LoadTheme( + Singleton<MimeUtilConstants>::get()->gtk_theme_name_); default_themes[2] = IconTheme::LoadTheme("gnome"); - g_free(gtk_theme_name); } // hicolor needs to be last per icon theme spec. default_themes[3] = IconTheme::LoadTheme("hicolor"); @@ -550,6 +552,24 @@ std::string GetDataMimeType(const std::string& data) { return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); } +void DetectGtkTheme() { + // If the theme name is already loaded, do nothing. Chrome doesn't respond + // to changes in the system theme, so we never need to set this more than + // once. + if (!Singleton<MimeUtilConstants>::get()->gtk_theme_name_.empty()) + return; + + // We should only be called on the UI thread. + DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); + + gchar* gtk_theme_name; + g_object_get(gtk_settings_get_default(), + "gtk-icon-theme-name", + >k_theme_name, NULL); + Singleton<MimeUtilConstants>::get()->gtk_theme_name_.assign(gtk_theme_name); + g_free(gtk_theme_name); +} + FilePath GetMimeIcon(const std::string& mime_type, size_t size) { std::vector<std::string> icon_names; std::string icon_name; |