// Copyright (c) 2012 The Chromium Authors. All rights reserved.// Use of this source code is governed by a BSD-style license that can be// found in the LICENSE file.#include "base/nix/mime_util_xdg.h"#include "base/files/file_path.h"#include "base/lazy_instance.h"#include "base/synchronization/lock.h"#include "base/third_party/xdg_mime/xdgmime.h"#include "base/threading/thread_restrictions.h"namespacebase{namespacenix{namespace{// None of the XDG stuff is thread-safe, so serialize all access under// this lock.LazyInstance<Lock>::Leakyg_mime_util_xdg_lock=LAZY_INSTANCE_INITIALIZER;}// namespacestd::stringGetFileMimeType(constFilePath&filepath){if(filepath.empty())returnstd::string();ThreadRestrictions::AssertIOAllowed();AutoLockscoped_lock(g_mime_util_xdg_lock.Get());returnxdg_mime_get_mime_type_from_file_name(filepath.value().c_str());}std::stringGetDataMimeType(conststd::string&data){ThreadRestrictions::AssertIOAllowed();AutoLockscoped_lock(g_mime_util_xdg_lock.Get());returnxdg_mime_get_mime_type_for_data(data.data(),data.length(),NULL);}}// namespace nix}// namespace base