| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/mime_util.h" | 5 #include "base/nix/mime_util_xdg.h" |
| 6 | |
| 7 | 6 |
| 8 #include <cstdlib> | 7 #include <cstdlib> |
| 9 #include <list> | 8 #include <list> |
| 10 #include <map> | 9 #include <map> |
| 11 #include <vector> | 10 #include <vector> |
| 12 | 11 |
| 13 #include "base/environment.h" | 12 #include "base/environment.h" |
| 14 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 15 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 19 #include "base/message_loop.h" | |
| 20 #include "base/nix/xdg_util.h" | 18 #include "base/nix/xdg_util.h" |
| 21 #include "base/string_split.h" | 19 #include "base/string_split.h" |
| 22 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 23 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 24 #include "base/third_party/xdg_mime/xdgmime.h" | 22 #include "base/third_party/xdg_mime/xdgmime.h" |
| 25 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
| 26 #include "base/time.h" | 24 #include "base/time.h" |
| 27 | 25 |
| 28 #if defined(TOOLKIT_USES_GTK) | 26 #if defined(TOOLKIT_USES_GTK) |
| 29 #include <gtk/gtk.h> | 27 #include <gtk/gtk.h> // NOLINT |
| 28 |
| 29 #include "base/message_loop.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // None of the XDG stuff is thread-safe, so serialize all access under | 34 // None of the XDG stuff is thread-safe, so serialize all access under |
| 35 // this lock. | 35 // this lock. |
| 36 static base::LazyInstance<base::Lock, | 36 static base::LazyInstance<base::Lock, |
| 37 base::LeakyLazyInstanceTraits<base::Lock> > | 37 base::LeakyLazyInstanceTraits<base::Lock> > |
| 38 g_mime_util_xdg_lock(base::LINKER_INITIALIZED); | 38 g_mime_util_xdg_lock(base::LINKER_INITIALIZED); |
| 39 | 39 |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 return LookupFallbackIcon(icon_name); | 578 return LookupFallbackIcon(icon_name); |
| 579 } | 579 } |
| 580 | 580 |
| 581 MimeUtilConstants::~MimeUtilConstants() { | 581 MimeUtilConstants::~MimeUtilConstants() { |
| 582 for (size_t i = 0; i < kDefaultThemeNum; i++) | 582 for (size_t i = 0; i < kDefaultThemeNum; i++) |
| 583 delete default_themes_[i]; | 583 delete default_themes_[i]; |
| 584 } | 584 } |
| 585 | 585 |
| 586 } // namespace | 586 } // namespace |
| 587 | 587 |
| 588 namespace mime_util { | 588 namespace base { |
| 589 namespace nix { |
| 589 | 590 |
| 590 std::string GetFileMimeType(const FilePath& filepath) { | 591 std::string GetFileMimeType(const FilePath& filepath) { |
| 591 base::ThreadRestrictions::AssertIOAllowed(); | 592 base::ThreadRestrictions::AssertIOAllowed(); |
| 592 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 593 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
| 593 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); | 594 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); |
| 594 } | 595 } |
| 595 | 596 |
| 596 std::string GetDataMimeType(const std::string& data) { | 597 std::string GetDataMimeType(const std::string& data) { |
| 597 base::ThreadRestrictions::AssertIOAllowed(); | 598 base::ThreadRestrictions::AssertIOAllowed(); |
| 598 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 599 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 return icon_file; | 666 return icon_file; |
| 666 } else { | 667 } else { |
| 667 icon_file = LookupIconInDefaultTheme(icon_names[i], size); | 668 icon_file = LookupIconInDefaultTheme(icon_names[i], size); |
| 668 if (!icon_file.empty()) | 669 if (!icon_file.empty()) |
| 669 return icon_file; | 670 return icon_file; |
| 670 } | 671 } |
| 671 } | 672 } |
| 672 return FilePath(); | 673 return FilePath(); |
| 673 } | 674 } |
| 674 | 675 |
| 675 } // namespace mime_util | 676 } // namespace nix |
| 677 } // namespace base |
| OLD | NEW |