summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authortsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 16:59:46 +0000
committertsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 16:59:46 +0000
commit4cd7ba1d972ef5206b7a3d2f23304f1f0ea3faf0 (patch)
treebfef0225a81db732a14bac92a1485480ba83a69b /base
parentef37f22d76fd0f6b9c2bc0ee0898fb1689920b22 (diff)
downloadchromium_src-4cd7ba1d972ef5206b7a3d2f23304f1f0ea3faf0.zip
chromium_src-4cd7ba1d972ef5206b7a3d2f23304f1f0ea3faf0.tar.gz
chromium_src-4cd7ba1d972ef5206b7a3d2f23304f1f0ea3faf0.tar.bz2
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
Diffstat (limited to 'base')
-rw-r--r--base/mime_util_xdg.cc15
1 files changed, 13 insertions, 2 deletions
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);