Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / nix / mime_util_xdg.cc
blobf78b6aba558e4209c30354df4cb6458aac79b814
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"
13 namespace base {
14 namespace nix {
16 namespace {
18 // None of the XDG stuff is thread-safe, so serialize all access under
19 // this lock.
20 LazyInstance<Lock>::Leaky g_mime_util_xdg_lock = LAZY_INSTANCE_INITIALIZER;
22 } // namespace
24 std::string GetFileMimeType(const FilePath& filepath) {
25 if (filepath.empty())
26 return std::string();
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);
38 } // namespace nix
39 } // namespace base