1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/nix/mime_util_xdg.h"
7 #include "base/files/file_path.h"
8 #include "base/lazy_instance.h"
9 #include "base/synchronization/lock.h"
10 #include "base/third_party/xdg_mime/xdgmime.h"
11 #include "base/threading/thread_restrictions.h"
18 // None of the XDG stuff is thread-safe, so serialize all access under
20 LazyInstance
<Lock
>::Leaky g_mime_util_xdg_lock
= LAZY_INSTANCE_INITIALIZER
;
24 std::string
GetFileMimeType(const FilePath
& filepath
) {
27 ThreadRestrictions::AssertIOAllowed();
28 AutoLock
scoped_lock(g_mime_util_xdg_lock
.Get());
29 return xdg_mime_get_mime_type_from_file_name(filepath
.value().c_str());
32 std::string
GetDataMimeType(const std::string
& data
) {
33 ThreadRestrictions::AssertIOAllowed();
34 AutoLock
scoped_lock(g_mime_util_xdg_lock
.Get());
35 return xdg_mime_get_mime_type_for_data(data
.data(), data
.length(), NULL
);