1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #include "base/nix/mime_util_xdg.h" 6*635a8641SAndroid Build Coastguard Worker 7*635a8641SAndroid Build Coastguard Worker #include "base/files/file_path.h" 8*635a8641SAndroid Build Coastguard Worker #include "base/lazy_instance.h" 9*635a8641SAndroid Build Coastguard Worker #include "base/synchronization/lock.h" 10*635a8641SAndroid Build Coastguard Worker #include "base/third_party/xdg_mime/xdgmime.h" 11*635a8641SAndroid Build Coastguard Worker #include "base/threading/thread_restrictions.h" 12*635a8641SAndroid Build Coastguard Worker 13*635a8641SAndroid Build Coastguard Worker namespace base { 14*635a8641SAndroid Build Coastguard Worker namespace nix { 15*635a8641SAndroid Build Coastguard Worker 16*635a8641SAndroid Build Coastguard Worker namespace { 17*635a8641SAndroid Build Coastguard Worker 18*635a8641SAndroid Build Coastguard Worker // None of the XDG stuff is thread-safe, so serialize all access under 19*635a8641SAndroid Build Coastguard Worker // this lock. 20*635a8641SAndroid Build Coastguard Worker LazyInstance<Lock>::Leaky g_mime_util_xdg_lock = LAZY_INSTANCE_INITIALIZER; 21*635a8641SAndroid Build Coastguard Worker 22*635a8641SAndroid Build Coastguard Worker } // namespace 23*635a8641SAndroid Build Coastguard Worker GetFileMimeType(const FilePath & filepath)24*635a8641SAndroid Build Coastguard Workerstd::string GetFileMimeType(const FilePath& filepath) { 25*635a8641SAndroid Build Coastguard Worker if (filepath.empty()) 26*635a8641SAndroid Build Coastguard Worker return std::string(); 27*635a8641SAndroid Build Coastguard Worker AssertBlockingAllowed(); 28*635a8641SAndroid Build Coastguard Worker AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); 29*635a8641SAndroid Build Coastguard Worker return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); 30*635a8641SAndroid Build Coastguard Worker } 31*635a8641SAndroid Build Coastguard Worker 32*635a8641SAndroid Build Coastguard Worker } // namespace nix 33*635a8641SAndroid Build Coastguard Worker } // namespace base 34