From 4cd7ba1d972ef5206b7a3d2f23304f1f0ea3faf0 Mon Sep 17 00:00:00 2001 From: "tsepez@chromium.org" Date: Wed, 30 Mar 2011 16:59:46 +0000 Subject: XDG isn't thread safe. Add a lock around calls to it. BUG=71586 Review URL: http://codereview.chromium.org/6708072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79851 0039d316-1c4b-4281-b951-d872f2087c98 --- base/mime_util_xdg.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'base') diff --git a/base/mime_util_xdg.cc b/base/mime_util_xdg.cc index 387b69a..e510b68 100644 --- a/base/mime_util_xdg.cc +++ b/base/mime_util_xdg.cc @@ -20,11 +20,16 @@ #include "base/message_loop.h" #include "base/string_split.h" #include "base/string_util.h" +#include "base/synchronization/lock.h" #include "base/third_party/xdg_mime/xdgmime.h" #include "base/threading/thread_restrictions.h" namespace { +// None of the XDG stuff is thread-safe, so serialize all accesss under +// this lock. +base::Lock g_mime_util_xdg_lock; + class IconTheme; class MimeUtilConstants { @@ -553,11 +558,13 @@ namespace mime_util { std::string GetFileMimeType(const FilePath& filepath) { base::ThreadRestrictions::AssertIOAllowed(); + base::AutoLock scoped_lock(g_mime_util_xdg_lock); return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); } std::string GetDataMimeType(const std::string& data) { base::ThreadRestrictions::AssertIOAllowed(); + base::AutoLock scoped_lock(g_mime_util_xdg_lock); return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); } @@ -585,8 +592,12 @@ FilePath GetMimeIcon(const std::string& mime_type, size_t size) { std::string icon_name; FilePath icon_file; - const char* icon = xdg_mime_get_icon(mime_type.c_str()); - icon_name = std::string(icon ? icon : ""); + { + base::AutoLock scoped_lock(g_mime_util_xdg_lock); + const char *icon = xdg_mime_get_icon(mime_type.c_str()); + icon_name = std::string(icon ? icon : ""); + } + if (icon_name.length()) icon_names.push_back(icon_name); -- cgit v1.1