• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "base/nix/mime_util_xdg.h"
6 
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"
12 
13 namespace base {
14 namespace nix {
15 
16 namespace {
17 
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;
21 
22 }  // namespace
23 
GetFileMimeType(const FilePath & filepath)24 std::string GetFileMimeType(const FilePath& filepath) {
25   if (filepath.empty())
26     return std::string();
27   AssertBlockingAllowed();
28   AutoLock scoped_lock(g_mime_util_xdg_lock.Get());
29   return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str());
30 }
31 
32 }  // namespace nix
33 }  // namespace base
34