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

Unified Diff: base/mime_util_xdg.cc

Issue 6758053: Merge 79851 - XDG isn't thread safe. Add a lock around calls to it. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/696/src/
Patch Set: Created 9 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mime_util_xdg.cc
===================================================================
--- base/mime_util_xdg.cc (revision 80095)
+++ base/mime_util_xdg.cc (working copy)
@@ -20,11 +20,16 @@
#include "base/singleton.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 @@
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 @@
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698